BAEL-2351 programmatically restart spring boot application

This commit is contained in:
mprevisic
2018-12-11 01:30:10 +01:00
parent 7ddcb76c09
commit 3e685aa12d
8 changed files with 280 additions and 2 deletions
@@ -0,0 +1,34 @@
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;
public class RestartApplicationIntegrationTest {
private TestRestTemplate template = new TestRestTemplate();
@Test
public void givenBootApp_whenRestart_thenOk() throws Exception {
Application.main(new String[0]);
ResponseEntity response = template.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 = template.exchange("http://localhost:8090/restartApp",
HttpMethod.POST, null, Object.class);
assertEquals(200, response.getStatusCode().value());
}
}