use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testErrorForMachineClientNoStacktrace.
@Test
@SuppressWarnings("rawtypes")
public void testErrorForMachineClientNoStacktrace() throws Exception {
load("--server.error.include-stacktrace=never");
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 testBindingExceptionForMachineClient.
@Test
@SuppressWarnings("rawtypes")
public void testBindingExceptionForMachineClient() throws Exception {
load();
RequestEntity request = RequestEntity.get(URI.create(createUrl("/bind"))).accept(MediaType.APPLICATION_JSON).build();
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("org.springframework.validation.BindException");
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class DevToolsIntegrationTests method createAController.
@Test
public void createAController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerTwo").withRequestMapping("two").build();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/two", String.class)).isEqualTo("two");
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class DevToolsIntegrationTests method deleteAController.
@Test
public void deleteAController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one", String.class)).isEqualTo("one");
assertThat(new File(this.launchedApplication.getClassesDirectory(), "com/example/ControllerOne.class").delete()).isTrue();
assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one", String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class HalBrowserMvcEndpointServerServletPathIntegrationTests method actuatorBrowserRedirect.
@Test
public void actuatorBrowserRedirect() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET, new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create("http://localhost:" + this.port + "/spring/actuator/browser.html"));
}
Aggregations