Search in sources :

Example 26 with TestRestTemplate

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();
}
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 27 with TestRestTemplate

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

Example 28 with TestRestTemplate

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");
}
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 29 with TestRestTemplate

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();
}
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 30 with TestRestTemplate

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

Aggregations

TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)70 Test (org.junit.Test)67 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)53 Map (java.util.Map)23 HttpHeaders (org.springframework.http.HttpHeaders)15 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