Search in sources :

Example 86 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 87 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 88 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 89 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 90 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)121 WebRequest (com.meterware.httpunit.WebRequest)108 Test (org.junit.Test)93 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)91 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)56 WebConversation (com.meterware.httpunit.WebConversation)44 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)42 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 Document (org.w3c.dom.Document)12 HttpSession (javax.servlet.http.HttpSession)9 WebLink (com.meterware.httpunit.WebLink)8 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5