Search in sources :

Example 26 with WebConversation

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

the class MyResourceTest method testGetSubResourceWithCorrectCredentials.

@Test
public void testGetSubResourceWithCorrectCredentials() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "u1", "p1");
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource/1");
    WebResponse response = null;
    try {
        response = conv.getResponse(getRequest);
    } catch (AuthorizationRequiredException e) {
        fail(e.getMessage());
    }
    assertNotNull(response);
    assertTrue(response.getText().contains("get1"));
}
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 27 with WebConversation

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

the class MyResourceTest method testGetWithIncorrectCredentials.

@Test
public void testGetWithIncorrectCredentials() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "random", "random");
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
    try {
        WebResponse response = conv.getResponse(getRequest);
    } catch (AuthorizationRequiredException e) {
        assertNotNull(e);
        return;
    }
    fail("GET can be called with incorrect credentials");
}
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 28 with WebConversation

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

the class MyResourceTest method testPost.

@Test
public void testPost() throws IOException, SAXException {
    WebConversation conv = new WebConversation();
    conv.setAuthentication("file", "u1", "p1");
    PostMethodWebRequest postRequest = new PostMethodWebRequest(base + "/webresources/myresource");
    try {
        WebResponse response = conv.getResponse(postRequest);
    } catch (HttpException e) {
        assertNotNull(e);
        assertEquals(403, e.getResponseCode());
        return;
    }
    fail("POST is not authorized and can still be called");
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) HttpException(com.meterware.httpunit.HttpException) Test(org.junit.Test)

Example 29 with WebConversation

use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.

the class RestoreOriginalRequestTestCase method testRedirectOriginalRequest.

@Test
@OperateOnDeployment("service-provider-1")
public void testRedirectOriginalRequest(@ArquillianResource URL serviceProvider1) throws Exception {
    WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider1) + "/savedRequest/savedRequest.html");
    WebConversation conversation = new WebConversation();
    WebResponse response = conversation.getResponse(request);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue(response.getText().contains("Back to the original requested resource."));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebConversation(com.meterware.httpunit.WebConversation) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 30 with WebConversation

use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.

the class RestoreOriginalRequestTestCase method testPostOriginalRequestWithParams.

@Test
@OperateOnDeployment("service-provider-2")
public void testPostOriginalRequestWithParams(@ArquillianResource URL serviceProvider2) throws Exception {
    WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider2) + "/savedRequest/savedRequest.jsp");
    request.setParameter("SAVED_PARAM", "Param was saved.");
    WebConversation conversation = new WebConversation();
    WebResponse response = conversation.getResponse(request);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue(response.getText().contains("Param was saved."));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebConversation(com.meterware.httpunit.WebConversation) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

WebConversation (com.meterware.httpunit.WebConversation)46 Test (org.junit.Test)46 WebResponse (com.meterware.httpunit.WebResponse)44 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)43 WebRequest (com.meterware.httpunit.WebRequest)39 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 AuthorizationRequiredException (com.meterware.httpunit.AuthorizationRequiredException)3 PrintWriter (java.io.PrintWriter)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 HttpException (com.meterware.httpunit.HttpException)2 WebLink (com.meterware.httpunit.WebLink)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)1 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1