[BAEL-16767] - Fix the integrations tests in spring-boot-ops
This commit is contained in:
parent
a3d7b77c13
commit
f7957e2fa8
@ -91,6 +91,12 @@
|
|||||||
<version>${springcloud.version}</version>
|
<version>${springcloud.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>${httpclient.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -191,6 +197,7 @@
|
|||||||
<guava.version>18.0</guava.version>
|
<guava.version>18.0</guava.version>
|
||||||
<subethasmtp.version>3.1.7</subethasmtp.version>
|
<subethasmtp.version>3.1.7</subethasmtp.version>
|
||||||
<springcloud.version>2.0.2.RELEASE</springcloud.version>
|
<springcloud.version>2.0.2.RELEASE</springcloud.version>
|
||||||
|
<httpclient.version>4.5.8</httpclient.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -6,13 +6,13 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
public class ConfProperties {
|
public class ConfProperties {
|
||||||
|
|
||||||
@Value("${url}")
|
@Value("${db.url}")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@Value("${username}")
|
@Value("${db.username}")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Value("${password}")
|
@Value("${db.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
url=jdbc:postgresql://localhost:5432/
|
db.url=jdbc:postgresql://localhost:5432/
|
||||||
username=admin
|
db.username=admin
|
||||||
password=root
|
db.password=root
|
||||||
spring.main.allow-bean-definition-overriding=true
|
spring.main.allow-bean-definition-overriding=true
|
@ -2,25 +2,24 @@ package com.baeldung.restart;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.junit.After;
|
import java.io.IOException;
|
||||||
import org.junit.Before;
|
import java.net.ServerSocket;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class RestartApplicationIntegrationTest {
|
public class RestartApplicationIntegrationTest {
|
||||||
|
|
||||||
private TestRestTemplate restTemplate = new TestRestTemplate();
|
private TestRestTemplate restTemplate = new TestRestTemplate();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenBootApp_whenRestart_thenOk() throws Exception {
|
public void givenBootApp_whenRestart_thenOk() throws Exception {
|
||||||
Application.main(new String[0]);
|
Integer port = findRandomOpenPortOnAllLocalInterfaces();
|
||||||
|
Application.main(new String[] { String.format("--server.port=%d", port) });
|
||||||
|
|
||||||
ResponseEntity response = restTemplate.exchange("http://localhost:8080/restart",
|
ResponseEntity response = restTemplate.exchange(String.format("http://localhost:%d/restart", port),
|
||||||
HttpMethod.POST, null, Object.class);
|
HttpMethod.POST, null, Object.class);
|
||||||
|
|
||||||
assertEquals(200, response.getStatusCode().value());
|
assertEquals(200, response.getStatusCode().value());
|
||||||
@ -28,12 +27,18 @@ public class RestartApplicationIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenBootApp_whenRestartUsingActuator_thenOk() throws Exception {
|
public void givenBootApp_whenRestartUsingActuator_thenOk() throws Exception {
|
||||||
Application.main(new String[] { "--server.port=8090" });
|
Integer port = findRandomOpenPortOnAllLocalInterfaces();
|
||||||
|
Application.main(new String[] { String.format("--server.port=%d", port) });
|
||||||
|
|
||||||
ResponseEntity response = restTemplate.exchange("http://localhost:8090/restartApp",
|
ResponseEntity response = restTemplate.exchange(String.format("http://localhost:%d/restartApp", port),
|
||||||
HttpMethod.POST, null, Object.class);
|
HttpMethod.POST, null, Object.class);
|
||||||
|
|
||||||
assertEquals(200, response.getStatusCode().value());
|
assertEquals(200, response.getStatusCode().value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer findRandomOpenPortOnAllLocalInterfaces() throws IOException {
|
||||||
|
try (ServerSocket socket = new ServerSocket(0);) {
|
||||||
|
return socket.getLocalPort();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user