Package org.springframework.boot.test

Examples of org.springframework.boot.test.TestRestTemplate


  private int port = 0;

  @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 {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.managementPort + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
  }
View Full Code Here

  @Test
  public void testMetricsNotAvailable() 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.NOT_FOUND, 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());
    assertEquals("{\"status\":\"UP\"}", entity.getBody());
  }
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

    }
    catch (AssertionError ex) {
      // ignore;
    }
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().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.401.unmapped"));
View Full Code Here

  @Test
  public void testHome() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange(
        "http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(
            headers), String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity
        .getBody().contains("<title>Hello"));
View Full Code Here

        .getBody().contains("<title>Hello"));
  }

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

  }

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

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

  @Test
  public void testHealth() 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.