Add Context Refresh Hikari sample

Closes gh-39
This commit is contained in:
Olga MaciaszekSharma
2023-10-05 13:32:13 +02:00
committed by Sébastien Deleuze
parent f01a91d613
commit f9d6380b59
22 changed files with 385 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings({ "JUnitMalformedDeclaration", "DataFlowIssue" })
@ApplicationTest
public class ContextRefreshApplicationTests {
@@ -21,10 +22,7 @@ public class ContextRefreshApplicationTests {
// since the app updates the property file after properties set
@AfterAll
static void cleanUp() throws IOException {
editExternalConfigurationProperties("""
simple.test=testVal
test=propVal
""");
editExternalConfigurationProperties();
}
@Test
@@ -49,9 +47,11 @@ public class ContextRefreshApplicationTests {
.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);
private static void editExternalConfigurationProperties() throws IOException {
Files.writeString(Path.of("./dev.properties"), """
simple.test=testVal
test=propVal
""", Charset.defaultCharset(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}
}

View File

@@ -1,4 +1,4 @@
package com.example.contextrefresh;
package com.example.contextrefresh.controllers;
import java.io.IOException;
import java.nio.charset.Charset;
@@ -24,7 +24,7 @@ public class ConfigUpdateController {
private String path;
@EventListener(ApplicationStartedEvent.class)
public void doSomethingAfterStartup() throws IOException {
public void editExternalConfig() throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("Updating file values");
}

View File

@@ -1,4 +1,4 @@
package com.example.contextrefresh;
package com.example.contextrefresh.controllers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;

View File

@@ -1,4 +1,4 @@
package com.example.contextrefresh;
package com.example.contextrefresh.controllers;
import com.example.contextrefresh.config.SimpleConfigurationProperties;