Search in sources :

Example 61 with WebResponse

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

the class CXFServletTest method testGetWSDLWithXMLBinding.

@Test
public void testGetWSDLWithXMLBinding() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(true);
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter2?wsdl");
    WebResponse res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    Document doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
    assertValid("//wsdl:operation[@name='greetMe']", doc);
    NodeList addresses = assertValid("//http:address/@location", doc);
    boolean found = true;
    for (int i = 0; i < addresses.getLength(); i++) {
        String address = addresses.item(i).getLocalName();
        if (address.startsWith("http://localhost") && address.endsWith("/services/greeter2")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) NodeList(org.w3c.dom.NodeList) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Document(org.w3c.dom.Document) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Example 62 with WebResponse

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

the class CXFServletTest 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);
}
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) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 63 with WebResponse

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

the class CXFServletTest method testGetWSDLWithMultiplePublishedEndpointUrl.

@Test
public void testGetWSDLWithMultiplePublishedEndpointUrl() throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(true);
    WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter5?wsdl");
    WebResponse res = client.getResponse(req);
    assertEquals(200, res.getResponseCode());
    assertEquals("text/xml", res.getContentType());
    Document doc = StaxUtils.read(res.getInputStream());
    assertNotNull(doc);
    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    assertValid("//wsdl:service[@name='SOAPService']/wsdl:port[@name='SoapPort']/wsdlsoap:address[@location='" + "http://cxf.apache.org/publishedEndpointUrl1']", doc);
    assertValid("//wsdl:service[@name='SOAPService']/wsdl:port[@name='SoapPort1']/wsdlsoap:address[@location='" + "http://cxf.apache.org/publishedEndpointUrl2']", doc);
}
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) Document(org.w3c.dom.Document) WSDLReader(javax.wsdl.xml.WSDLReader) Test(org.junit.Test)

Example 64 with WebResponse

use of com.meterware.httpunit.WebResponse 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 65 with WebResponse

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

the class SpringAutoPublishServletTest method invokingEndpoint.

public void invokingEndpoint(WebRequest req) throws Exception {
    WebResponse response = newClient().getResponse(req);
    assertEquals("text/xml", response.getContentType());
    assertTrue("utf-8".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) Document(org.w3c.dom.Document)

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