Search in sources :

Example 71 with WebResponse

use of com.meterware.httpunit.WebResponse 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 72 with WebResponse

use of com.meterware.httpunit.WebResponse 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)

Example 73 with WebResponse

use of com.meterware.httpunit.WebResponse 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 74 with WebResponse

use of com.meterware.httpunit.WebResponse 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 75 with WebResponse

use of com.meterware.httpunit.WebResponse 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)

Aggregations

WebResponse (com.meterware.httpunit.WebResponse)121 WebRequest (com.meterware.httpunit.WebRequest)108 Test (org.junit.Test)93 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)91 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)56 WebConversation (com.meterware.httpunit.WebConversation)44 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)42 ByteArrayInputStream (java.io.ByteArrayInputStream)28 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)15 TextBlock (com.meterware.httpunit.TextBlock)14 URL (java.net.URL)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 Document (org.w3c.dom.Document)12 HttpSession (javax.servlet.http.HttpSession)9 WebLink (com.meterware.httpunit.WebLink)8 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5