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:comsat.sample.velocity.SampleWebVelocityApplicationTests.java

@Test
public void testVelocityErrorTemplate() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    HttpEntity<String> requestEntity = new HttpEntity<String>(headers);

    ResponseEntity<String> responseEntity = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class);

    assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
    assertTrue("Wrong body:\n" + responseEntity.getBody(),
            responseEntity.getBody().contains("Something went wrong: 404 Not Found"));
}

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

@Test
public void assureThatBadRequestStatusIsSetForValidationException() throws Exception {
    ResponseEntity<?> response = responseManager.toResponse(new ValidationException());
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));
    verify(logManager).logIncomingCallEnd(eq(HttpStatus.BAD_REQUEST.value()), any(String.class));
}

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

@Test
public void testHealth() {
    ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword())
            .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("\"status\":\"UP\"");
    assertThat(entity.getBody()).contains("\"example\"");
    assertThat(entity.getBody()).contains("\"counter\":42");
}

From source file:com.nebhale.cyclinglibrary.web.PointControllerTest.java

@Test
public void readImage() {
    List<Point> points = Arrays.asList(new Point(Double.valueOf(0), Double.valueOf(1), Double.valueOf(2)));
    Item item = new Item(Long.valueOf(0), Long.valueOf(1), Long.valueOf(2), "test-name", "test-short-name",
            points);//w  ww . ja  v  a2s  .co  m
    when(this.itemRepository.read(Long.valueOf(2))).thenReturn(item);
    when(this.polylineEncoder.encodeSingle(1850, points)).thenReturn("encoded-polyline");

    ResponseEntity<Void> result = this.controller.read(Long.valueOf(2), "test-map-type", 100, 200,
            "test-user-ip");

    assertEquals(HttpStatus.SEE_OTHER, result.getStatusCode());
    assertEquals(URI.create(
            "http://maps.googleapis.com/maps/api/staticmap?key=test-google-api-key&sensor=false&userIp=test-user-ip&size=100x200&maptype=test-map-type&scale=2&path=color:0xff0000ff%7Cweight:2%7Cencoded-polyline"),
            result.getHeaders().getLocation());
}

From source file:io.jmnarloch.spring.cloud.ribbon.RibbonDiscoveryFilterTest.java

@Test
public void shouldRouteRequestWithContextAttributes() {

    // given/*from  w ww .j av a 2 s  .  c o  m*/
    RibbonFilterContextHolder.getCurrentContext().add("version", "1.0");

    // when
    ResponseEntity<String> response = restOperations.getForEntity("http://local/message", String.class);

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

From source file:io.jmnarloch.spring.cloud.ribbon.RibbonDiscoveryFilterTest.java

@Test
public void shouldRouteRequestWithMultipleContextAttributes() {

    // given//from  ww w .j  ava  2s  . c om
    RibbonFilterContextHolder.getCurrentContext().add("version", "1.0").add("variant", "A");

    // when
    ResponseEntity<String> response = restOperations.getForEntity("http://local/message", String.class);

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

From source file:org.trustedanalytics.user.orgs.SpacesIT.java

@Test
public void getAllSpaces_shouldAskCloudfoundryForAllSpaces() {

    final String EXPECTED_SPACES = SpacesTestsResources.getSpacesExpectedToBeReturnedBySc();

    when(ccClient.getSpaces())//w w  w. j a v  a  2 s.  c  o m
            .thenReturn(Observable.from(SpacesTestsResources.getSpacesReturnedByCf().getSpaces()));

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ResponseEntity<String> response = RestOperationsHelpers.getForEntityWithToken(testRestTemplate, TOKEN,
            BASE_URL + SpacesController.GET_ALL_SPACES_URL);

    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
    assertThat(response.getBody(), equalTo(EXPECTED_SPACES));

}

From source file:org.zaizi.AuthServerApplicationTests.java

@Test
public void authorizationRedirects() {
    ResponseEntity<String> response = template
            .getForEntity("http://localhost:" + port + contextPath + "/oauth/authorize", String.class);
    assertEquals(HttpStatus.FOUND, response.getStatusCode());
    String location = response.getHeaders().getFirst("Location");
    assertTrue("Wrong header: " + location,
            location.startsWith("http://localhost:" + port + contextPath + "/login"));
}

From source file:JCurlTest.java

protected void executeTest(String engine) throws Exception {

    stubFor(WireMock.get(WireMock.urlPathMatching("/some/url"))
            .withHeader("accept", WireMock.equalTo("application/xml")).willReturn(aResponse().withStatus(200)
                    .withBody("" + "<payload>" + "    <value>Body Text</value>" + "</payload>")));

    ResponseEntity<String> response = new JCurl().execute("--engine", engine, "-H", "accept: application/xml",
            "--verbose", "--count", "3", "http://localhost:" + wireMockRule.port() + "/some/url");

    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}

From source file:io.jmnarloch.spring.boot.rxjava.async.SingleDeferredResultTest.java

@Test
public void shouldRetrieveSingleValue() {

    // when/*from  w w w  .  j a va2s. c  o m*/
    ResponseEntity<String> response = restTemplate.getForEntity(path("/single"), String.class);

    // then
    assertNotNull(response);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals("single value", response.getBody());
}