Search in sources :

Example 51 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient 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 52 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient 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 53 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient in project cxf by apache.

the class CXFServletTest method testGetUnformatServiceList.

@Test
public void testGetUnformatServiceList() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse res = client.getResponse(CONTEXT_URL + "/services?formatted=false");
    assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter3"));
    assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter2"));
    assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Example 54 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient in project cxf by apache.

the class CXFServletTest method testGetServiceList.

@Test
public void testGetServiceList() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse res = client.getResponse(CONTEXT_URL + "/services");
    WebLink[] links = res.getLinks();
    assertEquals("Wrong number of service links", 6, links.length);
    Set<String> links2 = new HashSet<>();
    for (WebLink l : links) {
        links2.add(l.getURLString());
    }
    assertTrue(links2.contains(CONTEXT_URL + "/services/greeter?wsdl"));
    assertTrue(links2.contains(CONTEXT_URL + "/services/greeter2?wsdl"));
    assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
    assertEquals("text/html", res.getContentType());
    res = client.getResponse(CONTEXT_URL + "/services/");
    links = res.getLinks();
    links2.clear();
    for (WebLink l : links) {
        links2.add(l.getURLString());
    }
    assertEquals("Wrong number of service links", 6, links.length);
    assertTrue(links2.contains(CONTEXT_URL + "/services/greeter?wsdl"));
    assertTrue(links2.contains(CONTEXT_URL + "/services/greeter2?wsdl"));
    assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
    assertEquals("text/html", res.getContentType());
    // Ensure that the Bus is available for people doing an Endpoint.publish() or similar.
    assertNotNull(BusFactory.getDefaultBus(false));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) WebLink(com.meterware.httpunit.WebLink) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 55 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient in project cxf by apache.

the class CXFServletTest method testInvalidServiceUrl.

@Test
public void testInvalidServiceUrl() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse res = client.getResponse(CONTEXT_URL + "/services/NoSuchService");
    assertEquals(404, res.getResponseCode());
    assertEquals("text/html", res.getContentType());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Aggregations

ServletUnitClient (com.meterware.servletunit.ServletUnitClient)58 WebResponse (com.meterware.httpunit.WebResponse)56 WebRequest (com.meterware.httpunit.WebRequest)52 Test (org.junit.Test)47 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)40 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)34 ByteArrayInputStream (java.io.ByteArrayInputStream)27 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)12 Document (org.w3c.dom.Document)7 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)6 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 HttpException (com.meterware.httpunit.HttpException)3 WebLink (com.meterware.httpunit.WebLink)3 HashSet (java.util.HashSet)3 BasicBSONObject (org.bson.BasicBSONObject)3 ObjectId (org.bson.types.ObjectId)2 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)2 ContentSHA (v7db.files.spi.ContentSHA)2 InputStream (java.io.InputStream)1