Search in sources :

Example 66 with WebResponse

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

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

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

Example 69 with WebResponse

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

the class RestServletVerbTest method testGetAll.

@Test
public void testGetAll() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertEquals("[{ \"id\":\"1\", \"name\":\"Scott\" },{ \"id\":\"2\", \"name\":\"Claus\" }]", response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) HeaderOnlyWebRequest(com.meterware.httpunit.HeaderOnlyWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 70 with WebResponse

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

the class RestServletVerbTest method testGetOne.

@Test
public void testGetOne() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/1");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertEquals("{ \"id\":\"1\", \"name\":\"Scott\" }", response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) HeaderOnlyWebRequest(com.meterware.httpunit.HeaderOnlyWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

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