Example usage for org.springframework.http ResponseEntity getStatusCode

List of usage examples for org.springframework.http ResponseEntity getStatusCode

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity getStatusCode.

Prototype

public HttpStatus getStatusCode() 

Source Link

Document

Return the HTTP status code of the response.

Usage

From source file:com.muhardin.endy.training.ws.aplikasi.absen.rest.client.AbsenRestClient.java

public List<Karyawan> semuaKaryawan() {
    ParameterizedTypeReference<List<Karyawan>> typeRef = new ParameterizedTypeReference<List<Karyawan>>() {
    };/* ww w .j a  va2 s  .c o  m*/

    ResponseEntity<List<Karyawan>> response = restTemplate.exchange(SERVER_URL + "/karyawan/", HttpMethod.GET,
            null, typeRef);

    System.out.println("Response Status : " + response.getStatusCode());

    return response.getBody();
}

From source file:sample.tomcat.X509ApplicationTests.java

@Test
public void testAuthenticatedHello() throws Exception {
    RestTemplate template = new TestRestTemplate();
    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(
            httpClient());//from  www .  j av a  2s .c o m
    template.setRequestFactory(factory);

    ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello",
            String.class);
    assertEquals(HttpStatus.OK, httpsEntity.getStatusCode());
    assertEquals("hello", httpsEntity.getBody());
}

From source file:de.codecentric.boot.admin.web.CorsFilterOnDifferentPortsTest.java

@Test
@SuppressWarnings("rawtypes")
public void testCORS_GET_info_endpoint() {
    // DO serve CORS-Headers on management-endpoints
    ResponseEntity<Map> info = new TestRestTemplate()
            .getForEntity("http://localhost:" + managementPort + "/info", Map.class);
    assertEquals(HttpStatus.OK, info.getStatusCode());
    assertEquals(Arrays.asList("*"), info.getHeaders().get("Access-Control-Allow-Origin"));
    assertEquals(Arrays.asList("Origin, X-Requested-With, Content-Type, Accept"),
            info.getHeaders().get("Access-Control-Allow-Headers"));
}

From source file:info.rajesh.ui.SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
    assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), MediaType.valueOf("text/css"),
            entity.getHeaders().getContentType());
}

From source file:io.kahu.hawaii.rest.DefaultResponseManagerTest.java

@Test
public void testThatEmptyResponseIsOk() throws Exception {
    ResponseEntity<?> response = responseManager.toResponse();
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));
}

From source file:sample.webstatic.SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
    assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(),
            MediaType.valueOf("text/css;charset=UTF-8"), entity.getHeaders().getContentType());
}

From source file:com.cloudbees.jenkins.plugins.demo.actuator.ManagementPortSampleActuatorApplicationTests.java

@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("ok", entity.getBody());
}

From source file:com.trenako.web.images.WebImageServiceTests.java

@Test
public void shouldRenderImages() {
    GridFSDBFile mockFile = mock(GridFSDBFile.class);
    when(mockFile.getContentType()).thenReturn(MediaType.IMAGE_JPEG.toString());
    when(mockFile.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[] {}));

    when(repo.findFileBySlug(eq("img-slug"))).thenReturn(mockFile);

    ResponseEntity<byte[]> resp = service.renderImage("img-slug");

    assertNotNull(resp);/* w  w w.java2  s  .c om*/
    assertTrue(resp.hasBody());
    assertEquals(HttpStatus.CREATED, resp.getStatusCode());
    assertEquals(MediaType.IMAGE_JPEG, resp.getHeaders().getContentType());
}

From source file:org.kurento.repository.test.util.HttpRepositoryTest.java

protected void downloadFromURL(String urlToDownload, File downloadedFile) throws Exception {

    RestTemplate template = getRestTemplate();
    ResponseEntity<byte[]> entity = template.getForEntity(urlToDownload, byte[].class);

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

    FileOutputStream os = new FileOutputStream(downloadedFile);
    os.write(entity.getBody());//from   ww w. j  av  a 2s  .  com
    os.close();
}

From source file:io.syndesis.runtime.ConnectorsITCase.java

public void verifyBadTwitterConnectionSettings() throws IOException {

    // AlwaysOkVerifier never fails.. do don't try this test case, if that's whats being used.
    Assume.assumeFalse(verifier instanceof AlwaysOkVerifier);

    Properties credentials = new Properties();
    try (InputStream is = getClass().getResourceAsStream("/valid-twitter-keys.properties")) {
        credentials.load(is);/*from   ww w  .  ja v  a2  s .c  o  m*/
    }
    credentials.put("accessTokenSecret", "badtoken");

    ResponseEntity<Verifier.Result> response = post("/api/v1/connectors/twitter/verifier/connectivity",
            credentials, Verifier.Result.class);
    assertThat(response.getStatusCode()).as("component list status code").isEqualTo(HttpStatus.OK);
    Verifier.Result result = response.getBody();
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(Verifier.Result.Status.ERROR);
    assertThat(result.getErrors()).isNotEmpty();
}