Added simple test for multidocument properties file
This commit is contained in:
parent
73bfea2207
commit
eb4b03eb73
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue