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.cloudfoundry.identity.uaa.integration.PasswordCheckEndpointIntegrationTests.java

@Test
public void passwordPostWithUserDataSucceeds() throws Exception {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("password", "joe@joesplace.blah");
    formData.add("userData", "joe,joe@joesplace.blah,joesdogsname");
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.postForMap("/password/score", formData, headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());

    assertTrue(response.getBody().containsKey("score"));
    assertTrue(response.getBody().containsKey("requiredScore"));
    assertEquals(0, response.getBody().get("score"));
}

From source file:br.com.bancooriginal.notificacao.servlet.SampleServletApplicationTests.java

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

From source file:comsat.sample.actuator.ui.SampleActuatorUiApplicationPortTests.java

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

From source file:org.sventon.web.ctrl.ConfigurationReloadControllerTest.java

@Test
public void reloadConfigFileWhenExceptionOccurs() throws Exception {

    //noinspection ThrowableInstanceNeverThrown
    doThrow(new CacheException("exception")).when(application).reinit();
    ResponseEntity<String> response = controller.reloadConfigAndReinitializeApplication();
    assertThat(response.getBody(), equalTo("Internal error."));
    assertThat(response.getStatusCode(), equalTo(INTERNAL_SERVER_ERROR));
    assertContentType(response);/*from  w w w. j  a  v a 2s  .  c o  m*/
}

From source file:sample.RestTests.java

@Test
public void logout() {
    String auth = getAuth("user", "password");
    HttpHeaders headers = getHttpHeaders();
    headers.set(AUTHORIZATION, BASIC + auth);
    ResponseEntity<User> entity = getForUser(this.baseUrl + "/", headers, User.class);

    String token = entity.getHeaders().getFirst(X_AUTH_TOKEN);

    HttpHeaders logoutHeader = getHttpHeaders();
    logoutHeader.set(X_AUTH_TOKEN, token);
    ResponseEntity<User> logoutResponse = getForUser(this.baseUrl + "/logout", logoutHeader, User.class);
    assertThat(logoutResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}

From source file:sample.tomcat.jndi.SampleTomcatJndiApplicationTests.java

@Test
public void testFactoryBean() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/factoryBean", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertThat(entity.getBody(), containsString(BasicDataSource.class.getName()));
}

From source file:sample.undertow.SampleUndertowApplicationTests.java

private void assertOkResponse(String path, String body) {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + path,
            String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).isEqualTo(body);
}

From source file:org.zaizi.SensefySearchUiApplicationTests.java

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

From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java

private String post(String json, String url) {
    HttpEntity<String> requestEntity = new HttpEntity<>(json, headers);
    ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, requestEntity, String.class);
    this.setStatus(responseEntity.getStatusCode());
    return responseEntity.getBody();
}

From source file:org.zaizi.SensefySearchUiApplicationTests.java

@Test
public void resourceEndpointProtected() {
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/resource",
            String.class);
    assertEquals(HttpStatus.FOUND, response.getStatusCode());
}