JAVA-18600 Update "Guide to @ConfigurationProperties in Spring Boot" … (#13670)
* JAVA-18600 Update "Guide to @ConfigurationProperties in Spring Boot" article --------- Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
parent
d964c3d1eb
commit
fae3e80186
|
@ -63,10 +63,6 @@
|
||||||
<module>spring-boot-nashorn</module>
|
<module>spring-boot-nashorn</module>
|
||||||
<module>spring-boot-parent</module>
|
<module>spring-boot-parent</module>
|
||||||
<module>spring-boot-performance</module>
|
<module>spring-boot-performance</module>
|
||||||
<module>spring-boot-properties</module>
|
|
||||||
<module>spring-boot-properties-2</module>
|
|
||||||
<module>spring-boot-properties-3</module>
|
|
||||||
<module>spring-boot-properties-migrator-demo</module>
|
|
||||||
<module>spring-boot-property-exp</module>
|
<module>spring-boot-property-exp</module>
|
||||||
<module>spring-boot-request-params</module>
|
<module>spring-boot-request-params</module>
|
||||||
<module>spring-boot-runtime</module>
|
<module>spring-boot-runtime</module>
|
||||||
|
@ -94,6 +90,10 @@
|
||||||
<module>spring-boot-3-observation</module>
|
<module>spring-boot-3-observation</module>
|
||||||
<module>spring-boot-3-test-pitfalls</module>
|
<module>spring-boot-3-test-pitfalls</module>
|
||||||
<module>spring-boot-resilience4j</module>
|
<module>spring-boot-resilience4j</module>
|
||||||
|
<module>spring-boot-properties</module>
|
||||||
|
<module>spring-boot-properties-2</module>
|
||||||
|
<module>spring-boot-properties-3</module>
|
||||||
|
<module>spring-boot-properties-migrator-demo</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
|
@ -10,9 +10,10 @@
|
||||||
<description>Spring Boot Properties Module</description>
|
<description>Spring Boot Properties Module</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-boot-modules</artifactId>
|
<artifactId>parent-boot-3</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-3</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -24,6 +25,15 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<start-class>com.baeldung.properties.yaml.YamlApplication</start-class>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -7,11 +7,12 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySource(name = "myProperties", value = "values.properties")
|
@PropertySource(name = "myProperties", value = "values.properties")
|
||||||
public class ValuesApp {
|
public class ValuesApp {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.properties.value.defaults;
|
package com.baeldung.properties.value.defaults;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
@ -8,10 +8,11 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demonstrates setting defaults for @Value annotation. Note that there are no properties
|
* Demonstrates setting defaults for @Value annotation. Note that there are no properties
|
||||||
* defined in the specified property source. We also assume that the user here
|
* defined in the specified property source. We also assume that the user here
|
||||||
|
@ -60,10 +61,10 @@ public class ValuesWithDefaultsApp {
|
||||||
|
|
||||||
// arrays
|
// arrays
|
||||||
List<String> stringListValues = Arrays.asList("one", "two", "three");
|
List<String> stringListValues = Arrays.asList("one", "two", "three");
|
||||||
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults");
|
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults");
|
||||||
|
|
||||||
List<Integer> intListValues = Arrays.asList(1, 2, 3);
|
List<Integer> intListValues = Arrays.asList(1, 2, 3);
|
||||||
Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults");
|
Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults");
|
||||||
|
|
||||||
// SpEL
|
// SpEL
|
||||||
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"), "unexpected value for spelWithDefaultValue");
|
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"), "unexpected value for spelWithDefaultValue");
|
||||||
|
|
|
@ -9,9 +9,10 @@
|
||||||
<description>Spring Boot Properties Module</description>
|
<description>Spring Boot Properties Module</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-boot-modules</artifactId>
|
<artifactId>parent-boot-3</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-3</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -31,7 +32,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<version>RELEASE</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -44,4 +44,8 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<start-class>com.baeldung.boot.properties.DemoApplication</start-class>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class EnvironmentPropertiesPrinter {
|
public class EnvironmentPropertiesPrinter {
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-boot-modules</artifactId>
|
<artifactId>parent-boot-3</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../../parent-boot-3</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<!-- Used to demonstrate a particular scenario in the article -->
|
<!-- Used to demonstrate a particular scenario in the article -->
|
||||||
<!-- <parent> -->
|
<!-- <parent> -->
|
||||||
|
@ -49,8 +49,8 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -10,9 +10,10 @@
|
||||||
<description>Spring Boot Properties Module</description>
|
<description>Spring Boot Properties Module</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-boot-modules</artifactId>
|
<artifactId>parent-boot-3</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-3</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -141,7 +142,7 @@
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<spring-cloud.version>2021.0.3</spring-cloud.version>
|
<spring-cloud.version>2022.0.1</spring-cloud.version>
|
||||||
<commons-configuration.version>1.10</commons-configuration.version>
|
<commons-configuration.version>1.10</commons-configuration.version>
|
||||||
<resource.delimiter>@</resource.delimiter>
|
<resource.delimiter>@</resource.delimiter>
|
||||||
<!-- <start-class>com.baeldung.buildproperties.Application</start-class> -->
|
<!-- <start-class>com.baeldung.buildproperties.Application</start-class> -->
|
||||||
|
|
|
@ -3,10 +3,10 @@ package com.baeldung.configurationproperties;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.validation.constraints.Max;
|
import jakarta.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Pattern;
|
import jakarta.validation.constraints.Pattern;
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package com.baeldung.configurationproperties;
|
package com.baeldung.configurationproperties;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "mail.credentials")
|
@ConfigurationProperties(prefix = "mail.credentials")
|
||||||
@ConstructorBinding
|
|
||||||
public class ImmutableCredentials {
|
public class ImmutableCredentials {
|
||||||
|
|
||||||
private final String authMethod;
|
private final String authMethod;
|
||||||
|
|
|
@ -4,12 +4,9 @@ import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
class BuildInfoServiceIntegrationTest {
|
class BuildInfoServiceIntegrationTest {
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class BuildPropertiesUnitTest {
|
||||||
@Test
|
@Test
|
||||||
void givenBuildPropertiesBean_WhenFetchDefaultBuildProperties_ThenGetValidValues() {
|
void givenBuildPropertiesBean_WhenFetchDefaultBuildProperties_ThenGetValidValues() {
|
||||||
Assertions.assertEquals("spring-boot-properties", buildProperties.getArtifact());
|
Assertions.assertEquals("spring-boot-properties", buildProperties.getArtifact());
|
||||||
Assertions.assertEquals("com.baeldung.spring-boot-modules", buildProperties.getGroup());
|
Assertions.assertEquals("com.baeldung", buildProperties.getGroup());
|
||||||
Assertions.assertEquals("0.0.1-SNAPSHOT", buildProperties.getVersion());
|
Assertions.assertEquals("0.0.1-SNAPSHOT", buildProperties.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,27 @@
|
||||||
package com.baeldung.properties.reloading;
|
package com.baeldung.properties.reloading;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import com.baeldung.properties.reloading.beans.ConfigurationPropertiesRefreshConfigBean;
|
import com.baeldung.properties.reloading.beans.ConfigurationPropertiesRefreshConfigBean;
|
||||||
import com.baeldung.properties.reloading.beans.EnvironmentConfigBean;
|
import com.baeldung.properties.reloading.beans.EnvironmentConfigBean;
|
||||||
import com.baeldung.properties.reloading.beans.PropertiesConfigBean;
|
import com.baeldung.properties.reloading.beans.PropertiesConfigBean;
|
||||||
import com.baeldung.properties.reloading.beans.ValueRefreshConfigBean;
|
import com.baeldung.properties.reloading.beans.ValueRefreshConfigBean;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@SpringBootTest(classes = SpringBootPropertiesTestApplication.class)
|
@SpringBootTest(classes = SpringBootPropertiesTestApplication.class)
|
||||||
public class PropertiesReloadManualTest {
|
public class PropertiesReloadManualTest {
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class PropertiesReloadManualTest {
|
||||||
ValueRefreshConfigBean singletonValueRefreshConfigBean;
|
ValueRefreshConfigBean singletonValueRefreshConfigBean;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mvc = MockMvcBuilders
|
mvc = MockMvcBuilders
|
||||||
.webAppContextSetup(webApplicationContext)
|
.webAppContextSetup(webApplicationContext)
|
||||||
|
@ -61,7 +60,7 @@ public class PropertiesReloadManualTest {
|
||||||
callRefresh();
|
callRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
createConfig("extra.properties", "application.theme.color", "blue");
|
createConfig("extra.properties", "application.theme.color", "blue");
|
||||||
createConfig("extra2.properties", "application.theme.background", "red");
|
createConfig("extra2.properties", "application.theme.background", "red");
|
||||||
|
@ -69,76 +68,76 @@ public class PropertiesReloadManualTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEnvironmentReader_whenColorChanged_thenExpectChangeValue() throws Exception {
|
public void givenEnvironmentReader_whenColorChanged_thenExpectChangeValue() throws Exception {
|
||||||
Assert.assertEquals("blue", environmentConfigBean.getColor());
|
assertEquals("blue", environmentConfigBean.getColor());
|
||||||
|
|
||||||
createConfig("extra.properties", "application.theme.color", "red");
|
createConfig("extra.properties", "application.theme.color", "red");
|
||||||
Thread.sleep(refreshDelay);
|
Thread.sleep(refreshDelay);
|
||||||
|
|
||||||
Assert.assertEquals("red", environmentConfigBean.getColor());
|
assertEquals("red", environmentConfigBean.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEnvironmentReader_whenBackgroundChanged_thenExpectChangeValue() throws Exception {
|
public void givenEnvironmentReader_whenBackgroundChanged_thenExpectChangeValue() throws Exception {
|
||||||
Assert.assertEquals("red", environmentConfigBean.getBackgroundColor());
|
assertEquals("red", environmentConfigBean.getBackgroundColor());
|
||||||
|
|
||||||
createConfig("extra2.properties", "application.theme.background", "blue");
|
createConfig("extra2.properties", "application.theme.background", "blue");
|
||||||
Thread.sleep(refreshDelay);
|
Thread.sleep(refreshDelay);
|
||||||
|
|
||||||
Assert.assertEquals("blue", environmentConfigBean.getBackgroundColor());
|
assertEquals("blue", environmentConfigBean.getBackgroundColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPropertiesReader_whenColorChanged_thenExpectChangeValue() throws Exception {
|
public void givenPropertiesReader_whenColorChanged_thenExpectChangeValue() throws Exception {
|
||||||
Assert.assertEquals("blue", propertiesConfigBean.getColor());
|
assertEquals("blue", propertiesConfigBean.getColor());
|
||||||
|
|
||||||
createConfig("extra.properties", "application.theme.color", "red");
|
createConfig("extra.properties", "application.theme.color", "red");
|
||||||
Thread.sleep(refreshDelay);
|
Thread.sleep(refreshDelay);
|
||||||
|
|
||||||
Assert.assertEquals("red", propertiesConfigBean.getColor());
|
assertEquals("red", propertiesConfigBean.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenRefreshScopedValueReader_whenColorChangedAndRefreshCalled_thenExpectChangeValue() throws Exception {
|
public void givenRefreshScopedValueReader_whenColorChangedAndRefreshCalled_thenExpectChangeValue() throws Exception {
|
||||||
Assert.assertEquals("blue", valueRefreshConfigBean.getColor());
|
assertEquals("blue", valueRefreshConfigBean.getColor());
|
||||||
|
|
||||||
createConfig("extra.properties", "application.theme.color", "red");
|
createConfig("extra.properties", "application.theme.color", "red");
|
||||||
Thread.sleep(refreshDelay);
|
Thread.sleep(refreshDelay);
|
||||||
|
|
||||||
Assert.assertEquals("blue", valueRefreshConfigBean.getColor());
|
assertEquals("blue", valueRefreshConfigBean.getColor());
|
||||||
|
|
||||||
callRefresh();
|
callRefresh();
|
||||||
|
|
||||||
Assert.assertEquals("red", valueRefreshConfigBean.getColor());
|
assertEquals("red", valueRefreshConfigBean.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSingletonRefreshScopedValueReader_whenColorChangedAndRefreshCalled_thenExpectOldValue() throws Exception {
|
public void givenSingletonRefreshScopedValueReader_whenColorChangedAndRefreshCalled_thenExpectOldValue() throws Exception {
|
||||||
|
|
||||||
Assert.assertEquals("blue", singletonValueRefreshConfigBean.getColor());
|
assertEquals("blue", singletonValueRefreshConfigBean.getColor());
|
||||||
|
|
||||||
createConfig("extra.properties", "application.theme.color", "red");
|
createConfig("extra.properties", "application.theme.color", "red");
|
||||||
Thread.sleep(refreshDelay);
|
Thread.sleep(refreshDelay);
|
||||||
|
|
||||||
Assert.assertEquals("blue", singletonValueRefreshConfigBean.getColor());
|
assertEquals("blue", singletonValueRefreshConfigBean.getColor());
|
||||||
|
|
||||||
callRefresh();
|
callRefresh();
|
||||||
|
|
||||||
Assert.assertEquals("blue", singletonValueRefreshConfigBean.getColor());
|
assertEquals("blue", singletonValueRefreshConfigBean.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenRefreshScopedConfigurationPropertiesReader_whenColorChangedAndRefreshCalled_thenExpectChangeValue() throws Exception {
|
public void givenRefreshScopedConfigurationPropertiesReader_whenColorChangedAndRefreshCalled_thenExpectChangeValue() throws Exception {
|
||||||
|
|
||||||
Assert.assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor());
|
assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor());
|
||||||
|
|
||||||
createConfig("extra.properties", "application.theme.color", "red");
|
createConfig("extra.properties", "application.theme.color", "red");
|
||||||
Thread.sleep(refreshDelay);
|
Thread.sleep(refreshDelay);
|
||||||
|
|
||||||
Assert.assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor());
|
assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor());
|
||||||
|
|
||||||
callRefresh();
|
callRefresh();
|
||||||
|
|
||||||
Assert.assertEquals("red", configurationPropertiesRefreshConfigBean.getColor());
|
assertEquals("red", configurationPropertiesRefreshConfigBean.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void callRefresh() throws Exception {
|
public void callRefresh() throws Exception {
|
||||||
|
@ -148,7 +147,7 @@ public class PropertiesReloadManualTest {
|
||||||
.accept(MediaType.APPLICATION_JSON_VALUE))
|
.accept(MediaType.APPLICATION_JSON_VALUE))
|
||||||
.andReturn();
|
.andReturn();
|
||||||
MockHttpServletResponse response = mvcResult.getResponse();
|
MockHttpServletResponse response = mvcResult.getResponse();
|
||||||
Assert.assertEquals(response.getStatus(), 200);
|
assertEquals(200, response.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createConfig(String file, String key, String value) throws Exception {
|
public void createConfig(String file, String key, String value) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue