Search in sources :

Example 56 with TestRestTemplate

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();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Map(java.util.Map) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 57 with TestRestTemplate

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");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) RequestEntity(org.springframework.http.RequestEntity) Map(java.util.Map) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 58 with TestRestTemplate

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");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test)

Example 59 with TestRestTemplate

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);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) File(java.io.File) Test(org.junit.Test)

Example 60 with TestRestTemplate

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"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)75 Test (org.junit.Test)67 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)53 Map (java.util.Map)23 HttpHeaders (org.springframework.http.HttpHeaders)15 Before (org.junit.Before)5 RequestEntity (org.springframework.http.RequestEntity)2 OAuth2ContextConfiguration (org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 JSONArray (net.minidev.json.JSONArray)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1