Merge pull request #10421 from rozagerardo/rozagerardo/JAVA-3717_Update-articles-for-2.4.0--other-properties-modules
[JAVA-3717] Update articles for 2.4.0 - other properties-related articles
This commit is contained in:
commit
119af2bcb9
@ -33,6 +33,17 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -26,12 +26,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -0,0 +1,4 @@
|
||||
spring.datasource.password: 'password'
|
||||
spring.datasource.url: jdbc:mysql://localhost:3306/db_integration
|
||||
spring.datasource.username: user
|
||||
bael.property=integrationValue
|
@ -8,4 +8,18 @@ spring.datasource.url=jdbc:h2:dev
|
||||
spring.datasource.username=SA
|
||||
spring.datasource.password=password
|
||||
app.name=MyApp
|
||||
app.description=${app.name} is a Spring Boot application
|
||||
app.description=${app.name} is a Spring Boot application
|
||||
logging.file.name=myapplication.log
|
||||
bael.property=defaultValue
|
||||
#---
|
||||
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'
|
||||
|
@ -0,0 +1,26 @@
|
||||
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 com.baeldung.boot.properties.DemoApplication;
|
||||
|
||||
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||
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");
|
||||
}
|
||||
}
|
@ -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-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");
|
||||
}
|
||||
}
|
@ -51,6 +51,17 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Embedded Redis Server -->
|
||||
<dependency>
|
||||
|
@ -7,13 +7,13 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
|
||||
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
|
||||
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class)
|
||||
@EnableConfigurationProperties(value = ServerConfig.class)
|
||||
@ActiveProfiles("test")
|
||||
public class BindingYMLPropertiesUnitTest {
|
||||
|
@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
|
||||
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
@ -19,7 +19,7 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class },
|
||||
initializers = ConfigFileApplicationContextInitializer.class)
|
||||
initializers = ConfigDataApplicationContextInitializer.class)
|
||||
public class LoadSpringContextIntegrationTest {
|
||||
@SpyBean
|
||||
TaskService taskService;
|
||||
|
@ -1,5 +1,7 @@
|
||||
spring:
|
||||
profiles: test
|
||||
config:
|
||||
activate:
|
||||
on-profile: test
|
||||
server:
|
||||
address:
|
||||
ip: 192.168.0.4
|
||||
@ -7,7 +9,9 @@ server:
|
||||
imgs: /etc/test/imgs
|
||||
---
|
||||
spring:
|
||||
profiles: dev
|
||||
config:
|
||||
activate:
|
||||
on-profile: dev
|
||||
server:
|
||||
address:
|
||||
ip: 192.168.0.5
|
||||
|
@ -39,6 +39,17 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
|
Loading…
x
Reference in New Issue
Block a user