Search in sources :

Example 61 with WebRequest

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

the class CXFServletTest method invoke.

private void invoke(String encoding) throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=" + encoding);
    ServletUnitClient client = newClient();
    WebResponse response = client.getResponse(req);
    client.setExceptionsThrownOnErrorStatus(false);
    assertEquals("text/xml", response.getContentType());
    assertTrue(encoding.equalsIgnoreCase(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) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Document(org.w3c.dom.Document)

Example 62 with WebRequest

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

the class SpringAutoPublishServletTest method testGetWSDL.

@Test
public void testGetWSDL() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(true);
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/SOAPService?wsdl");
    WebResponse res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    Document doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    assertValid("//wsdl:operation[@name='greetMe']", doc);
    assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/SOAPService']", doc);
    req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/DerivedGreeterService?wsdl");
    res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    assertValid("//wsdl:operation[@name='greetMe']", doc);
    assertValid("//wsdlsoap:address" + "[@location='http://localhost/mycontext/services/DerivedGreeterService']", doc);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 63 with WebRequest

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

the class SpringServletTest method testGetWSDL.

@Test
public void testGetWSDL() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(true);
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/Greeter?wsdl");
    WebResponse res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    Document doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    assertValid("//wsdl:operation[@name='greetMe']", doc);
    assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/Greeter']", doc);
    req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/Greeter2?wsdl");
    res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    assertValid("//wsdl:operation[@name='greetMe']", doc);
    assertValid("//wsdlsoap:address[@location='http://cxf.apache.org/Greeter']", doc);
    Endpoint.publish("/services/Greeter3", new org.apache.hello_world_soap_http.GreeterImpl());
    req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/Greeter3?wsdl");
    res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    assertValid("//wsdl:operation[@name='greetMe']", doc);
    assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/Greeter3']", doc);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 64 with WebRequest

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

the class SpringServletTest method testIgnoreServiceList.

@Test
public void testIgnoreServiceList() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(true);
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/");
    try {
        client.getResponse(req);
        fail();
    } catch (HttpNotFoundException ex) {
    // expected
    }
}
Also used : HttpNotFoundException(com.meterware.httpunit.HttpNotFoundException) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Example 65 with WebRequest

use of com.meterware.httpunit.WebRequest in project camel by apache.

the class RestServletPostXmlJaxbPojoTest method testPostJaxbPojo.

@Test
public void testPostJaxbPojo() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
    String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "application/json");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertMockEndpointsSatisfied();
    UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
    assertNotNull(user);
    assertEquals(123, user.getId());
    assertEquals("Donald Duck", user.getName());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Aggregations

WebRequest (com.meterware.httpunit.WebRequest)113 WebResponse (com.meterware.httpunit.WebResponse)108 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)90 Test (org.junit.Test)87 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)52 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)45 WebConversation (com.meterware.httpunit.WebConversation)39 ByteArrayInputStream (java.io.ByteArrayInputStream)27 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)14 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)10 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5