[JAVA-27376] Moved article "Programmatically Restarting a Spring Boot… (#15412)

* [JAVA-27376] Moved article "Programmatically Restarting a Spring Boot Application" to spring-boot-runtime-2 module

* [JAVA-27367]
This commit is contained in:
panos-kakos
2023-12-13 21:58:43 +02:00
committed by GitHub
parent 9f7ec43036
commit 62c172f814
8 changed files with 25 additions and 2 deletions
@@ -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());
}
}