Search in sources :

Example 51 with TestRestTemplate

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

the class SampleActuatorUiApplicationPortTests method testHome.

@Test
public void testHome() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with TestRestTemplate

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

the class InsecureManagementPortAndPathSampleActuatorApplicationTests method testHome.

@Test
public void testHome() throws Exception {
    @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()).getForEntity("http://localhost:" + this.port, Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody();
    assertThat(body.get("message")).isEqualTo("Hello Phil");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with TestRestTemplate

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

the class InsecureManagementPortAndPathSampleActuatorApplicationTests method testHealth.

@Test
public void testHealth() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 54 with TestRestTemplate

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

the class ManagementPortAndPathSampleActuatorApplicationTests method testMissing.

@Test
public void testMissing() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()).getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    assertThat(entity.getBody()).contains("\"status\":404");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 55 with TestRestTemplate

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

the class ManagementPortAndPathSampleActuatorApplicationTests method testMetrics.

@Test
public void testMetrics() throws Exception {
    // makes sure some requests have been made
    testHome();
    @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Map(java.util.Map) 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