Search in sources :

Example 1 with PostMethodWebRequest

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

the class HttpClientRouteTest method testHttpConverter.

@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());
}
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 2 with PostMethodWebRequest

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

the class HttpClientRouteTest method testHttpClient.

@Test
public void testHttpClient() throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), CONTENT_TYPE);
    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()), CONTENT_TYPE);
    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);
}
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 3 with PostMethodWebRequest

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

the class ServletTransferExceptionTest method testTransferException.

@Test
public void testTransferException() throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream("".getBytes()), "text/plain");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(500, response.getResponseCode());
    assertEquals(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, response.getContentType());
    Object object = HttpHelper.deserializeJavaObjectFromStream(response.getInputStream());
    assertNotNull(object);
    IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, object);
    assertEquals("Damn", cause.getMessage());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Example 4 with PostMethodWebRequest

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

the class RestServletBindingModeAutoWithJsonTest method testServletProducerGet.

@Test
public void testServletProducerGet() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(UserPojo.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();
    UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.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 5 with PostMethodWebRequest

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

the class RestServletBindingModeJsonTest method testBindingMode.

@Test
public void testBindingMode() 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)

Aggregations

PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)29 WebRequest (com.meterware.httpunit.WebRequest)28 Test (org.junit.Test)26 WebResponse (com.meterware.httpunit.WebResponse)25 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)23 ByteArrayInputStream (java.io.ByteArrayInputStream)21 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)8 Document (org.w3c.dom.Document)4 HttpException (com.meterware.httpunit.HttpException)2 List (java.util.List)2 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)1 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)1 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)1 InvocationContext (com.meterware.servletunit.InvocationContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)1 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)1