added test for adding configuration properties scenarios

This commit is contained in:
Gerardo Roza 2020-11-28 10:57:31 -03:00
parent eb4b03eb73
commit 23c81c0595
7 changed files with 55 additions and 6 deletions

View File

@ -0,0 +1,29 @@
package com.baeldung.properties.additionalproperties;
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 = { AdditionalPropertiesTestConfig.class })
public class AdditionalPropertiesFilesIntegrationTest {
Logger logger = LoggerFactory.getLogger(AdditionalPropertiesFilesIntegrationTest.class);
@Value("${baeldung.additionalProperty}")
private String additionalProperty;
@Value("${baeldung.otherProperty}")
private String otherProperty;
@Test
public void givenMultidocumentPropertiesFileWhenBootContextLoadedThenDocumentProcessedCorrectly() {
assertThat(additionalProperty).isEqualTo("additionalValue2");
assertThat(otherProperty).isEqualTo("latterValue");
}
}

View File

@ -0,0 +1,10 @@
package com.baeldung.properties.additionalproperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.baeldung.properties.additionalproperties")
public class AdditionalPropertiesTestConfig {
}

View File

@ -0,0 +1,7 @@
baeldung:
additionalProperty: additionalValue
otherProperty: otherValue
spring:
config:
import: classpath:additional-application2.properties

View File

@ -0,0 +1,5 @@
spring.config.activate.on-profile=test
baeldung.customProperty=valueTest
#---
spring.config.activate.on-profile=prod
baeldung.customProperty=valueProd

View File

@ -0,0 +1 @@
baeldung.additionalProperty=additionalValue2

View File

@ -2,14 +2,10 @@ management.endpoints.web.exposure.include=refresh
spring.properties.refreshDelay=1000
spring.config.location=file:extra.properties
spring.main.allow-bean-definition-overriding=true
spring.config.import=classpath:additional-application.properties,classpath:additional-application[.yml],optional:file:./external.properties,classpath:additional-application-properties/
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