Search in sources :

Example 76 with OperateOnDeployment

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 77 with OperateOnDeployment

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);
}
Also used : HttpEntity(org.apache.http.HttpEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 78 with OperateOnDeployment

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);
}
Also used : HttpEntity(org.apache.http.HttpEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 79 with OperateOnDeployment

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));
}
Also used : URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 80 with OperateOnDeployment

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));
}
Also used : Cookie(org.apache.http.cookie.Cookie) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URL(java.net.URL) Header(org.apache.http.Header) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)94 Test (org.junit.Test)93 URL (java.net.URL)31 URI (java.net.URI)22 HttpGet (org.apache.http.client.methods.HttpGet)20 HttpResponse (org.apache.http.HttpResponse)17 InitialContext (javax.naming.InitialContext)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)13 QName (javax.xml.namespace.QName)11 Service (javax.xml.ws.Service)11 HttpEntity (org.apache.http.HttpEntity)10 Bus (org.apache.cxf.Bus)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)5 WebConversation (com.meterware.httpunit.WebConversation)5 WebForm (com.meterware.httpunit.WebForm)5 WebRequest (com.meterware.httpunit.WebRequest)5