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:org.sventon.web.ctrl.ConfigurationReloadControllerTest.java

@Test
public void reloadConfigFileHappyPath() throws Exception {

    ResponseEntity<String> response = controller.reloadConfigAndReinitializeApplication();
    assertThat(response.getBody(), equalTo("Configuration reloaded."));
    assertThat(response.getStatusCode(), equalTo(OK));
    assertContentType(response);/*from   w ww . jav  a 2s  . co  m*/
}

From source file:com.github.codersparks.dockerservice.HelloWorldConfigurationTests.java

@Test
public void testGreetingWorld() throws Exception {
    ResponseEntity<Greeting> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/",
            Greeting.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());

    Greeting greeting = entity.getBody();

    assertEquals("hello", greeting.getGreeting());
    assertEquals("world", greeting.getName());
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.legacy.impl.LegacySystemRepositoryImpl.java

private boolean isLegacySystemResponseValid(ResponseEntity<LegacySearchResponse> entityResponse) {
    if (!HttpStatus.OK.equals(entityResponse.getStatusCode())) {
        logger.error(".getLegacyCategoriesForCatDocRef : response from legacy system != 200: {}",
                entityResponse.getStatusCode());
        return true;
    }// ww  w .  j av  a  2s.co  m
    LegacySearchResponse searchResponse = entityResponse.getBody();
    if ((searchResponse.getSearchResult().getTotalResults() == null)
            || searchResponse.getSearchResult().getTotalResults() == 0) {
        logger.info(".getLegacyCategoriesForCatDocRef : no element found");
        return true;
    }
    return false;
}

From source file:com.allogy.amazonaws.elasticbeanstalk.worker.simulator.application.WorkerApplication.java

public HttpStatus forward(MessageWrapper messageWrapper) {
    Message message = messageWrapper.getMessage();
    HttpEntity<String> messageEntity = createHttpEntity(messageWrapper, message);

    logger.info("Forwarding message: messageId={}", messageWrapper.getMessage().getMessageId());

    try {/* ww w  .jav  a  2s  .  c  o  m*/
        ResponseEntity<String> responseEntity = restTemplate.exchange(targetUrl, HttpMethod.POST, messageEntity,
                String.class);
        return responseEntity.getStatusCode();
    } catch (HttpStatusCodeException ex) {
        HttpStatus statusCode = ex.getStatusCode();
        logger.error("The HTTP Worker Application returned a non successful error code. statusCode={}",
                statusCode);
        return statusCode;
    } catch (RestClientException ex) {
        logger.error("Unable to connect to the HTTP Worker Application.");
        return HttpStatus.NOT_FOUND;
    }
}

From source file:com.batch.traditional.SampleTraditionalApplicationTests.java

@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>"));
}

From source file:com.dimalimonov.tracking.rest.template.impl.FedexRestTemplateImpl.java

@Override
public String getStatus(String id) {
    String trackingRequest = getTrackingRequest(id);

    logger.debug("Request Body {}", trackingRequest);

    ResponseEntity<String> response = postForEntity(serverUrl, trackingRequest, String.class);

    String responseBody = response.getBody();
    logger.debug("Response code  {}", response.getStatusCode());
    logger.debug("Response Body {}", responseBody);

    return responseBody;

}

From source file:com.salatigacode.dao.ProductControllerTests.java

@Test
public void testDelete() {
    HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<Object> entity = new HttpEntity<>(headers);
    ResponseEntity<String> responseEntity = restTemplate.exchange(BASE_URL + "abc123", HttpMethod.DELETE,
            entity, String.class);
    Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode().OK);
}

From source file:name.bpdp.bootswipl.BootSwiplAppTests.java

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

From source file:net.eusashead.hateoas.response.impl.PostResponseBuilderImplTest.java

@Test
public void testBuildUri() throws Exception {
    ResponseEntity<Void> response = builder.location("/url/to/entity").build();
    Assert.assertNotNull(response);/*  ww  w . j  a v  a  2 s .  c  o  m*/
    Assert.assertEquals(HttpStatus.CREATED, response.getStatusCode());
    Assert.assertNull(response.getBody());
    Assert.assertNotNull(response.getHeaders().getLocation());
    Assert.assertEquals(new URI("/url/to/entity"), response.getHeaders().getLocation());
    Assert.assertNull(response.getHeaders().getETag());
    Assert.assertEquals(-1l, response.getHeaders().getLastModified());
    Assert.assertNull(response.getHeaders().getCacheControl());
    Assert.assertEquals(-1l, response.getHeaders().getExpires());
    Assert.assertEquals(-1l, response.getHeaders().getDate());
}

From source file:org.camunda.bpm.spring.boot.starter.webapp.WebappEeTest.java

@Test
public void testLicenseEndpointAvailable() throws Exception {
    final ResponseEntity<String> response = testRestTemplate.getForEntity(
            "http://localhost:" + this.port + "/api/admin/plugin/license/default/key", String.class);

    assertEquals(HttpStatus.OK, response.getStatusCode());
}