Package com.meterware.servletunit

Examples of com.meterware.servletunit.ServletUnitClient


   

    @Test
    public void testHttpClient() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        WebResponse response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/hello", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
       
        req = new PostMethodWebRequest(CONTEXT_URL + "/services/helloworld", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/helloworld", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        client.setExceptionsThrownOnErrorStatus(false);
    }
View Full Code Here


    }
   
    @Test
    public void testHttpConverter() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testConverter", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
        WebResponse response = client.getResponse(req);       
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        assertEquals("The response body is wrong", "Bye World", response.getText());
    }
View Full Code Here

    private static final String CONTENT_TYPE = "text/xml";

    @Test
    public void testHttpClient() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        WebResponse response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/hello", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
       
        req = new PostMethodWebRequest(CONTEXT_URL + "/services/helloworld", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/helloworld", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        client.setExceptionsThrownOnErrorStatus(false);
    }
View Full Code Here

    }
   
    @Test
    public void testHttpConverter() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testConverter", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
        WebResponse response = client.getResponse(req);       
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        assertEquals("The response body is wrong", "Bye World", response.getText());
    }
View Full Code Here

    /**
     * Gets the response for the given URL.
     */
    WebResponse getResponse(String url) {
        try {
            ServletUnitClient client = container.newClient();
            return client.getResponse(url);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to get response on " + url + ". Error: " + e.getMessage());
        }
        return null;
View Full Code Here

     * Asserts that the given URL generates the given error code.
     * @param error HTTP error code
     * @param url URL string
     */
    void assertError(int error, String url) throws Exception {
        ServletUnitClient client = container.newClient();
        try {
            client.getResponse(url);
            fail("expected HTTP error " + error + " on " + url);
        } catch (HttpException e) {
            assertEquals("Unexpected HTTP Error code for " + url, error, e.getResponseCode());
        }
    }
View Full Code Here

   

    @Test
    public void testHttpClient() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        WebResponse response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/hello", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
       
        req = new PostMethodWebRequest(CONTEXT_URL + "/services/helloworld", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/helloworld", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        client.setExceptionsThrownOnErrorStatus(false);
    }
View Full Code Here

        assertNotNull(BusFactory.getDefaultBus(false));
    }
   
    @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 = DOMUtils.readXml(res.getInputStream());
        assertNotNull(doc);
       
View Full Code Here

        assertValid("//wsdl:operation[@name='greetMe']", doc);
        assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/greeter']", doc);
    }
    @Test
    public void testGetWSDLWithIncludes() throws Exception {
        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);
View Full Code Here

        assertValid("//xsd:complexType[@name='ErrorCode']", doc);
    }
   
    @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 = DOMUtils.readXml(res.getInputStream());
        assertNotNull(doc);
View Full Code Here

TOP

Related Classes of com.meterware.servletunit.ServletUnitClient

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.