Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -44,8 +44,7 @@ public class SampleController {
|
||||
@GetMapping("/")
|
||||
@ResponseBody
|
||||
public Map<String, String> hello() {
|
||||
return Collections.singletonMap("message",
|
||||
this.helloWorldService.getHelloMessage());
|
||||
return Collections.singletonMap("message", this.helloWorldService.getHelloMessage());
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
|
||||
@@ -58,8 +58,8 @@ public class CorsSampleActuatorApplicationTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
|
||||
this.applicationContext.getEnvironment(), "http");
|
||||
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(),
|
||||
"http");
|
||||
restTemplate.setUriTemplateHandler(handler);
|
||||
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
|
||||
this.testRestTemplate = new TestRestTemplate(restTemplate);
|
||||
@@ -74,30 +74,24 @@ public class CorsSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void preflightRequestForInsensitiveShouldReturnOk() throws Exception {
|
||||
RequestEntity<?> healthRequest = RequestEntity.options(new URI("/health"))
|
||||
.header("Origin", "http://localhost:8080")
|
||||
.header("Access-Control-Request-Method", "GET").build();
|
||||
ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest,
|
||||
Map.class);
|
||||
.header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build();
|
||||
ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest, Map.class);
|
||||
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preflightRequestForSensitiveEndpointShouldReturnOk() throws Exception {
|
||||
RequestEntity<?> entity = RequestEntity.options(new URI("/env"))
|
||||
.header("Origin", "http://localhost:8080")
|
||||
RequestEntity<?> entity = RequestEntity.options(new URI("/env")).header("Origin", "http://localhost:8080")
|
||||
.header("Access-Control-Request-Method", "GET").build();
|
||||
ResponseEntity<?> env = this.testRestTemplate.exchange(entity, Map.class);
|
||||
assertThat(env.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden()
|
||||
throws Exception {
|
||||
RequestEntity<?> entity = RequestEntity.options(new URI("/health"))
|
||||
.header("Origin", "http://localhost:9095")
|
||||
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception {
|
||||
RequestEntity<?> entity = RequestEntity.options(new URI("/health")).header("Origin", "http://localhost:9095")
|
||||
.header("Access-Control-Request-Method", "GET").build();
|
||||
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity,
|
||||
byte[].class);
|
||||
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity, byte[].class);
|
||||
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testCustomErrorPath() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/oops", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -65,8 +65,7 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testCustomContextPath() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword())
|
||||
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
||||
.getForEntity("/admin/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
|
||||
@@ -42,8 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.port=0", "management.context-path=/admin",
|
||||
"management.security.enabled=false" })
|
||||
properties = { "management.port=0", "management.context-path=/admin", "management.security.enabled=false" })
|
||||
@DirtiesContext
|
||||
public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
|
||||
@@ -71,25 +70,23 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissing() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/missing",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(entity.getBody()).contains("\"status\":404");
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.security.enabled:false" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.security.enabled:false" })
|
||||
@DirtiesContext
|
||||
@ActiveProfiles("unsecure-management")
|
||||
public class InsecureManagementSampleActuatorApplicationTests {
|
||||
@@ -69,8 +68,7 @@ public class InsecureManagementSampleActuatorApplicationTests {
|
||||
// ignore;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics",
|
||||
Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
|
||||
@@ -39,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "security.basic.enabled:false" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "security.basic.enabled:false" })
|
||||
@DirtiesContext
|
||||
public class InsecureSampleActuatorApplicationTests {
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.port=0", "management.address=127.0.0.1",
|
||||
"management.context-path:/admin" })
|
||||
properties = { "management.port=0", "management.address=127.0.0.1", "management.context-path:/admin" })
|
||||
@DirtiesContext
|
||||
public class ManagementAddressActuatorApplicationTests {
|
||||
|
||||
@@ -54,16 +53,14 @@ public class ManagementAddressActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.context_path=/admin" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.context_path=/admin" })
|
||||
@DirtiesContext
|
||||
public class ManagementPathSampleActuatorApplicationTests {
|
||||
|
||||
@@ -48,8 +47,7 @@ public class ManagementPathSampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/admin/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/admin/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@@ -70,16 +70,15 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
@@ -87,9 +86,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testMissing() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/missing",
|
||||
String.class);
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(entity.getBody()).contains("\"status\":404");
|
||||
}
|
||||
@@ -97,8 +94,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testErrorPage() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/error", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/error",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -108,8 +105,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testManagementErrorPage() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
|
||||
@@ -41,8 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.port=0" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.port=0" })
|
||||
@DirtiesContext
|
||||
public class ManagementPortSampleActuatorApplicationTests {
|
||||
|
||||
@@ -70,15 +69,15 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/metrics", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/metrics", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/health", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
@@ -86,8 +85,8 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testErrorPage() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
|
||||
@@ -39,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.port=-1" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.port=-1" })
|
||||
@DirtiesContext
|
||||
public class NoManagementSampleActuatorApplicationTests {
|
||||
|
||||
@@ -53,8 +52,8 @@ public class NoManagementSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -65,8 +64,8 @@ public class NoManagementSampleActuatorApplicationTests {
|
||||
public void testMetricsNotAvailable() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/metrics", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "endpoints.health.sensitive=false" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "endpoints.health.sensitive=false" })
|
||||
@DirtiesContext
|
||||
public class NonSensitiveHealthTests {
|
||||
|
||||
@@ -46,8 +45,7 @@ public class NonSensitiveHealthTests {
|
||||
|
||||
@Test
|
||||
public void testSecureHealth() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).doesNotContain("\"hello\":1");
|
||||
}
|
||||
|
||||
@@ -71,8 +71,7 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testMetricsIsSecure() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics",
|
||||
Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
entity = this.restTemplate.getForEntity("/metrics/", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
@@ -85,8 +84,8 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -97,8 +96,8 @@ public class SampleActuatorApplicationTests {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/metrics", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -108,8 +107,8 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testEnv() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/env", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/env",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -118,8 +117,7 @@ public class SampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
assertThat(entity.getBody()).doesNotContain("\"hello\":\"1\"");
|
||||
@@ -127,31 +125,26 @@ public class SampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testSecureHealth() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword())
|
||||
.getForEntity("/health", String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/health",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"hello\":1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInfo() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/info",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/info", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody())
|
||||
.contains("\"artifact\":\"spring-boot-sample-actuator\"");
|
||||
assertThat(entity.getBody()).contains("\"artifact\":\"spring-boot-sample-actuator\"");
|
||||
assertThat(entity.getBody()).contains("\"someKey\":\"someValue\"");
|
||||
assertThat(entity.getBody()).contains("\"java\":{", "\"source\":\"1.8\"",
|
||||
"\"target\":\"1.8\"");
|
||||
assertThat(entity.getBody()).contains("\"encoding\":{", "\"source\":\"UTF-8\"",
|
||||
"\"reporting\":\"UTF-8\"");
|
||||
assertThat(entity.getBody()).contains("\"java\":{", "\"source\":\"1.8\"", "\"target\":\"1.8\"");
|
||||
assertThat(entity.getBody()).contains("\"encoding\":{", "\"source\":\"UTF-8\"", "\"reporting\":\"UTF-8\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorPage() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/foo", String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
String body = entity.getBody();
|
||||
assertThat(body).contains("\"error\":");
|
||||
@@ -162,9 +155,8 @@ public class SampleActuatorApplicationTests {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
||||
HttpEntity<?> request = new HttpEntity<Void>(headers);
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword())
|
||||
.exchange("/foo", HttpMethod.GET, request, String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo",
|
||||
HttpMethod.GET, request, String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
String body = entity.getBody();
|
||||
assertThat(body).as("Body was null").isNotNull();
|
||||
@@ -175,15 +167,15 @@ public class SampleActuatorApplicationTests {
|
||||
public void testTrace() throws Exception {
|
||||
this.restTemplate.getForEntity("/health", String.class);
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/trace", List.class);
|
||||
ResponseEntity<List> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/trace",
|
||||
List.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> list = entity.getBody();
|
||||
Map<String, Object> trace = list.get(list.size() - 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace
|
||||
.get("info")).get("headers")).get("response");
|
||||
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace.get("info"))
|
||||
.get("headers")).get("response");
|
||||
assertThat(map.get("status")).isEqualTo("200");
|
||||
}
|
||||
|
||||
@@ -191,15 +183,14 @@ public class SampleActuatorApplicationTests {
|
||||
public void traceWithParameterMap() throws Exception {
|
||||
this.restTemplate.getForEntity("/health?param1=value1", String.class);
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/trace", List.class);
|
||||
ResponseEntity<List> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/trace",
|
||||
List.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> list = entity.getBody();
|
||||
Map<String, Object> trace = list.get(0);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) trace
|
||||
.get("info")).get("parameters");
|
||||
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) trace.get("info")).get("parameters");
|
||||
assertThat(map.get("param1")).isNotNull();
|
||||
}
|
||||
|
||||
@@ -218,8 +209,8 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testBeans() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/beans", List.class);
|
||||
ResponseEntity<List> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/beans",
|
||||
List.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).hasSize(1);
|
||||
Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0);
|
||||
@@ -229,14 +220,12 @@ public class SampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testConfigProps() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword())
|
||||
.getForEntity("/configprops", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/configprops",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertThat(body)
|
||||
.containsKey("spring.datasource-" + DataSourceProperties.class.getName());
|
||||
assertThat(body).containsKey("spring.datasource-" + DataSourceProperties.class.getName());
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -50,8 +50,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/",
|
||||
Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -62,8 +61,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testMetricsIsSecure() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/metrics",
|
||||
Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/metrics", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "server.servletPath=/spring" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "server.servletPath=/spring" })
|
||||
@DirtiesContext
|
||||
public class ServletPathSampleActuatorApplicationTests {
|
||||
|
||||
@@ -49,8 +48,7 @@ public class ServletPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testErrorPath() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/error",
|
||||
Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/error", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -60,8 +58,7 @@ public class ServletPathSampleActuatorApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/spring/health",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/spring/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
@@ -69,8 +66,7 @@ public class ServletPathSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHomeIsSecure() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/",
|
||||
Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
|
||||
@@ -52,8 +52,8 @@ public class ShutdownSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword()).getForEntity("/", Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/",
|
||||
Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@@ -63,9 +63,8 @@ public class ShutdownSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testShutdown() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.restTemplate
|
||||
.withBasicAuth("user", getPassword())
|
||||
.postForEntity("/shutdown", null, Map.class);
|
||||
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).postForEntity("/shutdown",
|
||||
null, Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
|
||||
Reference in New Issue
Block a user