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.ge.predix.acs.commons.web.ResponseEntityBuilderTest.java

@Test
public void testCreatedWithLocation() {
    ResponseEntity<Object> created = ResponseEntityBuilder.created("/report/1", Boolean.FALSE);

    Assert.assertNotNull(created);/*from ww w  .j a  v  a  2s  . c o m*/
    Assert.assertNull(created.getBody());
    Assert.assertEquals(created.getStatusCode(), HttpStatus.CREATED);

    Assert.assertNotNull(created.getHeaders());
    URI location = created.getHeaders().getLocation();
    Assert.assertEquals(location.getPath(), "/report/1");
}

From source file:de.swm.nis.logicaldecoding.gwc.GWCInvalidator.java

private void postSeedRequest(Envelope envelope) {

    String gwcurl = gwcBaseUrl + "seed/" + layername + ".json";

    Bounds bounds = new Bounds(
            new Coordinates(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY()));
    Srs srs = new Srs(epsgCode);
    SeedRequest request = new SeedRequest(layername, bounds, srs, zoomStart, zoomStop, imageFormat, operation,
            numThreads);// w ww. ja v  a  2  s.  c  om

    HttpEntity<GwcSeedDAO> httpentity = new HttpEntity<GwcSeedDAO>(new GwcSeedDAO(request),
            createHeaders(gwcUserName, gwcPassword));
    ResponseEntity response = template.exchange(gwcurl, HttpMethod.POST, httpentity, String.class);
    HttpStatus returncode = response.getStatusCode();
    if (!returncode.is2xxSuccessful()) {
        log.warn("HTTP Call to " + gwcurl + " was not successfull, Status code: " + response.getStatusCode());
    } else {
        log.debug("HTTP Call to " + gwcurl + "succeeded");
    }

}

From source file:org.trustedanalytics.servicebroker.h2o.service.H2oProvisionerClient.java

@Override
public String deprovisionInstance(String serviceInstanceId) throws ServiceBrokerException {
    ResponseEntity<String> deleteH2oInstanceResponse;
    try {// w  w  w . ja va2s.com
        deleteH2oInstanceResponse = h2oRest.deleteH2oInstance(serviceInstanceId, yarnConf);
        LOGGER.info("response: '" + deleteH2oInstanceResponse.getStatusCode() + "'");
    } catch (RestClientException e) {
        throw new ServiceBrokerException("Unable to deprovision h2o for: " + serviceInstanceId, e);
    }

    if (deleteH2oInstanceResponse.getStatusCode() == HttpStatus.OK) {
        return deleteH2oInstanceResponse.getBody();
    } else {
        throw new ServiceBrokerException("Unable to deprovision h2o for: " + serviceInstanceId);
    }
}

From source file:com.opensearchserver.hadse.index.IndexTest.java

@Test
public void t01_deleteIndex() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.DELETE, null,
            String.class);
    assertNotNull(entity);/*  www  . j  a  v  a  2s . co  m*/
    HttpStatus res = entity.getStatusCode();
    assertNotNull(res);
    switch (res) {
    case OK:
        assertEquals(HttpStatus.OK, res);
        break;
    case NOT_FOUND:
        assertEquals(HttpStatus.NOT_FOUND, res);
        break;
    default:
        fail("Unexpected result: " + res);
        break;
    }
}

From source file:com.salmon.security.xacml.demo.springmvc.rest.HTTPPopulatorsTest.java

@Test
public void testAllDataIsErased() {

    this.createOneDriver();
    this.createOneVehicle();

    ResponseEntity<Integer> entity = this.eraseAllData();

    Integer totalItemsDeleted = entity.getBody();
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals(2, totalItemsDeleted.intValue());
}

From source file:com.create.controller.AuthenticationIT.java

@Test
public void shouldReturnAnUserForAuthorizedPost() {
    final ResponseEntity<User> response = authenticatedUserTestRestTemplate.postForEntity(TEST_POST_PATH, null,
            User.class);
    assertThat(response.getStatusCode(), is(HttpStatus.OK));
    assertThat(response.getBody().getUsername(), is(TICKET_SERVICE_USER));
}

From source file:com.interop.webapp.WebAppTests.java

private HttpHeaders getHeaders() {
    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<String> page = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/login", String.class);
    assertEquals(HttpStatus.OK, page.getStatusCode());
    String cookie = page.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(page.getBody());
    assertTrue("No csrf token: " + page.getBody(), matcher.matches());
    headers.set("X-CSRF-TOKEN", matcher.group(1));
    return headers;
}

From source file:sample.jetty.SampleJetty8ApplicationTests.java

@Test
public void testHomeBasicAuthNoCredentials403() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/static.html", String.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}

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

@Test
public void assureThatToResponseWithNullExceptionIsLogged() throws Exception {
    ServerException exception = null;
    ResponseEntity<?> response = responseManager.toResponse(exception);
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));
    verify(logManager).logIncomingCallEnd(Mockito.argThat(new TestInstanceOfMatcher<>(HawaiiException.class)));
}

From source file:be.boyenvaesen.Humidity.HumidityControllerTest.java

@Test
public void testScenarioPostOneGetList() {
    //Set up date that will be posted
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   www  . ja v a 2 s .com*/
    cal.add(Calendar.MINUTE, 15); // add 10 minutes
    Date postedDate = cal.getTime();

    //Check if list is the list from setup
    ResponseEntity<Humidity[]> responseEntity = restTemplate.getForEntity("/humidity", Humidity[].class);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    Humidity[] humidities = responseEntity.getBody();

    assertEquals(75.1f, humidities[0].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(80f, humidities[1].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(2, humidities.length);

    //Post a new Humidity
    ResponseEntity<Humidity> postedEntity = restTemplate.postForEntity("/humidity",
            new postObject<>(95f, postedDate), Humidity.class);
    Humidity postedHumidity = postedEntity.getBody();
    assertEquals(HttpStatus.CREATED, postedEntity.getStatusCode());
    assertEquals(95f, postedHumidity.getPercentage(), MAX_ASSERT_FLOAT_OFFSET);

    //Check if list is now changed with the new value
    responseEntity = restTemplate.getForEntity("/humidity", Humidity[].class);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    humidities = responseEntity.getBody();
    //Check humidity percentages
    assertEquals(75.1f, humidities[0].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(postedHumidity.getPercentage(), humidities[humidities.length - 1].getPercentage(),
            MAX_ASSERT_FLOAT_OFFSET);
    assertEquals(95f, humidities[humidities.length - 1].getPercentage(), MAX_ASSERT_FLOAT_OFFSET);
    //Check humidity dates
    assertEquals(postedHumidity.getMeasured().getTime(),
            humidities[humidities.length - 1].getMeasured().getTime(), MAX_ASSERT_DATE_MILLISECONDS_OFFSET);
    assertEquals(postedDate.getTime(), humidities[humidities.length - 1].getMeasured().getTime(),
            MAX_ASSERT_DATE_MILLISECONDS_OFFSET);
    //Check list length
    assertEquals(3, humidities.length);

}