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());
}
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);
}
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"));
}
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"));
}
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);
}
}
Aggregations