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.NativeApplicationIntegrationTests.java

/**
 * tests that a client secret is required.
 *//*from w ww  .j a v a 2 s.c  o m*/
@Test
public void testSecretRequired() throws Exception {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "password");
    formData.add("username", resource.getUsername());
    formData.add("password", resource.getPassword());
    formData.add("scope", "cloud_controller.read");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + new String(Base64.encode("no-such-client:".getBytes("UTF-8"))));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    ResponseEntity<String> response = serverRunning.postForString("/oauth/token", formData, headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}

From source file:com.eg.hello.HelloWorldConfigurationTests.java

@Test
public void testInfo() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.mgt + "/info",
            Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}

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

/**
 * tests a happy-day flow of the <code>/login</code> endpoint
 *//*from   www .  ja va2  s . c  om*/
@Test
public void testHappyDayHtml() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    HttpStatus status = HttpStatus.FOUND;
    String location = "/login";
    ResponseEntity<Void> response = null;
    while (status == HttpStatus.FOUND) {
        response = serverRunning.getForResponse(location, headers);
        status = response.getStatusCode();
        if (status == HttpStatus.FOUND) {
            location = response.getHeaders().getLocation().toString();
            System.err.println("Redirected to " + location);
        }
    }

    ResponseEntity<String> finalResponse = serverRunning.getForString(location, headers);
    String body = finalResponse.getBody().toString();
    // System.err.println(body);
    assertNotNull(body);
    assertTrue("Wrong body: " + body, body.contains("<form id="));

}

From source file:io.jmnarloch.spring.cloud.feign.OkHttpClientTest.java

@Test
public void okHttpFeignRequest() {

    // given//from   ww  w  . ja  v  a 2  s  . c  o  m
    final List<Invoice> invoices = Invoices.createInvoiceList(50);

    // when
    final ResponseEntity<List<Invoice>> response = invoiceClient.saveInvoices(invoices);

    // then
    assertNotNull(response);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertNotNull(response.getBody());
    assertEquals(invoices.size(), response.getBody().size());

}

From source file:com.carlomicieli.jtrains.infrastructure.web.ResponsesTests.java

@Test
public void shouldCreateResponsesForErrors() {
    ResponseEntity<VndErrors> error = Responses.error(new RuntimeException("Error message"),
            HttpStatus.INTERNAL_SERVER_ERROR, "details");
    assertThat(error).isNotNull();//from  w  w w  .j  av  a 2s  . com
    assertThat(error.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(error.getBody()).isEqualTo(new VndErrors("details", "Error message"));
}

From source file:de.zib.gndms.gndmc.dspace.Test.DSpaceClientTest.java

@Test(groups = { "dspaceServiceTest" })
public void testListSubspaceSpecifiers() {
    final ResponseEntity<List<Specifier<Void>>> listResponseEntity = dSpaceClient
            .listSubspaceSpecifiers(admindn);

    Assert.assertNotNull(listResponseEntity);
    Assert.assertEquals(listResponseEntity.getStatusCode(), HttpStatus.OK);
}

From source file:com.alcatel.hello.actuator.ui.SampleActuatorUIApplicationTests.java

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

From source file:com.github.jmnarloch.spring.cloud.feign.Demo.java

@Test
public void compressedResponse() {

    // given// w  w  w.  ja  v  a 2  s  .co  m
    final List<Invoice> invoices = Invoices.createInvoiceList(50);

    // when
    final ResponseEntity<List<Invoice>> response = invoiceClient.saveInvoices(invoices);

    // then
    assertNotNull(response);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertNotNull(response.getBody());
    assertEquals(invoices.size(), response.getBody().size());

}

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

@Test
public void register() {
    ResponseEntity<Application> response = controller.register(new Application("http://localhost", "test"));
    assertEquals(HttpStatus.CREATED, response.getStatusCode());
    assertEquals("http://localhost", response.getBody().getUrl());
    assertEquals("test", response.getBody().getName());
}

From source file:de.codecentric.boot.admin.web.CorsFilterOnSamePortsTest.java

@Test
@SuppressWarnings("rawtypes")
public void testCORS_GET_info_endpoint() {
    // DO serve CORS-Headers on management-endpoints
    ResponseEntity<Map> info = new TestRestTemplate().getForEntity("http://localhost:" + serverPort + "/info",
            Map.class);
    assertEquals(HttpStatus.OK, info.getStatusCode());
    assertEquals(Arrays.asList("*"), info.getHeaders().get("Access-Control-Allow-Origin"));
    assertEquals(Arrays.asList("Origin, X-Requested-With, Content-Type, Accept"),
            info.getHeaders().get("Access-Control-Allow-Headers"));
}