Package com.meterware.servletunit

Examples of com.meterware.servletunit.ServletUnitClient


    public void testGetRepositoryGroups()
        throws Exception
    {
        ServletRunner sr = new ServletRunner();
        ServletUnitClient sc = sr.newClient();

        Configuration configuration = createInitialConfiguration();

        archivaConfiguration.getConfiguration();
        archivaConfigurationControl.setReturnValue( configuration, 6 );
        archivaConfigurationControl.replay();

        action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositoryGroups.action" ).getRequest() );
        action.prepare();
        String result = action.execute();
        assertEquals( Action.SUCCESS, result );

        assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
View Full Code Here


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

        //test the '/' context get service list
        WebResponse  res = client.getResponse(CONTEXT_URL + "/");
        WebLink[] links = res.getLinks();
        assertEquals("There should get two links for the services", 3, links.length);
       
        Set<String> links2 = new HashSet<String>();
        for (WebLink l : links) {
View Full Code Here

        testInvokingRestService("/services/endpoint/restful");
    }
   
    @Test
    public void testJsonService() throws Exception {
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
       
        WebRequest req =
            new GetMethodQueryWebRequest(CONTEXT_URL + "/services/serverFactory/json/customers");
        WebResponse response = client.getResponse(req);
        assertTrue("Can't get the right Json customers ", response.getText().indexOf(JSON_CUSTOMER) > 0);
       
        req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/serverFactory/json/customers/123");
        response = client.getResponse(req);       
        assertEquals("Can't get the right Json customer ", response.getText(), JSON_CUSTOMER);
    }
View Full Code Here

        assertEquals("Can't get the right Json customer ", response.getText(), JSON_CUSTOMER);
    }
   
   
    private void testInvokingRestService(String serviceAddress) throws Exception {
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
       
        WebRequest req =
            new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress + "/customers");
       
        WebResponse response = client.getResponse(req);       
        Document doc = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);

        addNamespace("c", "http://cxf.apache.org/jra");
        assertValid("/c:customers", doc);
        assertValid("/c:customers/c:customer/c:id[text()='123']", doc);
        assertValid("/c:customers/c:customer/c:name[text()='Dan Diephouse']", doc);
       
        req = new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress + "/customers/123");
        response = client.getResponse(req);       
        doc = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);
       
        assertValid("/c:customer", doc);
        assertValid("/c:customer/c:id[text()='123']", doc);
        assertValid("/c:customer/c:name[text()='Dan Diephouse']", doc);
       
        // Try invalid customer
        req = new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress + "/customers/0");
        response = client.getResponse(req);
       
        assertEquals("Expect the wrong response code", response.getResponseCode(), 500);
        doc = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);
       
        assertValid("//c:CustomerNotFoundFault", doc);
       
        PostMethodWebRequest postReq =
            new PostMethodWebRequest(CONTEXT_URL + serviceAddress + "/customers",
                                 getClass().getResourceAsStream("add.xml"),
                                 "text/xml; charset=UTF-8");
        response = client.getResponse(postReq);
        doc = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);
        assertValid("/c:addCustomer", doc);
       
        PutMethodWebRequest putReq =
            new PutMethodWebRequest(CONTEXT_URL + serviceAddress + "/customers/123",
                                 getClass().getResourceAsStream("update.xml"),
                                 "text/xml; charset=UTF-8");
        response = client.getResponse(putReq);
        doc = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc);      
        assertValid("/c:updateCustomer", doc);
     
        // Get the updated document
        req = new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress + "/customers/123");
        response = client.getResponse(req);
        doc = DOMUtils.readXml(response.getInputStream());
        assertNotNull(doc)
       
        assertValid("/c:customer", doc);
        assertValid("/c:customer/c:id[text()='123']", doc);
View Full Code Here

    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 = DOMUtils.readXml(response.getInputStream());
View Full Code Here

        assertValid("//h:sayHiResponse", doc);   
    }
   
    @Test
    public void testGetServiceList() throws Exception {
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);

        WebResponse res = client.getResponse(CONTEXT_URL + "/services");
       
       
        WebLink[] links = res.getLinks();
        assertEquals("Wrong number of service links", 4, 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"));
        assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
        assertEquals("text/html", res.getContentType());
       
        res = client.getResponse(CONTEXT_URL + "/services/");
      
       
        links = res.getLinks();
        links2.clear();
        for (WebLink l : links) {
View Full Code Here

        assertNotNull(BusFactory.getDefaultBus(false));
    }
   
    @Test
    public void testGetUnformatServiceList() throws Exception {
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);

        WebResponse res = client.getResponse(CONTEXT_URL + "/services?formatted=false");
       
        assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter3"));
        assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter2"));
        assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter"));
       
View Full Code Here

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

        WebResponse res = client.getResponse(CONTEXT_URL + "/services");
       
        assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter3"));
        assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter2"));
        assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter"));
        WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl");
        res = client.getResponse(req);
        req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter2?wsdl");
        res = client.getResponse(req);
        req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?wsdl");
        res = client.getResponse(req);
        String loopAddr = "http://127.0.0.1/mycontext";
        res = client.getResponse(loopAddr + "/services");
        assertFalse(res.getText().contains(
             "http://127.0.0.1/mycontext/serviceshttp://localhost/mycontext/services/greeter"));
               
    }
View Full Code Here

               
    }
   
    @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

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.