From fb95f71104b85eaac1576daf2f6c0345db76d810 Mon Sep 17 00:00:00 2001 From: Felix Reichenbach <felix.reichenbach@mgm-tp.com> Date: Fri, 28 Mar 2025 08:42:27 +0100 Subject: [PATCH] OZG-7837 rename repository method, add ITCases --- .../warehouse/CustomWarehouseRepository.java | 2 +- .../CustomWarehouseRepositoryImpl.java | 2 +- .../CustomWarehouseRepositoryImplTest.java | 2 +- .../warehouse/WarehouseRepositoryITCase.java | 28 +++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepository.java b/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepository.java index da72066..b191dca 100644 --- a/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepository.java +++ b/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepository.java @@ -4,5 +4,5 @@ interface CustomWarehouseRepository { DocumentEntry saveInCollection(DocumentEntry documentEntry, String collectionName); - void deleteCollection(String collectionName); + void clearCollection(String collectionName); } diff --git a/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImpl.java b/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImpl.java index 6e331b6..7b6a1c0 100644 --- a/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImpl.java +++ b/src/main/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImpl.java @@ -15,7 +15,7 @@ class CustomWarehouseRepositoryImpl implements CustomWarehouseRepository { } @Override - public void deleteCollection(String collectionName) { + public void clearCollection(String collectionName) { mongoTemplate.dropCollection(collectionName); } diff --git a/src/test/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImplTest.java b/src/test/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImplTest.java index c797330..d3ea33c 100644 --- a/src/test/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImplTest.java +++ b/src/test/java/de/ozgcloud/aggregation/warehouse/CustomWarehouseRepositoryImplTest.java @@ -50,7 +50,7 @@ class CustomWarehouseRepositoryImplTest { @Test void shouldDropCollection() { - repository.deleteCollection(collectionName); + repository.clearCollection(collectionName); verify(mongoTemplate).dropCollection(collectionName); } diff --git a/src/test/java/de/ozgcloud/aggregation/warehouse/WarehouseRepositoryITCase.java b/src/test/java/de/ozgcloud/aggregation/warehouse/WarehouseRepositoryITCase.java index 18a3ab4..ad1c860 100644 --- a/src/test/java/de/ozgcloud/aggregation/warehouse/WarehouseRepositoryITCase.java +++ b/src/test/java/de/ozgcloud/aggregation/warehouse/WarehouseRepositoryITCase.java @@ -32,6 +32,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoOperations; +import com.thedeanda.lorem.LoremIpsum; + import de.ozgcloud.common.test.DataITCase; @DataITCase @@ -57,7 +59,33 @@ class WarehouseRepositoryITCase { var foundDocument = mongoOperations.findById(savedDocument.getId(), Document.class, DocumentEntry.COLLECTION); assertThat(foundDocument.getString("_class")).isEqualTo("Vorgang"); } + } + + @Nested + class TestSaveInCollection { + private final String collectionName = LoremIpsum.getInstance().getWords(1); + + @Test + void shouldSaveInCollection() { + repository.saveInCollection(DocumentEntryTestFactory.create(), collectionName); + + assertThat(mongoOperations.getCollection(collectionName).countDocuments()).isOne(); + } } + @Nested + class TestClearCollection { + + private final String collectionName = LoremIpsum.getInstance().getWords(1); + + @Test + void shouldClearCollection() { + mongoOperations.save(DocumentEntryTestFactory.create(), collectionName); + + repository.clearCollection(collectionName); + + assertThat(mongoOperations.getCollection(collectionName).countDocuments()).isZero(); + } + } } -- GitLab