use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.
the class SubDeploymentAvailableInClassPathTestCase method testWarsDontSeeEachOtherInEar.
/**
* Tests that for a .ear like this one:
* myapp.ear
* |
* |--- web-one.war
* |
* |--- web-two.war
* <p/>
* <p/>
* the classes within the web-one.war *don't* have access to the classes in the web-two.war
*
* @throws Exception
*/
@Test
@OperateOnDeployment("ear-with-multiple-wars")
public void testWarsDontSeeEachOtherInEar(@ContainerResource ManagementClient managementClient) throws Exception {
try (final CloseableHttpClient httpClient = HttpClients.createDefault()) {
final String classInOtherWar = HelloWorldServlet.class.getName();
final String requestURL = managementClient.getWebUri() + "/" + OTHER_WEB_APP_CONTEXT + ServletInOtherWar.URL_PATTERN + "?" + ServletInOtherWar.CLASS_IN_OTHER_WAR_PARAMETER + "=" + classInOtherWar;
final HttpGet request = new HttpGet(requestURL);
final HttpResponse response = httpClient.execute(request);
final HttpEntity entity = response.getEntity();
Assert.assertNotNull("Response message from servlet was null", entity);
final String responseMessage = EntityUtils.toString(entity);
Assert.assertEquals("Unexpected echo message from servlet", ServletInOtherWar.SUCCESS_MESSAGE, responseMessage);
}
}
use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.
the class XercesUsageTestCase method testXercesUsageInServletInJSFApp.
/**
* Test that a JSF web application, with xerces jar packaged within the deployment, functions correctly while using
* the packaged xerces API.
*
* @throws Exception
*/
@OperateOnDeployment("app-with-jsf")
@Test
public void testXercesUsageInServletInJSFApp() throws Exception {
final HttpClient httpClient = new DefaultHttpClient();
final String xml = "dummy.xml";
final String requestURL = withJsf.toExternalForm() + XercesUsageServlet.URL_PATTERN + "?" + XercesUsageServlet.XML_RESOURCE_NAME_PARAMETER + "=" + xml;
final HttpGet request = new HttpGet(requestURL);
final HttpResponse response = httpClient.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
Assert.assertEquals("Unexpected status code", 200, statusCode);
final HttpEntity entity = response.getEntity();
Assert.assertNotNull("Response message from servlet was null", entity);
final String responseMessage = EntityUtils.toString(entity);
Assert.assertEquals("Unexpected echo message from servlet", XercesUsageServlet.SUCCESS_MESSAGE, responseMessage);
}
use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.
the class XercesUsageTestCase method testXercesUsageInServletInNonJSFApp.
/**
* Test that a non-JSF web application, with xerces jar packaged within the deployment, functions correctly
* while using the packaged xerces API.
*
* @throws Exception
*/
@OperateOnDeployment("app-without-jsf")
@Test
public void testXercesUsageInServletInNonJSFApp() throws Exception {
final HttpClient httpClient = new DefaultHttpClient();
final String xml = "dummy.xml";
final String requestURL = withoutJsf.toExternalForm() + XercesUsageServlet.URL_PATTERN + "?" + XercesUsageServlet.XML_RESOURCE_NAME_PARAMETER + "=" + xml;
final HttpGet request = new HttpGet(requestURL);
final HttpResponse response = httpClient.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
Assert.assertEquals("Unexpected status code", 200, statusCode);
final HttpEntity entity = response.getEntity();
Assert.assertNotNull("Response message from servlet was null", entity);
final String responseMessage = EntityUtils.toString(entity);
Assert.assertEquals("Unexpected echo message from servlet", XercesUsageServlet.SUCCESS_MESSAGE, responseMessage);
}
use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.
the class ReuseAuthenticatedSubjectTestCase method testEjbInSameSecurityDomain.
/**
* Test whether if web app and EJB belong to the same security domain then the user is not unnecessarily reauthenticated
* when the web app invokes an EJB.
*
* @param url
* @throws Exception
*/
@OperateOnDeployment(DEPLOYMENT_NAME)
@Test
public void testEjbInSameSecurityDomain(@ArquillianResource URL url) throws Exception {
resetCounter(url);
final URL servletUrl = new URL(url.toExternalForm() + ReuseAuthenticatedSubjectServlet.SERVLET_PATH.substring(1) + "?" + ReuseAuthenticatedSubjectServlet.SAME_SECURITY_DOMAIN_PARAM + "=true");
String servletOutput = Utils.makeCallWithBasicAuthn(servletUrl, USER, PASSWORD, 200);
Assert.assertEquals("Unexpected servlet output after EJB call", EjbSecurityDomainAsServletImpl.SAY_HELLO, servletOutput);
Assert.assertEquals("Authenticated subject was not reused for EJB from the same security domain", "1", getCounter(url));
}
use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.
the class FormAuthUnitTestCase method testFormAuthException.
/**
* Test that a bad login is redirected to the errors.jsp and that the
* session j_exception is not null.
*/
@Test
@OperateOnDeployment("form-auth.war")
public void testFormAuthException() throws Exception {
log.trace("+++ testFormAuthException");
URL url = new URL(baseURLNoAuth + "restricted/SecuredServlet");
HttpGet httpget = new HttpGet(url.toURI());
log.trace("Executing request " + httpget.getRequestLine());
HttpResponse response = httpclient.execute(httpget);
int statusCode = response.getStatusLine().getStatusCode();
Header[] errorHeaders = response.getHeaders("X-NoJException");
assertTrue("Wrong response code: " + statusCode, statusCode == HttpURLConnection.HTTP_OK);
assertTrue("X-NoJException(" + Arrays.toString(errorHeaders) + ") is null", errorHeaders.length == 0);
HttpEntity entity = response.getEntity();
if ((entity != null) && (entity.getContentLength() > 0)) {
String body = EntityUtils.toString(entity);
assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0);
} else {
fail("Empty body in response");
}
String sessionID = null;
for (Cookie k : httpclient.getCookieStore().getCookies()) {
if (k.getName().equalsIgnoreCase("JSESSIONID"))
sessionID = k.getValue();
}
log.trace("Saw JSESSIONID=" + sessionID);
// Submit the login form
HttpPost formPost = new HttpPost(baseURLNoAuth + "j_security_check");
formPost.addHeader("Referer", baseURLNoAuth + "restricted/login.html");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("j_username", "baduser"));
formparams.add(new BasicNameValuePair("j_password", "badpass"));
formPost.setEntity(new UrlEncodedFormEntity(formparams, "UTF-8"));
log.trace("Executing request " + formPost.getRequestLine());
HttpResponse postResponse = httpclient.execute(formPost);
statusCode = postResponse.getStatusLine().getStatusCode();
errorHeaders = postResponse.getHeaders("X-NoJException");
assertTrue("Should see HTTP_OK. Got " + statusCode, statusCode == HttpURLConnection.HTTP_OK);
assertTrue("X-NoJException(" + Arrays.toString(errorHeaders) + ") is not null", errorHeaders.length != 0);
log.debug("Saw X-JException, " + Arrays.toString(errorHeaders));
}
Aggregations