Package org.springframework.boot.test

Examples of org.springframework.boot.test.TestRestTemplate


  private int port;

  @Test
  public void testHome() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().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


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

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

    assertTrue("Wrong body:\n" + body, body.contains("<h1>Home</h1>"));
  }

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

  private int port;

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

  }

  @Test
  public void testMetricsIsSecure() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port
        + "/metrics/", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port
        + "/metrics/foo", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port
        + "/metrics.json", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
  }
View Full Code Here

  }

  @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("user", getPassword())
        .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertTrue("Wrong body: " + body, body.containsKey("counter.status.200.root"));
View Full Code Here

  }

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

    assertTrue("Wrong body: " + body, body.containsKey("systemProperties"));
  }

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

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

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