List of usage examples for org.apache.commons.httpclient HttpStatus SC_MOVED_TEMPORARILY
int SC_MOVED_TEMPORARILY
To view the source code for org.apache.commons.httpclient HttpStatus SC_MOVED_TEMPORARILY.
Click Source Link
From source file:ru.org.linux.user.AddPhotoWebTest.java
@Test /**//w ww .j a v a 2 s.co m * ? */ public void testValidImage() throws IOException { String auth = WebHelper.doLogin(resource, "JB", "passwd"); ClientResponse cr = WebHelper.addPhoto(resource, "src/main/webapp/tango/img/android.png", auth); assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, cr.getStatus()); final String redirect = cr.getLocation().toString(); final String url = "http://127.0.0.1:8080/people/JB/profile"; final String val = "?nocache="; assertEquals(url, redirect.substring(0, url.length())); assertEquals(val, redirect.substring(url.length(), url.length() + val.length())); assertTrue(" nocache ", redirect.length() > url.length() + val.length()); }
From source file:ru.org.linux.user.EditRegisterWebTest.java
/** * . ? //from w w w. j ava2s . c o m * redirect * @throws IOException */ @Test public void testSimple() throws IOException { String auth = WebHelper.doLogin(resource, "JB", JB_PASS); ClientResponse cr = resource.path("people/JB/edit") .cookie(new Cookie(WebHelper.AUTH_COOKIE, auth, "/", "127.0.0.1", 1)).get(ClientResponse.class); assertEquals(HttpStatus.SC_OK, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); assertEquals("/people/JB/edit", doc.getElementById("editRegForm").attr("action")); String name = doc.getElementById("name").val(); String url = doc.getElementById("url").val(); String email = doc.getElementById("email").val(); String town = doc.getElementById("town").val(); String info = doc.getElementById("info").val(); assertEquals(JB_NAME, name); assertEquals(JB_URL, url); assertEquals(JB_EMAIL, email); assertEquals(JB_TOWN, town); assertEquals(JB_INFO, info); MultivaluedMap<String, String> formData = new MultivaluedMapImpl(); formData.add("name", name); formData.add("url", url); formData.add("email", email); formData.add("town", town); formData.add("info", info); formData.add("csrf", "csrf"); formData.add("oldpass", JB_PASS); ClientResponse cr2 = resource.path("people/maxcom/edit") .cookie(new Cookie(WebHelper.AUTH_COOKIE, auth, "/", "127.0.0.1", 1)) .cookie(new Cookie(CSRFProtectionService.CSRF_COOKIE, "csrf")).post(ClientResponse.class, formData); assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, cr2.getStatus()); assertEquals("http://127.0.0.1:8080/people/JB/profile", cr2.getLocation().toString()); }
From source file:ru.org.linux.user.EditRegisterWebTest.java
@Test public void testChangePassword() throws IOException { String auth = WebHelper.doLogin(resource, "maxcom", MAXCOM_PASS); ClientResponse cr = resource.path("people/maxcom/edit") .cookie(new Cookie(WebHelper.AUTH_COOKIE, auth, "/", "127.0.0.1", 1)).get(ClientResponse.class); assertEquals(HttpStatus.SC_OK, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); String name = doc.getElementById("name").val(); String url = doc.getElementById("url").val(); String email = doc.getElementById("email").val(); String town = doc.getElementById("town").val(); String info = doc.getElementById("info").val(); assertEquals(MAXCOM_NAME, name);/*from www . ja v a 2 s. com*/ assertEquals(MAXCOM_URL, url); assertEquals(MAXCOM_EMAIL, email); assertEquals(MAXCOM_TOWN, town); assertEquals(MAXCOM_INFO, info); MultivaluedMap<String, String> formData = new MultivaluedMapImpl(); formData.add("name", name); formData.add("url", url); formData.add("email", email); formData.add("town", town); formData.add("info", info); formData.add("csrf", "csrf"); formData.add("oldpass", "passwd"); formData.add("password", "passwd2"); formData.add("password2", "passwd2"); ClientResponse cr2 = resource.path("people/maxcom/edit") .cookie(new Cookie(WebHelper.AUTH_COOKIE, auth, "/", "127.0.0.1", 1)) .cookie(new Cookie(CSRFProtectionService.CSRF_COOKIE, "csrf")).post(ClientResponse.class, formData); assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, cr2.getStatus()); String newAuth = WebHelper.getAuthCookie(cr2); assertNotNull(newAuth); ClientResponse cr3 = resource.uri(cr2.getLocation()) .cookie(new Cookie(WebHelper.AUTH_COOKIE, newAuth, "/", "127.0.0.1", 1)).get(ClientResponse.class); assertEquals(HttpStatus.SC_OK, cr3.getStatus()); MultivaluedMap<String, String> formData2 = new MultivaluedMapImpl(); formData2.add("name", name); formData2.add("url", url); formData2.add("email", email); formData2.add("town", town); formData2.add("info", info); formData2.add("csrf", "csrf"); formData2.add("oldpass", "passwd2"); formData2.add("password", "passwd"); formData2.add("password2", "passwd"); ClientResponse cr4 = resource.path("people/maxcom/edit") .cookie(new Cookie(WebHelper.AUTH_COOKIE, newAuth, "/", "127.0.0.1", 1)) .cookie(new Cookie(CSRFProtectionService.CSRF_COOKIE, "csrf")) .post(ClientResponse.class, formData2); assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, cr4.getStatus()); String newAuth2 = WebHelper.getAuthCookie(cr4); ClientResponse cr5 = resource.uri(cr4.getLocation()) .cookie(new Cookie(WebHelper.AUTH_COOKIE, newAuth2, "/", "127.0.0.1", 1)).get(ClientResponse.class); assertEquals(HttpStatus.SC_OK, cr5.getStatus()); }