Search in sources :

Example 1 with GetMethodWebRequest

use of com.meterware.httpunit.GetMethodWebRequest in project javaee7-samples by javaee-samples.

the class MyResourceTest method testGetWithCorrectCredentials.

@Test
public void testGetWithCorrectCredentials() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "u1", "p1");
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
    WebResponse response = null;
    try {
        response = conv.getResponse(getRequest);
    } catch (AuthorizationRequiredException e) {
        fail(e.getMessage());
    }
    assertNotNull(response);
    assertTrue(response.getText().contains("get"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) AuthorizationRequiredException(com.meterware.httpunit.AuthorizationRequiredException) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 2 with GetMethodWebRequest

use of com.meterware.httpunit.GetMethodWebRequest 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 3 with GetMethodWebRequest

use of com.meterware.httpunit.GetMethodWebRequest 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 4 with GetMethodWebRequest

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

Example 5 with GetMethodWebRequest

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

the class ServletRootPathTest method testRootPath.

@Test
public void testRootPath() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/");
    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

GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)74 WebResponse (com.meterware.httpunit.WebResponse)73 WebRequest (com.meterware.httpunit.WebRequest)70 Test (org.junit.Test)53 WebConversation (com.meterware.httpunit.WebConversation)42 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)16 TextBlock (com.meterware.httpunit.TextBlock)14 URL (java.net.URL)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 HttpSession (javax.servlet.http.HttpSession)9 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)8 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)7 WebForm (com.meterware.httpunit.WebForm)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)4 WebLink (com.meterware.httpunit.WebLink)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AuthorizationRequiredException (com.meterware.httpunit.AuthorizationRequiredException)3 WebTable (com.meterware.httpunit.WebTable)3