Search in sources :

Example 16 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class DevToolsIntegrationTests method addARequestMappingToAnExistingController.

@Test
public void addARequestMappingToAnExistingController() 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.ControllerOne").withRequestMapping("one").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 17 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class DevToolsIntegrationTests method removeARequestMappingFromAnExistingController.

@Test
public void removeARequestMappingFromAnExistingController() throws Exception {
    TestRestTemplate template = new TestRestTemplate();
    assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one", String.class)).isEqualTo("one");
    controller("com.example.ControllerOne").build();
    assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one", String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test)

Example 18 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class EndpointMvcIntegrationTests method envEndpointNotHidden.

@Test
public void envEndpointNotHidden() throws InterruptedException {
    String body = new TestRestTemplate().getForObject("http://localhost:" + this.port + "/env/user.dir", String.class);
    assertThat(body).isNotNull().contains("spring-boot-actuator");
    assertThat(this.interceptor.invoked()).isTrue();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class HalBrowserMvcEndpointServerServletPathIntegrationTests method linksAddedToHomePage.

@Test
public void linksAddedToHomePage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/spring/", HttpMethod.GET, new HttpEntity<Void>(null, headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("\"_links\":");
}
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)

Example 20 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.

the class HalBrowserMvcEndpointServerServletPathIntegrationTests method actuatorLinks.

@Test
public void actuatorLinks() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    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.OK);
    assertThat(entity.getBody()).contains("\"_links\":");
}
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)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