Search in sources :

Example 21 with WebRequest

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

the class RestServletPojoInOutTest method testServletPojoInOut.

@Test
public void testServletPojoInOut() throws Exception {
    String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/lives", new ByteArrayInputStream(body.getBytes()), "application/json");
    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);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Example 22 with WebRequest

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

the class RestServletPostJsonJaxbPojoTest 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 23 with WebRequest

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

the class RestServletPostJsonPojoListTest method testPostJaxbPojo.

@Test
public void testPostJaxbPojo() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(1);
    String body = "[ {\"id\": 123, \"name\": \"Donald Duck\"}, {\"id\": 456, \"name\": \"John Doe\"} ]";
    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());
    assertEquals("application/json", response.getContentType());
    assertMockEndpointsSatisfied();
    List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
    assertNotNull(list);
    assertEquals(2, list.size());
    UserPojo user = (UserPojo) list.get(0);
    assertEquals(123, user.getId());
    assertEquals("Donald Duck", user.getName());
    user = (UserPojo) list.get(1);
    assertEquals(456, user.getId());
    assertEquals("John Doe", 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) List(java.util.List) Test(org.junit.Test)

Example 24 with WebRequest

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

the class RestServletPostXmlJaxbPojoTest method testPostJaxbPojoNoContentType.

@Test
public void testPostJaxbPojoNoContentType() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
    String body = "<user name=\"Donald Duck\" id=\"456\"></user>";
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "foo");
    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(456, 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 25 with WebRequest

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

the class RestServletVerbTest method testPut.

@Test
public void testPut() throws Exception {
    final String body = "{ \"id\":\"1\", \"name\":\"Scott\" }";
    MockEndpoint mock = getMockEndpoint("mock:update");
    mock.expectedBodiesReceived(body);
    mock.expectedHeaderReceived("id", "1");
    mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "PUT");
    WebRequest req = new PutMethodWebRequest(CONTEXT_URL + "/services/users/1", new ByteArrayInputStream(body.getBytes()), "application/json");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertMockEndpointsSatisfied();
}
Also used : PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) 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) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Aggregations

WebRequest (com.meterware.httpunit.WebRequest)113 WebResponse (com.meterware.httpunit.WebResponse)108 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)90 Test (org.junit.Test)87 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)52 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)45 WebConversation (com.meterware.httpunit.WebConversation)39 ByteArrayInputStream (java.io.ByteArrayInputStream)27 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)14 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)10 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5