Added simple test for multidocument properties file

This commit is contained in:
Gerardo Roza 2020-11-26 10:52:15 -03:00
parent 73bfea2207
commit eb4b03eb73
5 changed files with 95 additions and 0 deletions

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -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 {
}

View File

@ -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