Example usage for org.springframework.http HttpStatus FOUND

List of usage examples for org.springframework.http HttpStatus FOUND

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus FOUND.

Prototype

HttpStatus FOUND

To view the source code for org.springframework.http HttpStatus FOUND.

Click Source Link

Document

302 Found .

Usage

From source file:org.zaizi.SensefySearchUiApplicationTests.java

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

From source file:org.cloudfoundry.identity.app.integration.AuthenticationIntegrationTests.java

@Test
public void formLoginSucceeds() throws Exception {

    ResponseEntity<Void> result;
    String location;/* www . ja va  2  s .  c  o  m*/
    String cookie;

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

    // *** GET /app/id
    result = serverRunning.getForResponse("/id", appHeaders);
    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    location = result.getHeaders().getLocation().toString();

    cookie = result.getHeaders().getFirst("Set-Cookie");
    assertNotNull("Expected cookie in " + result.getHeaders(), cookie);
    appHeaders.set("Cookie", cookie);

    assertTrue("Wrong location: " + location, location.contains("/oauth/authorize"));
    // *** GET /uaa/oauth/authorize
    result = serverRunning.getForResponse(location, uaaHeaders);
    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    location = result.getHeaders().getLocation().toString();

    cookie = result.getHeaders().getFirst("Set-Cookie");
    assertNotNull("Expected cookie in " + result.getHeaders(), cookie);
    uaaHeaders.set("Cookie", cookie);

    assertTrue("Wrong location: " + location, location.contains("/login"));
    location = serverRunning.getAuthServerUrl("/login.do");

    MultiValueMap<String, String> formData;
    formData = new LinkedMultiValueMap<String, String>();
    formData.add("username", testAccounts.getUserName());
    formData.add("password", testAccounts.getPassword());

    // *** POST /uaa/login.do
    result = serverRunning.postForResponse(location, uaaHeaders, formData);

    cookie = result.getHeaders().getFirst("Set-Cookie");
    assertNotNull("Expected cookie in " + result.getHeaders(), cookie);
    uaaHeaders.set("Cookie", cookie);

    assertEquals(HttpStatus.FOUND, result.getStatusCode());
    location = result.getHeaders().getLocation().toString();

    assertTrue("Wrong location: " + location, location.contains("/oauth/authorize"));
    // *** GET /uaa/oauth/authorize
    result = serverRunning.getForResponse(location, uaaHeaders);

    // If there is no token in place already for this client we get the approval page.
    // TODO: revoke the token so we always get the approval page
    if (result.getStatusCode() == HttpStatus.OK) {
        location = serverRunning.getAuthServerUrl("/oauth/authorize");

        formData = new LinkedMultiValueMap<String, String>();
        formData.add("user_oauth_approval", "true");

        // *** POST /uaa/oauth/authorize
        result = serverRunning.postForResponse(location, uaaHeaders, formData);
    }

    location = result.getHeaders().getLocation().toString();

    // SUCCESS
    assertTrue("Wrong location: " + location, location.contains("/id"));

    // *** GET /app/id
    result = serverRunning.getForResponse(location, appHeaders);
    // System.err.println(result.getHeaders());
    assertEquals(HttpStatus.OK, result.getStatusCode());
}

From source file:com.work.petclinic.SampleWebUiApplicationTests.java

@After
public void cleanSession() throws Exception {
    ResponseEntity<String> page = sendRequest("http://localhost:" + this.port, HttpMethod.GET);

    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("_csrf", csrfValue);
    httpHeaders.set("X-CSRF-TOKEN", csrfValue);

    page = sendRequest("http://localhost:" + this.port + "/logout", HttpMethod.GET, form);

    assertEquals(HttpStatus.FOUND, page.getStatusCode());

    if (page.getStatusCode() == HttpStatus.FOUND) {
        page = sendRequest(page.getHeaders().getLocation(), HttpMethod.GET);
    }//from w w  w .ja  v  a  2  s.  c  om

    httpHeaders = null;
    csrfValue = null;
}

From source file:com.ginema.ApplicationTests.java

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

From source file:com.interop.webapp.WebAppTests.java

@Test
public void testHome() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port,
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    assertTrue("Wrong location:\n" + entity.getHeaders(),
            entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
}

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());
}

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

@Test
public void testDefaultScopes() {
    params.set("credentials", String.format("{\"username\":\"%s\",\"password\":\"%s\"}",
            testAccounts.getUserName(), testAccounts.getPassword()));
    ResponseEntity<Void> response = serverRunning.postForResponse(serverRunning.getAuthorizationUri(), headers,
            params);//from w w  w .ja v  a  2s.c  o m
    assertEquals(HttpStatus.FOUND, response.getStatusCode());
    String location = response.getHeaders().getLocation().toString();
    assertTrue("Not authenticated (no access token): " + location, location.contains("access_token"));
}

From source file:com.work.petclinic.MessageControllerWebTests.java

@Test
public void testCreate() throws Exception {
    ResponseEntity<String> page = executeLogin("user", "user");
    page = getPage("http://localhost:" + this.port + "/messages?form");

    String body = page.getBody();
    assertNotNull("Body was null", body);

    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("summary", "summary");
    form.set("messageText", "messageText");
    form.set("_csrf", csrfValue);

    String formAction = getFormAction(page);

    page = postPage(formAction, form);/*from   w w  w.j a  va 2s.  co m*/
    body = page.getBody();

    assertTrue("Error creating message.", body == null || body.contains("alert alert-danger"));
    assertTrue("Status was not FOUND (redirect), means message was not created properly.",
            page.getStatusCode() == HttpStatus.FOUND);

    page = getPage(page.getHeaders().getLocation());

    body = page.getBody();
    assertTrue("Error creating message.", body.contains("Successfully created a new message"));
}