Search in sources :

Example 11 with GetMethodWebRequest

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

the class RestServletGetWildcardsTest method testServletProducerGetWildcards.

@Test
public void testServletProducerGetWildcards() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/456/name=g*");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertEquals("456;Goofy", 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 GetMethodWebRequest

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

the class RestServletPojoInOutTest method testServletPojoGet.

@Test
public void testServletPojoGet() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/lives");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    String out = response.getText();
    assertNotNull(out);
    assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 13 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 14 with GetMethodWebRequest

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

the class AbstractBasicFederationTestCase method testFederationWithLocalLogout.

@Test
public void testFederationWithLocalLogout() throws Exception {
    WebConversation conversation = new WebConversation();
    HttpUnitOptions.setLoggingHttpHeaders(true);
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1));
    WebRequest request = new GetMethodWebRequest(formatUrl(this.serviceProvider1));
    WebResponse response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue(response.getURL().getPath().startsWith("/idp"));
    assertEquals(1, response.getForms().length);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider1), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider1)));
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2));
    request = new GetMethodWebRequest(formatUrl(this.serviceProvider2));
    response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider2), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider2)));
    // local logout from serviceProvider2
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2) + LOCAL_LOGOUT_URL_PARAM);
    response = conversation.getResponse(formatUrl(this.serviceProvider2) + LOCAL_LOGOUT_URL_PARAM);
    LOGGER.trace("LLO response(" + this.serviceProvider2 + "):" + response.getText());
    assertTrue("cannot reach locally logged out page", response.getText().contains("Logout"));
    // check if it was really LLO
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1));
    request = new GetMethodWebRequest(formatUrl(this.serviceProvider1));
    response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider1), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider1)));
    // LLO from serviceProvider1
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1) + LOCAL_LOGOUT_URL_PARAM);
    response = conversation.getResponse(formatUrl(this.serviceProvider1) + LOCAL_LOGOUT_URL_PARAM);
    LOGGER.trace("LLO response(" + this.serviceProvider1 + "):" + response.getText());
    assertTrue("cannot reach locally logged out page", response.getText().contains("Logout"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 15 with GetMethodWebRequest

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

the class AbstractBasicFederationTestCase method testFederationWithGlobalLogout.

@Test
public void testFederationWithGlobalLogout() throws Exception {
    WebConversation conversation = new WebConversation();
    HttpUnitOptions.setLoggingHttpHeaders(true);
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1) + "/index.jsp");
    WebRequest request = new GetMethodWebRequest(formatUrl(this.serviceProvider1) + "/index.jsp");
    WebResponse response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue(response.getURL().getPath().startsWith("/idp"));
    assertEquals(1, response.getForms().length);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider1), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider1)));
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2));
    request = new GetMethodWebRequest(formatUrl(this.serviceProvider2));
    response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider2), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider2)));
    if (performGlobalLogout()) {
        // global logout from serviceProvider2
        LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2) + GLOBAL_LOGOUT_URL_PARAM);
        response = conversation.getResponse(formatUrl(this.serviceProvider2) + GLOBAL_LOGOUT_URL_PARAM);
        LOGGER.trace("GLO response(" + this.serviceProvider2 + "):" + response.getText());
        assertTrue("cannot reach logged out page", response.getText().contains("Logout"));
        // check if GLO was successful, so serviceProvider1 is requesting IDP login form
        LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1));
        request = new GetMethodWebRequest(formatUrl(this.serviceProvider1));
        response = conversation.getResponse(request);
        LOGGER.trace("RESPONSE: " + response.getText());
        assertTrue("cannot reach IDP", response.getURL().getPath().startsWith("/idp"));
        assertEquals("no form present on supposed IDP login page", 1, response.getForms().length);
    }
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Aggregations

GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)76 WebResponse (com.meterware.httpunit.WebResponse)73 WebRequest (com.meterware.httpunit.WebRequest)72 Test (org.junit.Test)55 WebConversation (com.meterware.httpunit.WebConversation)43 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 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)8 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)8 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