diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java new file mode 100644 index 0000000000..683b0b86ab --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("default") +@SpringBootTest(classes = { MultidocumentTestConfig.class }) +public class MultidocumentPropertiesFileIntegrationTest { + + Logger logger = LoggerFactory.getLogger(MultidocumentPropertiesFileIntegrationTest.class); + + @Value("${baeldung.customProperty}") + private String customProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(customProperty).isEqualTo("valueDefault"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java new file mode 100644 index 0000000000..3771bdb1c7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithDevProfileIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +@SpringBootTest(classes = { MultidocumentTestConfig.class }) +public class MultidocumentPropertiesFileWithDevProfileIntegrationTest { + + Logger logger = LoggerFactory.getLogger(MultidocumentPropertiesFileWithDevProfileIntegrationTest.class); + + @Value("${baeldung.customProperty}") + private String customProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(customProperty).isEqualTo("valueTest"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java new file mode 100644 index 0000000000..b00dda19b7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentPropertiesFileWithTestProfileIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multidocument; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("dev") +@SpringBootTest(classes = { MultidocumentTestConfig.class }) +public class MultidocumentPropertiesFileWithTestProfileIntegrationTest { + + Logger logger = LoggerFactory.getLogger(MultidocumentPropertiesFileWithTestProfileIntegrationTest.class); + + @Value("${baeldung.customProperty}") + private String customProperty; + + @Test + public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() { + assertThat(customProperty).isEqualTo("valueDev"); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java new file mode 100644 index 0000000000..6f80cb70e7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multidocument/MultidocumentTestConfig.java @@ -0,0 +1,10 @@ +package com.baeldung.properties.multidocument; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.baeldung.properties.multidocument") +public class MultidocumentTestConfig { + +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties index af38556f81..c3a98b3da4 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties @@ -2,4 +2,14 @@ management.endpoints.web.exposure.include=refresh spring.properties.refreshDelay=1000 spring.config.location=file:extra.properties spring.main.allow-bean-definition-overriding=true +baeldung.customProperty=valueDefault +#--- +spring.config.activate.on-profile=dev +baeldung.customProperty=valueDev +#--- +spring.config.activate.on-profile=test +baeldung.customProperty=valueTest +#--- +spring.config.activate.on-profile=prod +baeldung.customProperty=valueProd