Search in sources :

Example 16 with PostMethodWebRequest

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

the class HttpClientRouteTest method testHttpUnicodeResponseWithObjectResponse.

@Test
public void testHttpUnicodeResponseWithObjectResponse() throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testUnicodeWithObjectResponse", 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", UNICODE_TEXT, 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 17 with PostMethodWebRequest

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

the class HttpClientRouteTest method testHttpUnicodeResponseWithStringResponse.

@Test
public void testHttpUnicodeResponseWithStringResponse() throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testUnicodeWithStringResponse", 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", UNICODE_TEXT, 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 18 with PostMethodWebRequest

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

the class HttpClientRouteTest method testHttpRestricMethod.

@Test
public void testHttpRestricMethod() throws Exception {
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testHttpMethodRestrict", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
    ServletUnitClient client = newClient();
    WebResponse response = client.getResponse(req);
    assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
    assertEquals("The response body is wrong", POST_DATA, response.getText());
    // Send other web method request
    req = new GetMethodWebRequest(CONTEXT_URL + "/services/testHttpMethodRestrict");
    try {
        response = client.getResponse(req);
        fail("Expect the exception here");
    } catch (Exception ex) {
        HttpException httpException = (HttpException) ex;
        assertEquals("Get a wrong response code", 405, httpException.getResponseCode());
    }
}
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) HttpException(com.meterware.httpunit.HttpException) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) HttpException(com.meterware.httpunit.HttpException) Test(org.junit.Test)

Example 19 with PostMethodWebRequest

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

the class RestServletPostJsonPojoTest method testPostJaxbPojo.

@Test
public void testPostJaxbPojo() 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 20 with PostMethodWebRequest

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

the class RestServletBindingModeAutoWithXmlTest method testServletProducerGet.

@Test
public void testServletProducerGet() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
    String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "application/xml");
    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)23 WebResponse (com.meterware.httpunit.WebResponse)22 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)22 Test (org.junit.Test)22 WebRequest (com.meterware.httpunit.WebRequest)21 ByteArrayInputStream (java.io.ByteArrayInputStream)21 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)7 HttpException (com.meterware.httpunit.HttpException)3 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)1 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)1 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)1 WebConversation (com.meterware.httpunit.WebConversation)1 List (java.util.List)1 FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)1 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)1