Package org.springframework.boot.test

Examples of org.springframework.boot.test.TestRestTemplate


        entity.getBody().contains("\"hello\":1"));
  }

  @Test
  public void testInfo() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/info", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body: " + entity.getBody(),
        entity.getBody().contains("\"artifact\":\"spring-boot-sample-actuator\""));
  }
View Full Code Here


        entity.getBody().contains("\"artifact\":\"spring-boot-sample-actuator\""));
  }

  @Test
  public void testErrorPage() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
        .getForEntity("http://localhost:" + this.port + "/foo", String.class);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
    String body = entity.getBody();
    assertNotNull(body);
    assertTrue("Wrong body: " + body, body.contains("\"error\":"));
View Full Code Here

  @Test
  public void testHtmlErrorPage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    HttpEntity<?> request = new HttpEntity<Void>(headers);
    ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
        .exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET,
            request, String.class);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
    String body = entity.getBody();
    assertNotNull("Body was null", body);
View Full Code Here

        body.contains("This application has no explicit mapping for /error"));
  }

  @Test
  public void testTrace() throws Exception {
    new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/health",
        String.class);
    @SuppressWarnings("rawtypes")
    ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
        .getForEntity("http://localhost:" + this.port + "/trace", List.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> list = entity.getBody();
    Map<String, Object> trace = list.get(list.size() - 1);
View Full Code Here

  }

  @Test
  public void testErrorPageDirectAccess() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/error", Map.class);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertEquals("None", body.get("error"));
View Full Code Here

  }

  @Test
  public void testBeans() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
        .getForEntity("http://localhost:" + this.port + "/beans", List.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals(1, entity.getBody().size());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0);
View Full Code Here

  private int port;

  @Test
  public void testHome() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
        .getForEntity("http://localhost:" + this.port, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertEquals("Hello Phil", body.get("message"));
View Full Code Here

  }

  @Test
  public void testShutdown() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
        .postForEntity("http://localhost:" + this.port + "/shutdown", null,
            Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
View Full Code Here

  @Value("${local.server.port}")
  private int port;

  @Test
  public void testJspWithEl() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(),
        entity.getBody().contains("/resources/text.txt"));
  }
View Full Code Here

  @Value("${local.server.port}")
  private int port;

  @Test
  public void testJspWithEl() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(),
        entity.getBody().contains("/resources/text.txt"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.boot.test.TestRestTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.