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.walmart.gatling.AbstractRestIntTest.java

protected HttpStatus delete(String url) {
    ResponseEntity<Void> response = template.exchange(url, HttpMethod.DELETE, null, Void.class);
    HttpStatus code = response.getStatusCode();
    if (code == HttpStatus.OK || code == HttpStatus.NO_CONTENT || code == HttpStatus.NOT_FOUND)
        return response.getStatusCode();
    else {/*from  www .j a  v  a2s . c  o  m*/
        fail("Expected the delete response to be 200 or 404, but was " + code.value() + "("
                + code.getReasonPhrase() + ").");
        return null; //for compiler
    }
}

From source file:comsat.sample.actuator.log4j2.SampleActuatorApplicationTests.java

@Test
public void testHome() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + port, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertEquals("Hello Daniel", body.get("message"));
}

From source file:de.codecentric.boot.admin.controller.RegistryControllerTest.java

@Test
public void get() {
    Application app = new Application("http://localhost", "FOO");
    app = controller.register(app).getBody();

    ResponseEntity<Application> response = controller.get(app.getId());
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals("http://localhost", response.getBody().getUrl());
    assertEquals("FOO", response.getBody().getName());
}

From source file:org.acme.sample.SpringBootFacesApplicationTests.java

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

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

@Test
public void toggleReloadSupportFalse() {
    when(application.isConfigurationReloadSupported()).thenReturn(false);
    ResponseEntity<String> response = controller.reloadConfigAndReinitializeApplication();
    assertThat(response.getBody(), equalTo("Forbidden."));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.FORBIDDEN));
    assertContentType(response);//from  w w  w .j av  a 2s .c  o m
}

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

@Test
public void testCustomContextPath() {
    ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
            .getForEntity("/admin/health", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("\"status\":\"UP\"");
    assertThat(entity.getBody()).contains("\"hello\":\"world\"");
}

From source file:comsat.sample.freemarker.SampleWebFreeMarkerApplicationTests.java

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

From source file:comsat.sample.jetty.SampleJetty8SslApplicationTests.java

@Test
public void testHome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory()).setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate.getForEntity("https://localhost:" + this.port,
            String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("Hello World", entity.getBody());
}

From source file:sample.SpringDataRestDeleteNotFoundApplicationTests.java

@Test
public void messagesCrud() {
    Message toCreate = createMessage();//from  ww w  .j a  va  2 s  .co m

    ResponseEntity<Message> created = rest.postForEntity("/messages/", toCreate, Message.class);

    assertThat(created).isNotNull();
    assertThat(created.getStatusCode()).isEqualTo(HttpStatus.CREATED);
    assertThat(created.getBody().getText()).isEqualTo(toCreate.getText());

    URI createdUri = created.getHeaders().getLocation();

    Message getForEntity = rest.getForEntity(createdUri, Message.class).getBody();
    assertThat(getForEntity.getText()).isEqualTo(toCreate.getText());

    // response is 405 when @GetMapping("/messages/{id}") is present
    rest.delete(createdUri);

    assertThat(rest.getForEntity(createdUri, Message.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

From source file:com.dolphine.customer.microservice.SampleActuatorApplicationTests.java

@Test
public void testHome() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + port, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertEquals("Hello Phil", body.get("message"));
}