Search in sources :

Example 26 with PostMethodWebRequest

use of com.meterware.httpunit.PostMethodWebRequest in project cxf by apache.

the class CXFFilterTest method testPostInvokeServices.

@Test
public void testPostInvokeServices() throws Exception {
    newClient();
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=UTF-8");
    WebResponse response = newClient().getResponse(req);
    assertEquals("text/xml", response.getContentType());
    assertEquals(StandardCharsets.UTF_8.name(), response.getCharacterSet());
    Document doc = StaxUtils.read(response.getInputStream());
    assertNotNull(doc);
    addNamespace("h", "http://apache.org/hello_world_soap_http/types");
    assertValid("/s:Envelope/s:Body", doc);
    assertValid("//h:sayHiResponse", doc);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 27 with PostMethodWebRequest

use of com.meterware.httpunit.PostMethodWebRequest in project cxf by apache.

the class JsFrontEndServletTest method testPostInvokeServices.

@Test
public void testPostInvokeServices() throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=UTF-8");
    WebResponse response = newClient().getResponse(req);
    assertEquals("text/xml", response.getContentType());
    // assertEquals(StandardCharsets.UTF_8, response.getCharacterSet());
    Document doc = StaxUtils.read(response.getInputStream());
    assertNotNull(doc);
    addNamespace("h", "http://apache.org/hello_world_soap_http/types");
    assertValid("/s:Envelope/s:Body", doc);
    assertValid("//h:sayHiResponse", doc);
    assertValid("//h:responseType", doc);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 28 with PostMethodWebRequest

use of com.meterware.httpunit.PostMethodWebRequest in project cxf by apache.

the class ExternalServicesServletTest method testPostInvokeServices.

@Test
public void testPostInvokeServices() throws Exception {
    newClient();
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=UTF-8");
    WebResponse response = newClient().getResponse(req);
    assertEquals("text/xml", response.getContentType());
    assertEquals(StandardCharsets.UTF_8.name(), response.getCharacterSet());
    Document doc = StaxUtils.read(response.getInputStream());
    assertNotNull(doc);
    addNamespace("h", "http://apache.org/hello_world_soap_http/types");
    assertValid("/s:Envelope/s:Body", doc);
    assertValid("//h:sayHiResponse", doc);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 29 with PostMethodWebRequest

use of com.meterware.httpunit.PostMethodWebRequest in project teammates by TEAMMATES.

the class GaeSimulation method createWebRequest.

private HttpServletRequest createWebRequest(String uri, String... parameters) {
    WebRequest request = new PostMethodWebRequest("http://localhost" + uri);
    if (Const.SystemParams.PAGES_REQUIRING_ORIGIN_VALIDATION.contains(uri)) {
        request.setHeaderField("referer", "http://localhost");
        String sessionId = sc.getSession(true).getId();
        String token = CryptoHelper.computeSessionToken(sessionId);
        request.setParameter(Const.ParamsNames.SESSION_TOKEN, token);
    }
    Map<String, List<String>> paramMultiMap = new HashMap<>();
    for (int i = 0; i < parameters.length; i = i + 2) {
        String key = parameters[i];
        if (paramMultiMap.get(key) == null) {
            paramMultiMap.put(key, new ArrayList<String>());
        }
        paramMultiMap.get(key).add(parameters[i + 1]);
    }
    paramMultiMap.forEach((key, values) -> request.setParameter(key, values.toArray(new String[0])));
    try {
        InvocationContext ic = sc.newInvocation(request);
        return ic.getRequest();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) HashMap(java.util.HashMap) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ArrayList(java.util.ArrayList) List(java.util.List) InvocationContext(com.meterware.servletunit.InvocationContext)

Aggregations

PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)29 WebRequest (com.meterware.httpunit.WebRequest)28 Test (org.junit.Test)26 WebResponse (com.meterware.httpunit.WebResponse)25 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)23 ByteArrayInputStream (java.io.ByteArrayInputStream)21 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)8 Document (org.w3c.dom.Document)4 HttpException (com.meterware.httpunit.HttpException)2 List (java.util.List)2 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)1 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)1 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)1 InvocationContext (com.meterware.servletunit.InvocationContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)1 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)1