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.crazyacking.learn.spring.actuator.SampleActuatorApplicationTests.java

@Test
public void testErrorPage() {
    ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo",
            String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    String body = entity.getBody();
    assertThat(body).contains("\"error\":");
}

From source file:com.ge.predix.integration.test.ACSPerformanceIT.java

@Test(invocationCount = 2)
public void testPolicyEvalPerformanceWithLargePolicySet() throws Exception {

    PolicyEvaluationRequestV1 request = this.policyHelper.createEvalRequest(NOT_MATCHING_ACTION,
            this.defaultSubject.getSubjectIdentifier(),
            (new BaseResource(DEFAULT_RESOURCE_IDENTIFIER)).getResourceIdentifier(), null);

    ResponseEntity<PolicyEvaluationResult> postForEntity = this.acsRestTemplate.postForEntity(
            this.zoneUrl + PolicyHelper.ACS_POLICY_EVAL_API_PATH, request, PolicyEvaluationResult.class);

    Assert.assertEquals(postForEntity.getStatusCode(), HttpStatus.OK);
    PolicyEvaluationResult responseBody = postForEntity.getBody();
    Assert.assertEquals(responseBody.getEffect(), Effect.DENY);

}

From source file:de.qaware.cloud.nativ.zwitscher.monitor.ZwitscherMonitorApplicationTests.java

@Test
public void componentNameIsAvailableUsingInfoEndpoint() {
    ResponseEntity<String> responseEntity = testRestTemplate.getForEntity(HOST + DEFINED_PORT + "/info",
            String.class);
    assertNotNull("responseEntity is null", responseEntity);
    assertEquals("wrong status code", HttpStatus.OK, responseEntity.getStatusCode());
    assertTrue(responseEntity.getBody().contains(environment.getProperty("info.component")));
}

From source file:de.qaware.cloud.nativ.zwitscher.board.ZwitscherBoardApplicationTests.java

@Test
public void healthEndpointIsReachable() {
    ResponseEntity<String> responseEntity = testRestTemplate.getForEntity(HOST + DEFINED_PORT + "/health",
            String.class);
    assertNotNull("responseEntity is null", responseEntity);
    assertEquals("wrong status code", HttpStatus.OK, responseEntity.getStatusCode());
    assertTrue(responseEntity.getBody().contains("UP"));
}

From source file:id.co.teleanjar.ppobws.restclient.RestClientService.java

public Map<String, Object> inquiry(String idpel, String idloket, String merchantCode) throws IOException {
    String uri = "http://localhost:8080/ppobws/api/produk";
    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = createHeaders("superuser", "passwordku");
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("idpel", idpel)
            .queryParam("idloket", idloket).queryParam("merchantcode", merchantCode);
    HttpEntity<?> entity = new HttpEntity<>(headers);

    ResponseEntity<String> httpResp = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
            entity, String.class);
    String json = httpResp.getBody();
    LOGGER.info("JSON [{}]", json);
    LOGGER.info("STATUS [{}]", httpResp.getStatusCode().toString());

    Map<String, Object> map = new HashMap<>();
    ObjectMapper mapper = new ObjectMapper();

    map = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() {
    });/*from  w  w w .  ja  v  a2 s. c  o  m*/
    return map;
}

From source file:io.acme.solution.api.test.ProfileApplicationTest.java

@Test
public void testProfileRegistration() {

    try {/*from  www  .j  a v a2 s .  com*/
        final URL profileAppURL = new URL(this.base, RESTKeys.Profile.BASE + RESTKeys.Profile.REGISTRATION);
        final UserProfile testProfile = new UserProfile("testname", "test@email.com", "password");
        final MessageReceiver receiver = this.context.getBean(MessageReceiver.class);
        final ResponseEntity<CommandPromise> responseEntity = this.restTemplate
                .postForEntity(profileAppURL.toURI(), testProfile, CommandPromise.class);

        Assert.assertThat(responseEntity.getStatusCode(), Matchers.equalTo(HttpStatus.OK));
        Assert.assertThat(responseEntity.getBody().getId(), Matchers.notNullValue());

        receiver.getLatch().await(1000, TimeUnit.MILLISECONDS);

        final RegisterNewUserProfileCommand publishedCommand = receiver.getLastMessage();

        Assert.assertThat(publishedCommand, Matchers.instanceOf(RegisterNewUserProfileCommand.class));
        Assert.assertThat(publishedCommand.getUsername(), Matchers.equalTo("testname"));
        Assert.assertThat(publishedCommand.getEmail(), Matchers.equalTo("test@email.com"));

    } catch (MalformedURLException exception) {
        log.error("Could not open a test server socket for profile solution");
        log.trace("Test profile solution URL is malformed", exception);
        Assert.fail();
    } catch (URISyntaxException exception) {
        log.error("Could not hit profile solution endpoint");
        log.trace("Test profile solution URI is malformed", exception);
        Assert.fail();
    } catch (InterruptedException exception) {
        log.error("Could get the published command from the bus");
        log.trace("Waiting for command to get published is timeout", exception);
        Assert.fail();
    }

}

From source file:de.qaware.cloud.nativ.zwitscher.eureka.ZwitscherEurekaApplicationTests.java

@Test
public void componentNameIsAvailableUsingInfoEndpoint() {
    ResponseEntity<String> responseEntity = this.testRestTemplate
            .getForEntity(HOST + DEFINED_PORT + "/admin/info", String.class);
    assertNotNull("responseEntity is null", responseEntity);
    assertEquals("wrong status code", HttpStatus.OK, responseEntity.getStatusCode());
    assertTrue(responseEntity.getBody().contains(environment.getProperty("info.component")));
}

From source file:de.qaware.cloud.nativ.zwitscher.monitor.ZwitscherMonitorApplicationTests.java

@Test
public void healthEndpointIsReachable() {
    ResponseEntity<String> responseEntity = testRestTemplate.getForEntity(HOST + DEFINED_PORT + "/health",
            String.class);
    assertNotNull("responseEntity is null", responseEntity);
    assertEquals("wrong status code", HttpStatus.OK, responseEntity.getStatusCode());
    assertTrue("health Endpoint is not reachable", responseEntity.getBody().contains("UP"));
}

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

@Test
public void testAllHeaders() throws Exception {
    Entity entity = new Entity("foo");
    Date now = new Date(1373571924000l);
    ResponseEntity<Entity> response = builder.entity(entity).etag().lastModified(now).expireIn(1000l).build();
    Assert.assertNotNull(response);/*ww  w  .  j av a  2s.  c  o  m*/
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    Assert.assertEquals(entity, response.getBody());
    Assert.assertNotNull(response.getHeaders().getETag());
    Assert.assertEquals("W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"", response.getHeaders().getETag());
    Assert.assertEquals(now.getTime(), response.getHeaders().getLastModified());
    Assert.assertNotNull(response.getHeaders().getCacheControl());
    Assert.assertEquals("public, must-revalidate, proxy-revalidate, max-age=1",
            response.getHeaders().getCacheControl());
    Assert.assertNotEquals(-1l, response.getHeaders().getDate());
    Assert.assertEquals(response.getHeaders().getDate() + 1000l, response.getHeaders().getExpires());
}

From source file:org.ow2.proactive.procci.rest.MixinRestTest.java

@Test
public void getMixinTest() throws ClientException, IOException {
    when(mixinService.getMixinByTitle("titleTest"))
            .thenReturn(new MixinBuilder("schemeTest", "termTest").title("titleTest").build());
    ResponseEntity<MixinRendering> response = mixinRest.getMixin("titleTest");
    assertThat(response.getBody().getScheme()).matches("schemeTest");
    assertThat(response.getBody().getTerm()).matches("termTest");
    assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();

    when(mixinService.getMixinByTitle("titleTest2"))
            .thenThrow(new CloudAutomationClientException("titleTest2"));

    ResponseEntity<MixinRendering> responseClientError = mixinRest.getMixin("titleTest2");
    assertThat(responseClientError.getStatusCode().is4xxClientError()).isTrue();

    when(mixinService.getMixinByTitle("titleTest3")).thenThrow(ServerException.class);
    ResponseEntity<MixinRendering> responseServerError = mixinRest.getMixin("titleTest3");
    assertThat(responseServerError.getStatusCode().is5xxServerError()).isTrue();
}