Search in sources :

Example 76 with WebResponse

use of com.meterware.httpunit.WebResponse in project v7files by thiloplanz.

the class MiltonServletTest method testCOPYFolder.

public void testCOPYFolder() throws IOException, SAXException {
    ServletUnitClient sc = sr.newClient();
    sc.setAuthentication("V7Files", "admin", "admin");
    {
        WebRequest request = new MkColWebRequest("http://test/myServlet/1");
        WebResponse resp = sc.getResponse(request);
        assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
    }
    {
        WebRequest request = new PutMethodWebRequest("http://test/myServlet/1/test.txt", new ByteArrayInputStream("testPUT".getBytes()), "text/plain");
        WebResponse resp = sc.getResponse(request);
        assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
    }
    {
        WebRequest request = new CopyWebRequest("http://test/myServlet/1", "/myServlet/2");
        WebResponse resp = sc.getResponse(request);
        assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
    }
    assertExists(sc, "http://test/myServlet/2/test.txt");
}
Also used : PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ServletUnitClient(com.meterware.servletunit.ServletUnitClient)

Example 77 with WebResponse

use of com.meterware.httpunit.WebResponse in project v7files by thiloplanz.

the class MiltonServletTest method testCOPYFile.

public void testCOPYFile() throws IOException, SAXException {
    ServletUnitClient sc = sr.newClient();
    sc.setAuthentication("V7Files", "admin", "admin");
    prepareMockData("test.v7files.files", new BasicBSONObject("_id", new ObjectId()).append("filename", "a.txt").append("parent", "webdav").append("in", "abcd".getBytes()));
    {
        WebRequest request = new CopyWebRequest("http://test/myServlet/a.txt", "/myServlet/b.txt");
        WebResponse resp = sc.getResponse(request);
        assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
    }
    assertGET(sc, "http://test/myServlet/a.txt", "abcd");
    assertGET(sc, "http://test/myServlet/b.txt", "abcd");
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) ObjectId(org.bson.types.ObjectId) ServletUnitClient(com.meterware.servletunit.ServletUnitClient)

Example 78 with WebResponse

use of com.meterware.httpunit.WebResponse in project v7files by thiloplanz.

the class MiltonServletTest method assertGET.

private void assertGET(ServletUnitClient sc, String url, String contents) throws IOException, SAXException {
    WebRequest request = new GetMethodWebRequest(url);
    WebResponse resp = sc.getResponse(request);
    assertEquals(contents, resp.getText());
    assertEquals(HttpServletResponse.SC_OK, resp.getResponseCode());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest)

Example 79 with WebResponse

use of com.meterware.httpunit.WebResponse in project wildfly by wildfly.

the class RestoreOriginalRequestTestCase method testRedirectOriginalRequest.

@Test
@OperateOnDeployment("service-provider-1")
public void testRedirectOriginalRequest(@ArquillianResource URL serviceProvider1) throws Exception {
    WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider1) + "/savedRequest/savedRequest.html");
    WebConversation conversation = new WebConversation();
    WebResponse response = conversation.getResponse(request);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue(response.getText().contains("Back to the original requested resource."));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebConversation(com.meterware.httpunit.WebConversation) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 80 with WebResponse

use of com.meterware.httpunit.WebResponse in project wildfly by wildfly.

the class RestoreOriginalRequestTestCase method testPostOriginalRequestWithParams.

@Test
@OperateOnDeployment("service-provider-2")
public void testPostOriginalRequestWithParams(@ArquillianResource URL serviceProvider2) throws Exception {
    WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider2) + "/savedRequest/savedRequest.jsp");
    request.setParameter("SAVED_PARAM", "Param was saved.");
    WebConversation conversation = new WebConversation();
    WebResponse response = conversation.getResponse(request);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue(response.getText().contains("Param was saved."));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebConversation(com.meterware.httpunit.WebConversation) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

WebResponse (com.meterware.httpunit.WebResponse)100 WebRequest (com.meterware.httpunit.WebRequest)95 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)84 Test (org.junit.Test)76 WebConversation (com.meterware.httpunit.WebConversation)43 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)41 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)15 TextBlock (com.meterware.httpunit.TextBlock)14 URL (java.net.URL)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 HttpException (com.meterware.httpunit.HttpException)4 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)4