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:it.reply.orchestrator.service.CmdbServiceImpl.java

@Override
public Image getImageById(String imageId) {
    ResponseEntity<Image> response = restTemplate.getForEntity(url.concat("image/id").concat(imageId),
            Image.class);
    if (response.getStatusCode().is2xxSuccessful()) {
        return response.getBody();
    }// www . j a  v a2 s  . c  om
    throw new DeploymentException("Unable to find image <" + imageId + "> in the CMDB."
            + response.getStatusCode().toString() + " " + response.getStatusCode().getReasonPhrase());
}

From source file:org.cloudfoundry.identity.uaa.integration.TestAccountSetup.java

private void createUserAccount(RestOperations client) {
    ScimUser user = testAccounts.getUser();
    ResponseEntity<ScimUser> response = client.postForEntity(serverRunning.getUserUri(), user, ScimUser.class);
    Assert.state(response.getStatusCode() == HttpStatus.CREATED);
}

From source file:com.crazyacking.learn.spring.actuator.ManagementPortAndPathSampleActuatorApplicationTests.java

@Test
public void testManagementErrorPage() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
            .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertThat(body.get("status")).isEqualTo(999);
}

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

@Test
public void testLoginPage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login",
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong content:\n" + entity.getBody(), entity.getBody().contains("_csrf"));
}

From source file:org.cloudfoundry.identity.api.web.AppsIntegrationTests.java

/**
 * tests a happy-day flow of the native application profile.
 *//*from   w  w w  .j a  v a2s . c o m*/
@Test
public void testHappyDay() throws Exception {

    RestOperations restTemplate = serverRunning.createRestTemplate();
    ResponseEntity<String> response = restTemplate.getForEntity(serverRunning.getUrl("/api/apps"),
            String.class);
    // first make sure the resource is actually protected.
    assertNotSame(HttpStatus.OK, response.getStatusCode());
    HttpHeaders approvalHeaders = new HttpHeaders();
    OAuth2AccessToken accessToken = context.getAccessToken();
    approvalHeaders.set("Authorization", "bearer " + accessToken.getValue());
    Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000);
    Date expiresAt = new Date(System.currentTimeMillis() + 60000);
    ResponseEntity<Approval[]> approvals = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/uaa/approvals"), HttpMethod.PUT,
            new HttpEntity<Approval[]>((new Approval[] {
                    new Approval(testAccounts.getUserName(), "app", "cloud_controller.read", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "openid", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "password.write", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo) }),
                    approvalHeaders),
            Approval[].class);
    assertEquals(HttpStatus.OK, approvals.getStatusCode());

    ResponseEntity<String> result = serverRunning.getForString("/api/apps");
    assertEquals(HttpStatus.OK, result.getStatusCode());
    String body = result.getBody();
    assertTrue("Wrong response: " + body, body.contains("dsyerapi.cloudfoundry.com"));

}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.RegisterServiceHandlerTest.java

@Test
/**//from w ww  .j a  v a  2 s . c  o m
 * Test what happens when a null is sent to register a service
 */
public void testHandleJobRequestNull() {
    PiazzaJobType jobRequest = null;
    ResponseEntity<String> result = rsHandler.handle(jobRequest);
    assertEquals("The response to a null JobRequest update should be null", result.getStatusCode(),
            HttpStatus.BAD_REQUEST);
}

From source file:org.mimacom.sample.integration.patterns.user.service.integration.SimpleSearchServiceIntegration.java

public void indexUser(User user) {
    LOG.info("going to send request to index user '{}' '{}'", user.getFirstName(), user.getLastName());

    ResponseEntity<String> response = this.restTemplate.postForEntity(this.searchServiceUrl + "/index", user,
            String.class);
    LOG.info("user '{}' '{}' was indexed and response status code was '{}'", user.getFirstName(),
            user.getLastName(), response.getStatusCode());
}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.RegisterServiceHandlerTest.java

/**
 * Test what happens when there is an invalid registration
 *//* w  w w.  ja  v  a  2s. c om*/
@Test
public void testUnsuccessfulRegistration() {
    RegisterServiceJob job = new RegisterServiceJob();

    job.data = service;

    final RegisterServiceHandler rsMock = Mockito.spy(rsHandler);

    Mockito.doReturn("").when(rsMock).handle(service);

    ResponseEntity<String> result = rsMock.handle(job);

    assertEquals("The status code should be HttpStatus.UNPROCESSABLE_ENTITY.", result.getStatusCode(),
            HttpStatus.UNPROCESSABLE_ENTITY);

}

From source file:com.crazyacking.learn.spring.actuator.SampleActuatorApplicationTests.java

@Test
public void testMetricsIsSecure() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    entity = this.restTemplate.getForEntity("/metrics/", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    entity = this.restTemplate.getForEntity("/metrics/foo", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    entity = this.restTemplate.getForEntity("/metrics.json", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}