Search in sources :

Example 1 with ServletUnitClient

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

the class HttpClientRouteExampleSpringTest method testHttpRestricMethod.

@Test
public void testHttpRestricMethod() throws Exception {
    ServletUnitClient client = newClient();
    // Send a web get method request
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/hello");
    WebResponse response = client.getResponse(req);
    assertEquals("Get a wrong response message.", "OK", response.getResponseMessage());
    assertEquals("Get a wrong response text.", "Add a name parameter to uri, eg ?name=foo", response.getText());
    req = new GetMethodWebRequest(CONTEXT_URL + "/services/hello?name=Willem");
    response = client.getResponse(req);
    assertEquals("Get a wrong response text.", "Hello Willem how are you?", 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 2 with ServletUnitClient

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

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

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

the class MultiServletConsumerTest method getService.

public String getService(String path) throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + path);
    ServletUnitClient client = newClient();
    WebResponse response = client.getResponse(req);
    return 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)

Example 5 with ServletUnitClient

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

the class ServletNoSlashNeededTest method testNoSlashNeeded.

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

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