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:SampleWebStaticApplicationTests.java

@Test
public void testCss() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("body");
    assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.valueOf("text/css"));
}

From source file:com.example.SampleWebFreeMarkerApplicationTests.java

@Test
public void testFreeMarkerTemplate() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/" + contextPath + "/welcome", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).contains("Hello, Andy");
}

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

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test/*from   ww  w  .j  av a 2s .  co  m*/
public void testActuatorHealthPage() throws Exception {
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + actuatorPath + "/health", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());

    Map<String, Object> body = entity.getBody();
    assertTrue("Wrong body:\n" + entity.getBody(), body.containsKey("status"));
}

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

@Test
public void testInvalidScopes() {
    params.set("credentials", String.format("{\"username\":\"%s\",\"password\":\"%s\"}",
            testAccounts.getUserName(), testAccounts.getPassword()));
    params.set("scope", "read");
    ResponseEntity<Void> response = serverRunning.postForResponse(serverRunning.getAuthorizationUri(), headers,
            params);//  w w w  .  j av a 2s  .  c  om
    assertEquals(HttpStatus.FOUND, response.getStatusCode());
    String location = response.getHeaders().getLocation().toString();
    // System.err.println(location);
    assertTrue(location.startsWith(params.getFirst("redirect_uri")));
    assertTrue(location.contains("error=invalid_scope"));
    assertFalse(location.contains("credentials="));
}

From source file:tds.assessment.web.endpoints.AssessmentControllerTest.java

@Test
public void shouldFindAssessmentByKey() {
    final String clientName = "SBAC_PT";
    final String assessmentKey = "theKey";
    Assessment assessment = new Assessment();
    assessment.setKey(assessmentKey);/* w  w w . j av a2  s .  c o m*/

    when(service.findAssessment(clientName, assessmentKey)).thenReturn(Optional.of(assessment));
    ResponseEntity<Assessment> response = controller.findAssessment(clientName, assessmentKey);
    verify(service).findAssessment(clientName, assessmentKey);

    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(response.getBody().getKey()).isEqualTo("theKey");
}

From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilderTest.java

@Test
public void testCreated() {
    ResponseEntity<Object> created = ResponseEntityBuilder.created();
    Assert.assertNotNull(created);//from  ww w.j av a 2 s .c om
    Assert.assertNull(created.getBody());
    Assert.assertEquals(created.getStatusCode(), HttpStatus.CREATED);
}

From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilderTest.java

@Test
public void testDeleted() {
    ResponseEntity<Void> deleted = ResponseEntityBuilder.noContent();
    Assert.assertNotNull(deleted);//from  w w w. ja  v  a 2s. co  m
    Assert.assertNull(deleted.getBody());
    Assert.assertEquals(deleted.getStatusCode(), HttpStatus.NO_CONTENT);
}

From source file:net.eusashead.hateoas.response.impl.PostResponseBuilderImplTest.java

@Test
public void testBuildUriTemplate() throws Exception {
    ResponseEntity<Void> response = builder.location("/url/to/{entity}", "blah").build();
    Assert.assertNotNull(response);//from w  w w . j  av  a2 s .c  om
    Assert.assertEquals(HttpStatus.CREATED, response.getStatusCode());
    Assert.assertNull(response.getBody());
    Assert.assertNotNull(response.getHeaders().getLocation());
    Assert.assertEquals(new URI("/url/to/blah"), response.getHeaders().getLocation());
    Assert.assertNull(response.getHeaders().getETag());
    Assert.assertEquals(-1l, response.getHeaders().getLastModified());
    Assert.assertNull(response.getHeaders().getCacheControl());
    Assert.assertEquals(-1l, response.getHeaders().getExpires());
    Assert.assertEquals(-1l, response.getHeaders().getDate());
}

From source file:sagan.projects.support.BadgeControllerTest.java

@Test
public void badgeShouldBeGenerated() throws Exception {

    releases.add(new ProjectRelease("1.0.RELEASE", ReleaseStatus.GENERAL_AVAILABILITY, true, "", "", "", ""));
    ResponseEntity<byte[]> response = controller.releaseBadge("spring-data-redis");

    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));
    assertThat(response.getHeaders().getETag(), is(equalTo("\"1.0.RELEASE\"")));
    assertThat(response.getHeaders().getCacheControl(), is(equalTo("max-age=3600")));

    String content = new String(response.getBody());
    assertThat(content, containsString("<svg"));
    assertThat(content, containsString("Spring Data Redis"));
    assertThat(content, containsString("1.0.RELEASE"));
}

From source file:com.cloudbees.jenkins.plugins.demo.actuator.UnsecureSampleActuatorApplicationTests.java

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