Package org.springframework.boot.test

Examples of org.springframework.boot.test.TestRestTemplate


        .getBody().contains("Access denied"));
  }

  @Test
  public void testManagementProtected() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/beans", String.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
  }
View Full Code Here


    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
  }

  @Test
  public void testManagementAuthorizedAccess() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
        .getForEntity("http://localhost:" + this.port + "/beans", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
  }
View Full Code Here

    assertEquals(HttpStatus.OK, entity.getStatusCode());
  }

  @Test
  public void testManagementUnauthorizedAccess() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate("user", "user")
        .getForEntity("http://localhost:" + this.port + "/beans", String.class);
    assertEquals(HttpStatus.FORBIDDEN, entity.getStatusCode());
  }
View Full Code Here

        .getForEntity("http://localhost:" + this.port + "/beans", String.class);
    assertEquals(HttpStatus.FORBIDDEN, entity.getStatusCode());
  }

  private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) {
    ResponseEntity<String> page = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/login", String.class);
    String cookie = page.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    String body = page.getBody();
    Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*")
 
View Full Code Here

  private int managementPort = 9011;

  @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 testMetrics() throws Exception {
    testHome(); // makes sure some requests have been made
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.managementPort + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
  }
View Full Code Here

    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
  }

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

  }

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

  private int port;

  @Test
  public void testCustomErrorPath() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate("user", "password")
        .getForEntity("http://localhost:" + this.port + "/oops", 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

    assertEquals(999, body.get("status"));
  }

  @Test
  public void testCustomContextPath() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/admin/health", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body: " + entity.getBody(),
        entity.getBody().contains("\"status\":\"UP\""));
  }
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.