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:fr.patouche.soat.google.GoogleApplicationTests.java

@Test
public void loginRedirectsToGithub() throws Exception {
    TestRestTemplate restTemplate = new TestRestTemplate();
    ResponseEntity<Void> entity = restTemplate.getForEntity("http://localhost:" + this.port + "/login",
            Void.class);
    assertThat(entity.getStatusCode(), is(HttpStatus.FOUND));
    assertThat(entity.getHeaders().getLocation().toString(), startsWith("https://github.com/login/oauth"));
}

From source file:org.shaigor.rest.retro.service.security.IntegrationTest.java

/**
 * Logic to test unauthorized access to protected resource
 * @param uri/* w  w w  . j a  v  a2s .co m*/
 */
protected void testInvalidTokenErrorMessge(String uri) {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Bearer FOO");
    ResponseEntity<String> response = helper.getForResponse(uri, headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
    String authenticate = response.getHeaders().getFirst("WWW-Authenticate");
    assertTrue("Wrong header: " + authenticate, authenticate.contains("error=\"invalid_token\""));
}

From source file:runtheshow.resource.BootTests.java

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

From source file:com.walmart.gatling.AbstractRestIntTest.java

protected <T> T getForObject(String url, Class<T> responseType, HttpStatus expectedStatus) {
    ResponseEntity<T> entity = template.getForEntity(url, responseType);
    assertEquals(expectedStatus, entity.getStatusCode());
    return entity.getBody();
}

From source file:de.alexkrieg.IntegrationTests.java

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

From source file:org.shaigor.rest.retro.service.security.IntegrationTest.java

/**
 * Access resource for given URI and user
 * @param uri resource URI to access/*from   w w  w . j  a  v  a2  s. c o m*/
 * @param pwd the password of the user
 * @throws IOException 
 */
protected void testResourceAccess(URIInfo testUri) throws IOException {
    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<String> response = helper.getForResponse(testUri.getUri(), headers);

    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals("Rigth method should be called.", testUri.getResponse(), response.getBody());
}

From source file:com.clearprecision.microservices.reference.jetty.BirthdayApplicationTests.java

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

From source file:com.springer.semantic.classifier.jetty.ClassifierApplicationTests.java

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

From source file:de.hamburg.mse.ui.SampleWebUiApplicationTests.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:com.crazyacking.learn.spring.actuator.ServletPathSampleActuatorApplicationTests.java

@Test
public void testHomeIsSecure() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertThat(body.get("error")).isEqualTo("Unauthorized");
    assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
}