Search in sources :

Example 56 with ServletUnitClient

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

the class CXFServletTest method testServiceListWithLoopAddress.

@Test
public void testServiceListWithLoopAddress() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse res = client.getResponse(CONTEXT_URL + "/services");
    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"));
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl");
    res = client.getResponse(req);
    req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter2?wsdl");
    res = client.getResponse(req);
    req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?wsdl");
    res = client.getResponse(req);
    String loopAddr = "http://127.0.0.1/mycontext";
    res = client.getResponse(loopAddr + "/services");
    assertFalse(res.getText().contains("http://127.0.0.1/mycontext/serviceshttp://localhost/mycontext/services/greeter"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Example 57 with ServletUnitClient

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

the class ExternalServicesServletTest method testGetServiceList.

@Test
public void testGetServiceList() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    // test the '/' context get service list
    WebResponse res = client.getResponse(CONTEXT_URL + "/");
    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(FORCED_BASE_ADDRESS + "/greeter?wsdl"));
    assertTrue(links2.contains(FORCED_BASE_ADDRESS + "/greeter2?wsdl"));
    assertEquals("text/html", res.getContentType());
// HTTPUnit do not support require url with ""
/*
        res = client.getResponse(CONTEXT_URL);
        links = res.getLinks();
        assertEquals("There should get two links for the services", 1, links.length);
        assertEquals(CONTEXT_URL + "/greeter?wsdl", links[0].getURLString());
        assertEquals(CONTEXT_URL + "/greeter2?wsdl", links[1].getURLString());
        assertEquals("text/html", res.getContentType());*/
}
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 58 with ServletUnitClient

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

the class JaxRsServletTest method testInvokingBookService.

private void testInvokingBookService(String serviceAddress) throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress);
    WebResponse response = client.getResponse(req);
    InputStream in = response.getInputStream();
    InputStream expected = JaxRsServletTest.class.getResourceAsStream("resources/expected_get_book123.txt");
    assertEquals(" Can't get the expected result ", getStringFromInputStream(expected), getStringFromInputStream(in));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) InputStream(java.io.InputStream) ServletUnitClient(com.meterware.servletunit.ServletUnitClient)

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