From eebbdf82d9e1f28fd017e05d828ad8ff6347d501 Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Sun, 11 Sep 2022 11:54:49 +0200 Subject: [PATCH] fix: add embedded properties to tests (#12714) --- .../collection/name/SpringBootCollectionNameApplication.java | 2 +- .../composite/key/SpringBootCompositeKeyApplication.java | 2 +- .../com/baeldung/boot/count/SpringBootCountApplication.java | 2 +- .../boot/unique/field/SpringBootUniqueFieldApplication.java | 2 +- .../name/service/MusicStoreServiceIntegrationTest.java | 5 ++++- .../boot/composite/key/CustomerServiceIntegrationTest.java | 4 +++- .../boot/count/service/CountCarServiceIntegrationTest.java | 5 ++++- .../boot/unique/field/UniqueFieldIntegrationTest.java | 4 +++- 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/collection/name/SpringBootCollectionNameApplication.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/collection/name/SpringBootCollectionNameApplication.java index 09b5a8ef17..5d6af81fcd 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/collection/name/SpringBootCollectionNameApplication.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/collection/name/SpringBootCollectionNameApplication.java @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -@SpringBootApplication(exclude = EmbeddedMongoAutoConfiguration.class) +@SpringBootApplication @PropertySource("classpath:boot.collection.name/app.properties") @EnableMongoRepositories(basePackages = { "com.baeldung.boot.collection.name" }) public class SpringBootCollectionNameApplication { diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/composite/key/SpringBootCompositeKeyApplication.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/composite/key/SpringBootCompositeKeyApplication.java index 14c88d3ec7..0cf5d0eab8 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/composite/key/SpringBootCompositeKeyApplication.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/composite/key/SpringBootCompositeKeyApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -@SpringBootApplication(exclude = EmbeddedMongoAutoConfiguration.class) +@SpringBootApplication @EnableMongoRepositories(basePackages = { "com.baeldung.boot.composite.key" }) public class SpringBootCompositeKeyApplication { public static void main(String... args) { diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/count/SpringBootCountApplication.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/count/SpringBootCountApplication.java index cb90544a33..56ca8309f0 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/count/SpringBootCountApplication.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/count/SpringBootCountApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -@SpringBootApplication(exclude = EmbeddedMongoAutoConfiguration.class) +@SpringBootApplication @EnableMongoRepositories(basePackages = { "com.baeldung.boot.count" }) public class SpringBootCountApplication { public static void main(String... args) { diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/unique/field/SpringBootUniqueFieldApplication.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/unique/field/SpringBootUniqueFieldApplication.java index de983c08ff..d8a0f3293c 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/unique/field/SpringBootUniqueFieldApplication.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/main/java/com/baeldung/boot/unique/field/SpringBootUniqueFieldApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoCo import org.springframework.context.annotation.PropertySource; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -@SpringBootApplication(exclude = EmbeddedMongoAutoConfiguration.class) +@SpringBootApplication @PropertySource("classpath:boot.unique.field/app.properties") @EnableMongoRepositories(basePackages = { "com.baeldung.boot.unique.field" }) public class SpringBootUniqueFieldApplication { diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/collection/name/service/MusicStoreServiceIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/collection/name/service/MusicStoreServiceIntegrationTest.java index eda8b8aafb..2cb9d7fdfa 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/collection/name/service/MusicStoreServiceIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/collection/name/service/MusicStoreServiceIntegrationTest.java @@ -10,16 +10,19 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.collection.name.SpringBootCollectionNameApplication; import com.baeldung.boot.collection.name.data.Compilation; import com.baeldung.boot.collection.name.data.MusicAlbum; import com.baeldung.boot.collection.name.data.MusicTrack; import com.baeldung.boot.collection.name.data.Store; -@SpringBootTest +@SpringBootTest(classes = SpringBootCollectionNameApplication.class) @DirtiesContext @RunWith(SpringRunner.class) +@TestPropertySource("/embedded.properties") public class MusicStoreServiceIntegrationTest { @Autowired private MusicStoreService service; diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/composite/key/CustomerServiceIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/composite/key/CustomerServiceIntegrationTest.java index af310ab29e..d41c920666 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/composite/key/CustomerServiceIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/composite/key/CustomerServiceIntegrationTest.java @@ -12,15 +12,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DuplicateKeyException; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.boot.composite.key.data.Ticket; import com.baeldung.boot.composite.key.data.TicketId; import com.baeldung.boot.composite.key.service.CustomerService; -@SpringBootTest +@SpringBootTest(classes = SpringBootCompositeKeyApplication.class) @DirtiesContext @RunWith(SpringRunner.class) +@TestPropertySource("/embedded.properties") public class CustomerServiceIntegrationTest { @Autowired private CustomerService service; diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/count/service/CountCarServiceIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/count/service/CountCarServiceIntegrationTest.java index 421ecd3a34..24201727db 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/count/service/CountCarServiceIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/count/service/CountCarServiceIntegrationTest.java @@ -10,13 +10,16 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.boot.count.SpringBootCountApplication; import com.baeldung.boot.count.data.Car; -@SpringBootTest +@SpringBootTest(classes = SpringBootCountApplication.class) @DirtiesContext @RunWith(SpringRunner.class) +@TestPropertySource("/embedded.properties") public class CountCarServiceIntegrationTest { @Autowired private CountCarService service; diff --git a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/unique/field/UniqueFieldIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/unique/field/UniqueFieldIntegrationTest.java index c18a877b79..7ad0798ae2 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/unique/field/UniqueFieldIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-2/src/test/java/com/baeldung/boot/unique/field/UniqueFieldIntegrationTest.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DuplicateKeyException; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.boot.unique.field.dao.AssetRepository; @@ -20,9 +21,10 @@ import com.baeldung.boot.unique.field.data.Customer; import com.baeldung.boot.unique.field.data.Sale; import com.baeldung.boot.unique.field.data.SaleId; -@SpringBootTest +@SpringBootTest(classes = SpringBootUniqueFieldApplication.class) @DirtiesContext @RunWith(SpringRunner.class) +@TestPropertySource("/embedded.properties") public class UniqueFieldIntegrationTest { @Autowired private SaleRepository saleRepo;