[BAEL-16767] - Fix the integrations tests in spring-boot-ops

This commit is contained in:
amit2103 2019-08-31 22:49:12 +05:30
parent a3d7b77c13
commit f7957e2fa8
4 changed files with 30 additions and 18 deletions

View File

@ -85,11 +85,17 @@
<version>${jquery.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>${springcloud.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
</dependencies>
@ -190,7 +196,8 @@
<jpa.version>2.2</jpa.version>
<guava.version>18.0</guava.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>
</project>

View File

@ -6,13 +6,13 @@ import org.springframework.stereotype.Component;
@Component
public class ConfProperties {
@Value("${url}")
@Value("${db.url}")
private String url;
@Value("${username}")
@Value("${db.username}")
private String username;
@Value("${password}")
@Value("${db.password}")
private String password;
public String getUrl() {

View File

@ -1,4 +1,4 @@
url=jdbc:postgresql://localhost:5432/
username=admin
password=root
db.url=jdbc:postgresql://localhost:5432/
db.username=admin
db.password=root
spring.main.allow-bean-definition-overriding=true

View File

@ -2,25 +2,24 @@ package com.baeldung.restart;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import java.io.IOException;
import java.net.ServerSocket;
import org.junit.Test;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import java.time.Duration;
public class RestartApplicationIntegrationTest {
private TestRestTemplate restTemplate = new TestRestTemplate();
@Test
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);
assertEquals(200, response.getStatusCode().value());
@ -28,12 +27,18 @@ public class RestartApplicationIntegrationTest {
@Test
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);
assertEquals(200, response.getStatusCode().value());
}
private Integer findRandomOpenPortOnAllLocalInterfaces() throws IOException {
try (ServerSocket socket = new ServerSocket(0);) {
return socket.getLocalPort();
}
}
}