use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testErrorForMachineClient.
@Test
@SuppressWarnings("rawtypes")
public void testErrorForMachineClient() throws Exception {
load();
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("?trace=true"), Map.class);
assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", IllegalStateException.class, "Expected!", "/");
assertThat(entity.getBody().containsKey("trace")).isFalse();
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testConventionTemplateMapping.
@Test
public void testConventionTemplateMapping() throws Exception {
load();
RequestEntity<?> request = RequestEntity.get(URI.create(createUrl("/noStorage"))).accept(MediaType.TEXT_HTML).build();
ResponseEntity<String> entity = new TestRestTemplate().exchange(request, String.class);
String resp = entity.getBody();
assertThat(resp).contains("We are out of storage");
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testErrorForAnnotatedNoReasonException.
@Test
@SuppressWarnings("rawtypes")
public void testErrorForAnnotatedNoReasonException() throws Exception {
load();
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/annotatedNoReason"), Map.class);
assertErrorAttributes(entity.getBody(), "406", "Not Acceptable", TestConfiguration.Errors.NoReasonExpectedException.class, "Expected message", "/annotatedNoReason");
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testErrorForMachineClientAlwaysStacktrace.
@Test
@SuppressWarnings("rawtypes")
public void testErrorForMachineClientAlwaysStacktrace() throws Exception {
load("--server.error.include-stacktrace=always");
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("?trace=false"), Map.class);
assertErrorAttributes(entity.getBody(), "500", "Internal Server Error", IllegalStateException.class, "Expected!", "/");
assertThat(entity.getBody().containsKey("trace")).isTrue();
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testRequestBodyValidationForMachineClient.
@Test
@SuppressWarnings("rawtypes")
public void testRequestBodyValidationForMachineClient() throws Exception {
load();
RequestEntity request = RequestEntity.post(URI.create(createUrl("/bodyValidation"))).contentType(MediaType.APPLICATION_JSON).body("{}");
ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
String resp = entity.getBody().toString();
assertThat(resp).contains("Error count: 1");
assertThat(resp).contains("errors=[{");
assertThat(resp).contains("codes=[");
assertThat(resp).contains(MethodArgumentNotValidException.class.getName());
}
Aggregations