Package com.meterware.httpunit

Examples of com.meterware.httpunit.WebResponse


    public void testServletPojoGet() throws Exception {
       
        WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/lives");
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
        WebResponse response = client.getResponse(req);

        assertEquals(200, response.getResponseCode());

        String out = response.getText();

        assertNotNull(out);
        assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
    }  
View Full Code Here


        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 = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);

        addNamespace("h", "http://apache.org/hello_world_soap_http/types");

        assertValid("/s:Envelope/s:Body", doc);
View Full Code Here

    @Test
    public void testGetServiceList() throws Exception {
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);

        WebResponse res = client.getResponse(CONTEXT_URL + "/services");
       
       
        WebLink[] links = res.getLinks();
        assertEquals("There should get two links for the service", 3, links.length);
       
        Set<String> links2 = new HashSet<String>();
        for (WebLink l : links) {
            links2.add(l.getURLString());
        }
       
        assertTrue(links2.contains(CONTEXT_URL + "/services/greeter?wsdl"));      
        assertTrue(links2.contains(CONTEXT_URL + "/services/greeter2?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("There should get two links for the service", 3, links.length);
        assertTrue(links2.contains(CONTEXT_URL + "/services/greeter?wsdl"));      
        assertTrue(links2.contains(CONTEXT_URL + "/services/greeter2?wsdl"));
       
        assertEquals("text/html", res.getContentType());
       
      
        // Ensure that the Bus is available for people doing an Endpoint.publish() or similar.
        assertNotNull(BusFactory.getDefaultBus(false));
    }
View Full Code Here

        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 = DOMUtils.readXml(res.getInputStream());
        assertNotNull(doc);
       
        assertValid("//wsdl:operation[@name='greetMe']", doc);
        assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/greeter']", doc);
    }
View Full Code Here

        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(true);
       
        WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?wsdl");
       
        WebResponse res = client.getResponse(req);
        assertEquals(200, res.getResponseCode());
        assertEquals("text/xml", res.getContentType());
        Document doc = DOMUtils.readXml(res.getInputStream());
        assertNotNull(doc);
       
        assertXPathEquals("//xsd:include/@schemaLocation",
                          "http://localhost/mycontext/services/greeter3?xsd=hello_world_includes2.xsd",
                          doc.getDocumentElement());
       
        req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?xsd=hello_world_includes2.xsd");
       
        res = client.getResponse(req);
        assertEquals(200, res.getResponseCode());
        assertEquals("text/xml", res.getContentType());
        doc = DOMUtils.readXml(res.getInputStream());
        assertNotNull(doc);

        assertValid("//xsd:complexType[@name='ErrorCode']", doc);
    }
View Full Code Here

        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 = DOMUtils.readXml(res.getInputStream());
        assertNotNull(doc);
       
        addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
        assertValid("//wsdl:operation[@name='greetMe']", doc);
        assertValid("//http:address[@location='" + CONTEXT_URL + "/services/greeter2']", doc);
View Full Code Here

    @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());
    }
View Full Code Here

        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(true);

        WebRequest req
            = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl");
        WebResponse res = client.getResponse(req);
        assertEquals(200, res.getResponseCode());
        String text = res.getText();
        assertEquals("text/xml", res.getContentType());
        assertTrue(text.contains(CONTEXT_URL + "/services/greeter?wsdl=test_import.xsd"));

        req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl=test_import.xsd");
        res = client.getResponse(req);
        assertEquals(200, res.getResponseCode());
        text = res.getText();
       
        assertEquals("text/xml", res.getContentType());
        assertTrue("the xsd should contain the completType SimpleStruct",
                   text.contains("<complexType name=\"SimpleStruct\">"));
    }
View Full Code Here

        invokingEndpoint(req);
    }
   
    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 = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);

        addNamespace("h", "http://apache.org/hello_world_soap_http/types");
        assertValid("/s:Envelope/s:Body", doc);
        assertValid("//h:sayHiResponse", doc);
View Full Code Here

       
        WebRequest req =
            new GetMethodQueryWebRequest(CONTEXT_URL + "/services/SOAPService/greetMe?"
                                         + "requestType=hello");
       
        WebResponse response = client.getResponse(req);       
        Document doc = DOMUtils.readXml(response.getInputStream());
        addNamespace("h", "http://apache.org/hello_world_soap_http/types");
        assertValid("/s:Envelope/s:Body", doc);
        assertValid("//h:greetMeResponse", doc);
       
        req =
            new GetMethodQueryWebRequest(CONTEXT_URL + "/services/DerivedGreeterService/greetMe?"
                                         + "requestType=hello");
       
        response = client.getResponse(req);       
        doc = DOMUtils.readXml(response.getInputStream());
        addNamespace("h", "http://apache.org/hello_world_soap_http/types");
        assertValid("/s:Envelope/s:Body", doc);
        assertValid("//h:greetMeResponse", doc);
    }
View Full Code Here

TOP

Related Classes of com.meterware.httpunit.WebResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.