From cfa1b4dfc4104ec8fe70d965c8b51e1ccd1ac485 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sat, 7 Sep 2019 19:51:25 +0530 Subject: [PATCH] [BAEL-16767] - Renamed RestartApplicationIntegrationTest to RestartApplicationManualTest --- .../RestartApplicationIntegrationTest.java | 44 ------------------- .../restart/RestartApplicationManualTest.java | 38 ++++++++++++++++ 2 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationIntegrationTest.java create mode 100644 spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationManualTest.java diff --git a/spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationIntegrationTest.java b/spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationIntegrationTest.java deleted file mode 100644 index 48c876de87..0000000000 --- a/spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationIntegrationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.restart; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.net.ServerSocket; - -import org.junit.Test; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; - -public class RestartApplicationIntegrationTest { - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - @Test - public void givenBootApp_whenRestart_thenOk() throws Exception { - Integer port = findRandomOpenPortOnAllLocalInterfaces(); - Application.main(new String[] { String.format("--server.port=%d", port) }); - - ResponseEntity response = restTemplate.exchange(String.format("http://localhost:%d/restart", port), - HttpMethod.POST, null, Object.class); - - assertEquals(200, response.getStatusCode().value()); - } - - @Test - public void givenBootApp_whenRestartUsingActuator_thenOk() throws Exception { - Integer port = findRandomOpenPortOnAllLocalInterfaces(); - Application.main(new String[] { String.format("--server.port=%d", port) }); - - 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(); - } - } -} \ No newline at end of file diff --git a/spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationManualTest.java b/spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationManualTest.java new file mode 100644 index 0000000000..35b488f9d8 --- /dev/null +++ b/spring-boot-ops/src/test/java/com/baeldung/restart/RestartApplicationManualTest.java @@ -0,0 +1,38 @@ +package com.baeldung.restart; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +/** + * We have to make sure that while running this test, 8080 and 8090 ports are free. + * Otherwise it will fail. + */ +public class RestartApplicationManualTest { + + private TestRestTemplate restTemplate = new TestRestTemplate(); + + @Test + public void givenBootApp_whenRestart_thenOk() throws Exception { + Application.main(new String[0]); + + ResponseEntity response = restTemplate.exchange("http://localhost:8080/restart", + HttpMethod.POST, null, Object.class); + + assertEquals(200, response.getStatusCode().value()); + } + + @Test + public void givenBootApp_whenRestartUsingActuator_thenOk() throws Exception { + Application.main(new String[] { "--server.port=8090" }); + + ResponseEntity response = restTemplate.exchange("http://localhost:8090/restartApp", + HttpMethod.POST, null, Object.class); + + assertEquals(200, response.getStatusCode().value()); + } + +} \ No newline at end of file