Provide links for actuators at / when using a separate management port

See gh-17418
This commit is contained in:
HaiTao Zhang
2019-07-02 18:18:29 -07:00
committed by Madhura Bhave
parent edea223841
commit c108629311
11 changed files with 147 additions and 10 deletions

View File

@@ -0,0 +1,37 @@
package smoketest.actuator;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.web.base-path=/","management.server.port=0"})
public class ManagementDifferentPortSampleActuatorApplicationTests {
@LocalServerPort
private int port;
@LocalManagementPort
private int managementPort;
@Test
void testDifferentServerPort(){
if(this.managementPort != this.port) {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\"");
}
}
private String getPassword(){
return "password";
}
}

View File

@@ -0,0 +1,35 @@
package smoketest.jersey;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"management.server.port=0","management.endpoints.web.base-path=/"})
public class JerseyDifferentPortSampleActuatorApplicationTests {
@LocalManagementPort
private int managementPort;
@LocalServerPort
private int port;
@Test
void testDifferentServerPort(){
if(this.managementPort != this.port) {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\"");
}
}
private String getPassword(){
return "password";
}
}

View File

@@ -0,0 +1,35 @@
package smoketest.webflux;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"management.server.port=0","management.endpoints.web.base-path=/"})
public class WebFluxDifferentPortSampleActuatorApplicationTests {
@LocalManagementPort
private int managementPort;
@LocalServerPort
private int port;
@Test
void testDifferentServerPort(){
if(this.managementPort != this.port) {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\"");
}
}
private String getPassword(){
return "password";
}
}