improved and updated spring-boot-yaml-vs-properties article code
This commit is contained in:
parent
7347c8fe16
commit
0de3237365
|
@ -0,0 +1,4 @@
|
|||
spring.datasource.password: 'password'
|
||||
spring.datasource.url: jdbc:mysql://localhost:3306/db_integration
|
||||
spring.datasource.username: user
|
||||
bael.property=integrationValue
|
|
@ -9,7 +9,17 @@ spring.datasource.username=SA
|
|||
spring.datasource.password=password
|
||||
app.name=MyApp
|
||||
app.description=${app.name} is a Spring Boot application
|
||||
logging.file.name=myapplication.log
|
||||
bael.property=defaultValue
|
||||
#---
|
||||
spring.config.activate.on-profile=prod
|
||||
spring.config.activate.on-profile=multidocument-dev
|
||||
spring.datasource.password=password
|
||||
spring.datasource.url=jdbc:h2:dev
|
||||
spring.datasource.username=SA
|
||||
bael.property=devValue
|
||||
#---
|
||||
spring.config.activate.on-profile=multidocument-prod
|
||||
spring.datasource.password=password
|
||||
spring.datasource.url=jdbc:h2:prod
|
||||
spring.datasource.username=prodUser
|
||||
bael.property=prodValue
|
|
@ -1,17 +1,17 @@
|
|||
logging:
|
||||
file:
|
||||
name: myapplication.log
|
||||
spring:
|
||||
datasource:
|
||||
password: 'password'
|
||||
url: jdbc:h2:dev
|
||||
username: SA
|
||||
bael:
|
||||
root-level-property: defaultRootLevelValue
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: multidocument-staging
|
||||
datasource:
|
||||
password: 'password'
|
||||
url: jdbc:mysql://localhost:3306/db_production
|
||||
username: user
|
||||
url: jdbc:h2:staging
|
||||
username: SA
|
||||
bael:
|
||||
property: stagingValue
|
||||
---
|
||||
application:
|
||||
servers:
|
||||
- ip: '127.0.0.1'
|
||||
|
|
|
@ -10,13 +10,17 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
|||
import com.baeldung.boot.properties.DemoApplication;
|
||||
|
||||
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||
public class DefaultMultidocumentPropertiesFileIntegrationTest {
|
||||
public class DefaultMultidocumentFilesIntegrationTest {
|
||||
|
||||
@Value("${bael.property}")
|
||||
private String baelCustomProperty;
|
||||
|
||||
@Value("${bael.root-level-property}")
|
||||
private String baelRootProperty;
|
||||
|
||||
@Test
|
||||
public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||
assertThat(baelCustomProperty).isEqualTo("defaultValue");
|
||||
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.boot.properties.multidocument;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.baeldung.boot.properties.DemoApplication;
|
||||
|
||||
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||
@ActiveProfiles("multidocument-dev")
|
||||
public class DevMultidocumentFilesIntegrationTest {
|
||||
|
||||
@Value("${bael.property}")
|
||||
private String baelCustomProperty;
|
||||
|
||||
@Value("${bael.root-level-property}")
|
||||
private String baelRootProperty;
|
||||
|
||||
@Test
|
||||
public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||
assertThat(baelCustomProperty).isEqualTo("devValue");
|
||||
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.boot.properties.multidocument;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.baeldung.boot.properties.DemoApplication;
|
||||
|
||||
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||
@ActiveProfiles("multidocument-integration")
|
||||
public class IntegrationMultidocumentFilesIntegrationTest {
|
||||
|
||||
@Value("${bael.property}")
|
||||
private String baelCustomProperty;
|
||||
|
||||
@Value("${bael.root-level-property}")
|
||||
private String baelRootProperty;
|
||||
|
||||
@Test
|
||||
public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||
assertThat(baelCustomProperty).isEqualTo("integrationValue");
|
||||
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||
}
|
||||
}
|
|
@ -11,14 +11,18 @@ import org.springframework.test.context.ActiveProfiles;
|
|||
import com.baeldung.boot.properties.DemoApplication;
|
||||
|
||||
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||
@ActiveProfiles("prod")
|
||||
public class ProdMultidocumentPropertiesFileIntegrationTest {
|
||||
@ActiveProfiles("multidocument-prod")
|
||||
public class ProdMultidocumentFilesIntegrationTest {
|
||||
|
||||
@Value("${bael.property}")
|
||||
private String baelCustomProperty;
|
||||
|
||||
@Value("${bael.root-level-property}")
|
||||
private String baelRootProperty;
|
||||
|
||||
@Test
|
||||
public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||
assertThat(baelCustomProperty).isEqualTo("prodValue");
|
||||
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.boot.properties.multidocument;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.baeldung.boot.properties.DemoApplication;
|
||||
|
||||
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||
@ActiveProfiles("multidocument-staging")
|
||||
public class StagingMultidocumentFilesIntegrationTest {
|
||||
|
||||
@Value("${bael.property}")
|
||||
private String baelCustomProperty;
|
||||
|
||||
@Value("${bael.root-level-property}")
|
||||
private String baelRootProperty;
|
||||
|
||||
@Test
|
||||
public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||
assertThat(baelCustomProperty).isEqualTo("stagingValue");
|
||||
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue