Package org.springframework.boot.test

Examples of org.springframework.boot.test.TestRestTemplate


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

  @Test
  public void contextLoads() {
    assertEquals("Hello World", new TestRestTemplate().getForObject(
        "http://localhost:" + this.port + "/", String.class));
  }
View Full Code Here


  }

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

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

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

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

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

  public void testFreeMarkerErrorTemplate() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    HttpEntity<String> requestEntity = new HttpEntity<String>(headers);

    ResponseEntity<String> responseEntity = new TestRestTemplate().exchange(
        "http://localhost:" + port + "/does-not-exist", HttpMethod.GET,
        requestEntity, String.class);

    assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
    assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody()
View Full Code Here

  private int port;

  @Test
  @SuppressWarnings("rawtypes")
  public void testErrorForMachineClient() throws Exception {
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port, Map.class);
    String body = entity.getBody().toString();
    assertThat(body, endsWith("status=500, " + "error=Internal Server Error, "
        + "exception=java.lang.IllegalStateException, " + "message=Expected!, "
        + "path=/}"));
View Full Code Here

  }

  @Test
  @SuppressWarnings("rawtypes")
  public void testErrorForAnnotatedException() throws Exception {
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
        "http://localhost:" + this.port + "/annotated", Map.class);
    assertThat(
        entity.getBody().toString(),
        endsWith("status=400, "
            + "error=Bad Request, "
View Full Code Here

  @SuppressWarnings("rawtypes")
  public void testBindingExceptionForMachineClient() throws Exception {
    RequestEntity request = RequestEntity
        .get(URI.create("http://localhost:" + this.port + "/bind"))
        .accept(MediaType.APPLICATION_JSON).build();
    ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
    String resp = entity.getBody().toString();
    assertThat(resp, containsString("Error count: 1"));
    assertThat(resp, containsString("errors=[{"));
    assertThat(resp, containsString("codes=["));
    assertThat(resp, containsString("org.springframework.validation.BindException"));
View Full Code Here

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

  @Test
  public void envEndpointNotHidden() {
    String body = new TestRestTemplate().getForObject("http://localhost:" + this.port
        + "/env/user.dir", String.class);
    assertNotNull(body);
    assertTrue("Wrong body: \n" + body, body.contains("spring-boot-actuator"));
  }
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.