diff --git a/STATUS.adoc b/STATUS.adoc index acde31b..22cfd8e 100644 --- a/STATUS.adoc +++ b/STATUS.adoc @@ -126,3 +126,22 @@ h|test |=== +== Cloud + +[%header,cols="4"] +|=== +h|Smoke Test +h|appTest +h|checkpointRestoreAppTest +h|test + +|context-refresh-http +|image:https://ci.spring.io/api/v1/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-http-app-test/badge[link=https://ci.spring.io/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-http-app-test] +|image:https://ci.spring.io/api/v1/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-http-cr-app-test/badge[link=https://ci.spring.io/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-http-cr-app-test] +|image:https://ci.spring.io/api/v1/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-http-test/badge[link=https://ci.spring.io/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-http-test] +|context-refresh +| +|image:https://ci.spring.io/api/v1/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-cr-app-test/badge[link=https://ci.spring.io/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-cr-app-test] +|image:https://ci.spring.io/api/v1/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-test/badge[link=https://ci.spring.io/teams/spring-checkpoint-restore-smoke-tests/pipelines/spring-checkpoint-restore-smoke-tests-3.2.x/jobs/context-refresh-test] +|=== + diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index 520873d..95222b0 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -55,3 +55,11 @@ groups: - name: spring-kafka-streams app_test: true test: false + - name: cloud + smoke_tests: + - name: context-refresh-http + app_test: true + test: true + - name: context-refresh + app_test: false + test: false \ No newline at end of file diff --git a/cloud/context-refresh-http/build.gradle b/cloud/context-refresh-http/build.gradle new file mode 100644 index 0000000..c4babe2 --- /dev/null +++ b/cloud/context-refresh-http/build.gradle @@ -0,0 +1,33 @@ +plugins { + id "java" + id "org.springframework.boot" + id "org.springframework.cr.smoke-test" + id 'io.spring.dependency-management' +} + +ext { + set('springCloudVersion', "2023.0.0-SNAPSHOT") +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.crac:crac:$cracVersion") + implementation(project(":cr-listener")) + implementation("org.springframework.cloud:spring-cloud-starter") + implementation("org.springframework.boot:spring-boot-starter-actuator") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + appTestImplementation(project(":cr-smoke-test-support")) +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + +crSmokeTest { + webApplication = true +} diff --git a/cloud/context-refresh-http/dev.properties b/cloud/context-refresh-http/dev.properties new file mode 100644 index 0000000..df04ce4 --- /dev/null +++ b/cloud/context-refresh-http/dev.properties @@ -0,0 +1,2 @@ +simple.test=testVal +test=propVal diff --git a/cloud/context-refresh-http/src/appTest/java/com/example/contextrefreshhttp/ContextRefreshHttpApplicationTests.java b/cloud/context-refresh-http/src/appTest/java/com/example/contextrefreshhttp/ContextRefreshHttpApplicationTests.java new file mode 100644 index 0000000..9145193 --- /dev/null +++ b/cloud/context-refresh-http/src/appTest/java/com/example/contextrefreshhttp/ContextRefreshHttpApplicationTests.java @@ -0,0 +1,81 @@ +package com.example.contextrefreshhttp; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import org.springframework.cr.smoketest.support.junit.ApplicationTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@ApplicationTest +public class ContextRefreshHttpApplicationTests { + + @AfterAll + static void cleanUp() throws IOException { + editExternalConfigurationProperties(""" + simple.test=testVal + test=propVal + """); + } + + @Test + void refreshScopeBean(WebTestClient webClient) throws IOException { + webClient.get() + .uri("/refresh") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith(result -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("propVal")); + editExternalConfigurationProperties(""" + simple.test=testVal + test=propValNew + """); + webClient.post().uri("/actuator/refresh").exchange().expectStatus().isOk(); + + webClient.get() + .uri("/refresh") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith(result -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("propValNew")); + } + + @Test + void configurationProperties(WebTestClient webClient) throws IOException { + webClient.get() + .uri("/simple") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith(result -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("testVal")); + editExternalConfigurationProperties(""" + simple.test=testValNew + test=propVal + """); + webClient.post().uri("/actuator/refresh").exchange().expectStatus().isOk(); + + webClient.get() + .uri("/simple") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith(result -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("testValNew")); + } + + private static void editExternalConfigurationProperties(String newFileContent) throws IOException { + Files.writeString(Path.of("././dev.properties"), newFileContent, Charset.defaultCharset(), + StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); + } + +} diff --git a/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/ContextRefreshHttpApplication.java b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/ContextRefreshHttpApplication.java new file mode 100644 index 0000000..0718aa5 --- /dev/null +++ b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/ContextRefreshHttpApplication.java @@ -0,0 +1,17 @@ +package com.example.contextrefreshhttp; + +import com.example.contextrefreshhttp.config.SimpleConfigurationProperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +@SpringBootApplication +@EnableConfigurationProperties(SimpleConfigurationProperties.class) +public class ContextRefreshHttpApplication { + + public static void main(String[] args) { + SpringApplication.run(ContextRefreshHttpApplication.class, args); + } + +} \ No newline at end of file diff --git a/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/RefreshScopeController.java b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/RefreshScopeController.java new file mode 100644 index 0000000..82c4200 --- /dev/null +++ b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/RefreshScopeController.java @@ -0,0 +1,22 @@ +package com.example.contextrefreshhttp; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/refresh") +@RefreshScope +public class RefreshScopeController { + + @Value("${test}") + private String test; + + @GetMapping + String test() { + return test; + } + +} diff --git a/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/SimpleController.java b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/SimpleController.java new file mode 100644 index 0000000..d0e12e5 --- /dev/null +++ b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/SimpleController.java @@ -0,0 +1,24 @@ +package com.example.contextrefreshhttp; + +import com.example.contextrefreshhttp.config.SimpleConfigurationProperties; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/simple") +public class SimpleController { + + private final SimpleConfigurationProperties properties; + + public SimpleController(SimpleConfigurationProperties properties) { + this.properties = properties; + } + + @GetMapping + String test() { + return properties.getTest(); + } + +} diff --git a/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/config/SimpleConfigurationProperties.java b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/config/SimpleConfigurationProperties.java new file mode 100644 index 0000000..f84bd1d --- /dev/null +++ b/cloud/context-refresh-http/src/main/java/com/example/contextrefreshhttp/config/SimpleConfigurationProperties.java @@ -0,0 +1,18 @@ +package com.example.contextrefreshhttp.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "simple") +public class SimpleConfigurationProperties { + + private String test = "default"; + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + +} diff --git a/cloud/context-refresh-http/src/main/resources/application.yml b/cloud/context-refresh-http/src/main/resources/application.yml new file mode 100644 index 0000000..6079caa --- /dev/null +++ b/cloud/context-refresh-http/src/main/resources/application.yml @@ -0,0 +1,17 @@ +spring: + cloud: + refresh: + on-restart: + enabled: false + application: + name: context-refresh-http + config: + import: file:./cloud/context-refresh-http/dev.properties + +management: + endpoints: + web: + exposure: + include: + - refresh + - env diff --git a/cloud/context-refresh-http/src/test/java/com/example/contextrefreshhttp/ContextRefreshHttpTests.java b/cloud/context-refresh-http/src/test/java/com/example/contextrefreshhttp/ContextRefreshHttpTests.java new file mode 100644 index 0000000..0f39f14 --- /dev/null +++ b/cloud/context-refresh-http/src/test/java/com/example/contextrefreshhttp/ContextRefreshHttpTests.java @@ -0,0 +1,77 @@ +package com.example.contextrefreshhttp; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.MediaType; +import org.springframework.http.RequestEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class ContextRefreshHttpTests { + + @Autowired + private TestRestTemplate restTemplate; + + @AfterAll + static void setUp() throws IOException { + editExternalConfigurationProperties(""" + simple.test=testVal + test=propVal + """); + } + + @Test + void refreshScopeBean() throws IOException { + String property = this.restTemplate.getForObject("/refresh", String.class); + assertThat(property).isEqualTo("propVal"); + editExternalConfigurationProperties(""" + simple.test=testVal + test=propValNew + """); + + RequestEntity request = RequestEntity.post("/actuator/refresh") + .contentType(MediaType.APPLICATION_JSON) + .build(); + + this.restTemplate.postForObject("/actuator/refresh", request, String.class); + + String updatedProperty = this.restTemplate.getForObject("/refresh", String.class); + assertThat(updatedProperty).isEqualTo("propValNew"); + } + + @Test + void configurationProperties() throws IOException { + String property = this.restTemplate.getForObject("/simple", String.class); + assertThat(property).isEqualTo("testVal"); + editExternalConfigurationProperties(""" + simple.test=testValNew + test=propVal + """); + + RequestEntity request = RequestEntity.post("/actuator/refresh") + .contentType(MediaType.APPLICATION_JSON) + .build(); + + this.restTemplate.postForObject("/actuator/refresh", request, String.class); + + String updatedProperty = this.restTemplate.getForObject("/simple", String.class); + assertThat(updatedProperty).isEqualTo("testValNew"); + } + + static void editExternalConfigurationProperties(String newFileContent) throws IOException { + Files.writeString(Path.of("././dev.properties"), newFileContent, Charset.defaultCharset(), + StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); + } + +} diff --git a/cloud/context-refresh-http/src/test/resources/application.yml b/cloud/context-refresh-http/src/test/resources/application.yml new file mode 100644 index 0000000..123129c --- /dev/null +++ b/cloud/context-refresh-http/src/test/resources/application.yml @@ -0,0 +1,17 @@ +spring: + cloud: + refresh: + on-restart: + enabled: false + application: + name: context-refresh-http + config: + import: file:././dev.properties + +management: + endpoints: + web: + exposure: + include: + - refresh + - env diff --git a/cloud/context-refresh/build.gradle b/cloud/context-refresh/build.gradle new file mode 100644 index 0000000..ddbeb5c --- /dev/null +++ b/cloud/context-refresh/build.gradle @@ -0,0 +1,37 @@ +plugins { + id "java" + id "org.springframework.boot" + id "org.springframework.cr.smoke-test" + id 'io.spring.dependency-management' +} + +ext { + set('springCloudVersion', "2023.0.0-SNAPSHOT") +} + +dependencies { + implementation(platform( + org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.crac:crac:$cracVersion") + implementation(project(":cr-listener")) + implementation("org.springframework.cloud:spring-cloud-starter") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + appTestImplementation(project(":cr-smoke-test-support")) +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + +crSmokeTest { + webApplication = true +} + +// `@ApplicationTest`s need to only be executed during the `checkpointRestoreAppTest and not `appTest` +// (we're checking for a value that we want to have been modified in between these two phases). +project.gradle.startParameter.excludedTaskNames.add("appTest") \ No newline at end of file diff --git a/cloud/context-refresh/dev.properties b/cloud/context-refresh/dev.properties new file mode 100644 index 0000000..df04ce4 --- /dev/null +++ b/cloud/context-refresh/dev.properties @@ -0,0 +1,2 @@ +simple.test=testVal +test=propVal diff --git a/cloud/context-refresh/src/appTest/java/com/example/contextrefresh/ContextRefreshApplicationTests.java b/cloud/context-refresh/src/appTest/java/com/example/contextrefresh/ContextRefreshApplicationTests.java new file mode 100644 index 0000000..e489c0f --- /dev/null +++ b/cloud/context-refresh/src/appTest/java/com/example/contextrefresh/ContextRefreshApplicationTests.java @@ -0,0 +1,57 @@ +package com.example.contextrefresh; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import org.springframework.cr.smoketest.support.junit.ApplicationTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@ApplicationTest +public class ContextRefreshApplicationTests { + + // Bring the config file back to init values before next app start, + // since the app updates the property file after properties set + @AfterAll + static void cleanUp() throws IOException { + editExternalConfigurationProperties(""" + simple.test=testVal + test=propVal + """); + } + + @Test + void refreshScopeBean(WebTestClient webClient) { + webClient.get() + .uri("/refresh") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith(result -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("propValNew")); + } + + @Test + void configurationProperties(WebTestClient webClient) { + webClient.get() + .uri("/simple") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith(result -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("testValNew")); + } + + private static void editExternalConfigurationProperties(String newFileContent) throws IOException { + Files.writeString(Path.of("./dev.properties"), newFileContent, Charset.defaultCharset(), + StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); + } + +} diff --git a/cloud/context-refresh/src/main/java/com/example/contextrefresh/ConfigUpdateController.java b/cloud/context-refresh/src/main/java/com/example/contextrefresh/ConfigUpdateController.java new file mode 100644 index 0000000..65371de --- /dev/null +++ b/cloud/context-refresh/src/main/java/com/example/contextrefresh/ConfigUpdateController.java @@ -0,0 +1,50 @@ +package com.example.contextrefresh; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ConfigUpdateController { + + private static final Log LOG = LogFactory.getLog(ConfigUpdateController.class); + + @Value("${config.path}") + private String path; + + @EventListener(ApplicationStartedEvent.class) + public void doSomethingAfterStartup() throws IOException { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating file values"); + } + editExternalConfigurationProperties(""" + simple.test=testValNew + test=propValNew + """); + } + + @GetMapping("/reset") + void reset() throws IOException { + editExternalConfigurationProperties(""" + simple.test=testVal + test=propVal + """); + } + + private void editExternalConfigurationProperties(String newFileContent) throws IOException { + Files.writeString(Path.of(path), newFileContent, Charset.defaultCharset(), StandardOpenOption.WRITE, + StandardOpenOption.TRUNCATE_EXISTING); + } + +} diff --git a/cloud/context-refresh/src/main/java/com/example/contextrefresh/ContextRefreshApplication.java b/cloud/context-refresh/src/main/java/com/example/contextrefresh/ContextRefreshApplication.java new file mode 100644 index 0000000..2d92b50 --- /dev/null +++ b/cloud/context-refresh/src/main/java/com/example/contextrefresh/ContextRefreshApplication.java @@ -0,0 +1,17 @@ +package com.example.contextrefresh; + +import com.example.contextrefresh.config.SimpleConfigurationProperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +@SpringBootApplication +@EnableConfigurationProperties(SimpleConfigurationProperties.class) +public class ContextRefreshApplication { + + public static void main(String[] args) { + SpringApplication.run(ContextRefreshApplication.class, args); + } + +} \ No newline at end of file diff --git a/cloud/context-refresh/src/main/java/com/example/contextrefresh/RefreshScopeController.java b/cloud/context-refresh/src/main/java/com/example/contextrefresh/RefreshScopeController.java new file mode 100644 index 0000000..cedbd91 --- /dev/null +++ b/cloud/context-refresh/src/main/java/com/example/contextrefresh/RefreshScopeController.java @@ -0,0 +1,22 @@ +package com.example.contextrefresh; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/refresh") +@RefreshScope +public class RefreshScopeController { + + @Value("${test}") + private String test; + + @GetMapping + String test() { + return test; + } + +} diff --git a/cloud/context-refresh/src/main/java/com/example/contextrefresh/SimpleController.java b/cloud/context-refresh/src/main/java/com/example/contextrefresh/SimpleController.java new file mode 100644 index 0000000..a1e9eea --- /dev/null +++ b/cloud/context-refresh/src/main/java/com/example/contextrefresh/SimpleController.java @@ -0,0 +1,24 @@ +package com.example.contextrefresh; + +import com.example.contextrefresh.config.SimpleConfigurationProperties; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/simple") +public class SimpleController { + + private final SimpleConfigurationProperties properties; + + public SimpleController(SimpleConfigurationProperties properties) { + this.properties = properties; + } + + @GetMapping + String test() { + return properties.getTest(); + } + +} diff --git a/cloud/context-refresh/src/main/java/com/example/contextrefresh/config/SimpleConfigurationProperties.java b/cloud/context-refresh/src/main/java/com/example/contextrefresh/config/SimpleConfigurationProperties.java new file mode 100644 index 0000000..601ee74 --- /dev/null +++ b/cloud/context-refresh/src/main/java/com/example/contextrefresh/config/SimpleConfigurationProperties.java @@ -0,0 +1,18 @@ +package com.example.contextrefresh.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "simple") +public class SimpleConfigurationProperties { + + private String test = "default"; + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + +} diff --git a/cloud/context-refresh/src/main/resources/application.yml b/cloud/context-refresh/src/main/resources/application.yml new file mode 100644 index 0000000..8903318 --- /dev/null +++ b/cloud/context-refresh/src/main/resources/application.yml @@ -0,0 +1,8 @@ +spring: + application: + name: context-refresh + config: + import: file:./cloud/context-refresh/dev.properties + +config: + path: ./cloud/context-refresh/dev.properties diff --git a/cloud/context-refresh/src/test/java/com/example/contextrefresh/ContextRefreshTests.java b/cloud/context-refresh/src/test/java/com/example/contextrefresh/ContextRefreshTests.java new file mode 100644 index 0000000..a68e512 --- /dev/null +++ b/cloud/context-refresh/src/test/java/com/example/contextrefresh/ContextRefreshTests.java @@ -0,0 +1,37 @@ +package com.example.contextrefresh; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class ContextRefreshTests { + + @Autowired + private TestRestTemplate restTemplate; + + @AfterEach + void cleanUp() { + restTemplate.getForObject("/reset", Void.class); + } + + // Verify for initial values only + @Test + void refreshScopeBean() { + String property = this.restTemplate.getForObject("/refresh", String.class); + assertThat(property).isEqualTo("propVal"); + } + + // Verify for initial values only + @Test + void configurationProperties() { + String property = this.restTemplate.getForObject("/simple", String.class); + assertThat(property).isEqualTo("testVal"); + } + +} diff --git a/cloud/context-refresh/src/test/resources/application.yml b/cloud/context-refresh/src/test/resources/application.yml new file mode 100644 index 0000000..d15743b --- /dev/null +++ b/cloud/context-refresh/src/test/resources/application.yml @@ -0,0 +1,8 @@ +spring: + application: + name: context-refresh + config: + import: file:././dev.properties + +config: + path: ././dev.properties \ No newline at end of file diff --git a/framework/webclient-netty/src/main/java/com/example/webclient/WebClientConfiguration.java b/framework/webclient-netty/src/main/java/com/example/webclient/WebClientConfiguration.java index cf797dd..29f94c7 100644 --- a/framework/webclient-netty/src/main/java/com/example/webclient/WebClientConfiguration.java +++ b/framework/webclient-netty/src/main/java/com/example/webclient/WebClientConfiguration.java @@ -12,11 +12,10 @@ class WebClientConfiguration { @Bean WebClient webClient(WebClient.Builder builder, ClientHttpConnector clientHttpConnector) { // TODO Check why run-dev-container.sh is broken by the commented line below - //String host = env("HTTPBIN_HOST", "localhost"); + // String host = env("HTTPBIN_HOST", "localhost"); String host = "localhost"; int port = env("HTTPBIN_PORT_8080", 8080); - return builder.baseUrl("http://%s:%d/".formatted(host, port)) - .clientConnector(clientHttpConnector).build(); + return builder.baseUrl("http://%s:%d/".formatted(host, port)).clientConnector(clientHttpConnector).build(); } private static String env(String name, String def) { diff --git a/settings.gradle b/settings.gradle index ecc96a2..804005b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,8 +27,8 @@ rootProject.name="spring-checkpoint-restore-smoke-tests" include "cr-smoke-test-support" include "cr-listener" -["boot", "data", "framework", "integration"].each { group -> +["boot", "cloud", "data", "framework", "integration"].each { group -> file(group).eachDirMatch(~/[a-z].*/) { smokeTest -> include "$group:${smokeTest.name}" } -} +} \ No newline at end of file