Search in sources :

Example 11 with ServletUnitClient

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

the class ServletSetBodyTest method testSetBody.

@Test
public void testSetBody() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/hello");
    ServletUnitClient client = newClient();
    WebResponse response = client.getResponse(req);
    assertEquals("The response message is wrong ", "Bye World", response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 12 with ServletUnitClient

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

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

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

Example 15 with ServletUnitClient

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

the class RestServletBindingModeJsonTest method testBindingModeWrong.

@Test
public void testBindingModeWrong() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:input");
    mock.expectedMessageCount(0);
    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(500, response.getResponseCode());
    assertMockEndpointsSatisfied();
}
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

ServletUnitClient (com.meterware.servletunit.ServletUnitClient)58 WebResponse (com.meterware.httpunit.WebResponse)56 WebRequest (com.meterware.httpunit.WebRequest)52 Test (org.junit.Test)47 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)40 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)34 ByteArrayInputStream (java.io.ByteArrayInputStream)27 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)12 Document (org.w3c.dom.Document)7 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)6 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 HttpException (com.meterware.httpunit.HttpException)3 WebLink (com.meterware.httpunit.WebLink)3 HashSet (java.util.HashSet)3 BasicBSONObject (org.bson.BasicBSONObject)3 ObjectId (org.bson.types.ObjectId)2 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)2 ContentSHA (v7db.files.spi.ContentSHA)2 InputStream (java.io.InputStream)1