Search in sources :

Example 26 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient 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 27 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient 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 28 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient 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)

Example 29 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient in project camel by apache.

the class RestServletVerbTest method testPost.

@Test
public void testPost() throws Exception {
    final String body = "{ \"id\":\"1\", \"name\":\"Scott\" }";
    MockEndpoint mock = getMockEndpoint("mock:create");
    mock.expectedBodiesReceived(body);
    mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST");
    WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users", new ByteArrayInputStream(body.getBytes()), "application/json");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertMockEndpointsSatisfied();
}
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) 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 30 with ServletUnitClient

use of com.meterware.servletunit.ServletUnitClient in project camel by apache.

the class RestServletVerbTest method testDelete.

@Test
public void testDelete() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:delete");
    mock.expectedHeaderReceived("id", "1");
    mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "DELETE");
    WebRequest req = new HeaderOnlyWebRequest(CONTEXT_URL + "/services/users/1") {

        @Override
        public String getMethod() {
            return "DELETE";
        }
    };
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertMockEndpointsSatisfied();
}
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) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) HeaderOnlyWebRequest(com.meterware.httpunit.HeaderOnlyWebRequest) Test(org.junit.Test)

Aggregations

ServletUnitClient (com.meterware.servletunit.ServletUnitClient)42 WebRequest (com.meterware.httpunit.WebRequest)41 WebResponse (com.meterware.httpunit.WebResponse)41 Test (org.junit.Test)33 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)30 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)27 ByteArrayInputStream (java.io.ByteArrayInputStream)27 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)12 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)5 HttpException (com.meterware.httpunit.HttpException)3 BasicBSONObject (org.bson.BasicBSONObject)3 ObjectId (org.bson.types.ObjectId)2 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)2 ContentSHA (v7db.files.spi.ContentSHA)2 Date (java.util.Date)1 List (java.util.List)1 FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)1 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)1