PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/SubDeploymentAvailableInClassPathTestCase.java

https://bitbucket.org/cprenzberg/wildfly
Java | 203 lines | 103 code | 25 blank | 75 comment | 0 complexity | db90a1a1536e852ffcf17ef875f69a92 MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments;
  23. import org.apache.http.HttpEntity;
  24. import org.apache.http.HttpResponse;
  25. import org.apache.http.client.HttpClient;
  26. import org.apache.http.client.methods.HttpGet;
  27. import org.apache.http.impl.client.DefaultHttpClient;
  28. import org.apache.http.util.EntityUtils;
  29. import org.jboss.arquillian.container.test.api.Deployment;
  30. import org.jboss.arquillian.container.test.api.OperateOnDeployment;
  31. import org.jboss.arquillian.container.test.api.RunAsClient;
  32. import org.jboss.arquillian.junit.Arquillian;
  33. import org.jboss.as.arquillian.api.ContainerResource;
  34. import org.jboss.as.arquillian.container.ManagementClient;
  35. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.EJBBusinessInterface;
  36. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.SimpleSLSB;
  37. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.EjbInvokingServlet;
  38. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.HelloWorldServlet;
  39. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.ServletInOtherWar;
  40. import org.jboss.logging.Logger;
  41. import org.jboss.shrinkwrap.api.ShrinkWrap;
  42. import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
  43. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  44. import org.jboss.shrinkwrap.api.spec.WebArchive;
  45. import org.junit.Assert;
  46. import org.junit.Test;
  47. import org.junit.runner.RunWith;
  48. /**
  49. * Tests various scenarios for class access between subdeployments within a .ear.
  50. *
  51. * @see https://issues.jboss.org/browse/AS7-306
  52. * User: Jaikiran Pai
  53. */
  54. @RunWith(Arquillian.class)
  55. @RunAsClient
  56. public class SubDeploymentAvailableInClassPathTestCase {
  57. private static final Logger logger = Logger.getLogger(SubDeploymentAvailableInClassPathTestCase.class);
  58. private static final String WEB_APP_CONTEXT_ONE = "war-access-to-ejb";
  59. private static final String WEB_APP_CONTEXT_TWO = "war-access-to-war";
  60. private static final String OTHER_WEB_APP_CONTEXT = "other-war";
  61. @ContainerResource
  62. private ManagementClient managementClient;
  63. @Deployment(name = "ear-with-single-war", testable = false)
  64. public static EnterpriseArchive createEar() {
  65. final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar");
  66. ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class);
  67. final WebArchive war = ShrinkWrap.create(WebArchive.class, WEB_APP_CONTEXT_ONE + ".war");
  68. war.addClasses(HelloWorldServlet.class, EjbInvokingServlet.class);
  69. // TODO: Currently, due to an issue in AS7 integration with Arquillian, the web-app context and the
  70. // .ear name should be the same or else you run into test deployment failures like:
  71. // Caused by: java.lang.IllegalStateException: Error launching test at
  72. // http://127.0.0.1:8080/<earname>/ArquillianServletRunner?outputMode=serializedObject&className=org.jboss.as.test.spec.ear.classpath.unit.SubDeploymentAvailableInClassPathTestCase&methodName=testEjbClassAvailableInServlet. Kept on getting 404s.
  73. // @see https://issues.jboss.org/browse/AS7-367
  74. final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, WEB_APP_CONTEXT_ONE + ".ear");
  75. ear.addAsModule(ejbJar);
  76. ear.addAsModule(war);
  77. logger.info(ear.toString(true));
  78. return ear;
  79. }
  80. @Deployment(name = "ear-with-multiple-wars", testable = false)
  81. public static EnterpriseArchive createEarWithMultipleWars() {
  82. final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar");
  83. ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class);
  84. final WebArchive war = ShrinkWrap.create(WebArchive.class, WEB_APP_CONTEXT_TWO + ".war");
  85. war.addClasses(HelloWorldServlet.class, EjbInvokingServlet.class);
  86. final WebArchive otherWar = ShrinkWrap.create(WebArchive.class, OTHER_WEB_APP_CONTEXT + ".war");
  87. otherWar.addClass(ServletInOtherWar.class);
  88. // TODO: Currently, due to an issue in AS7 integration with Arquillian, the web-app context and the
  89. // .ear name should be the same or else you run into test deployment failures like:
  90. // Caused by: java.lang.IllegalStateException: Error launching test at
  91. // http://127.0.0.1:8080/<earname>/ArquillianServletRunner?outputMode=serializedObject&className=org.jboss.as.test.spec.ear.classpath.unit.SubDeploymentAvailableInClassPathTestCase&methodName=testEjbClassAvailableInServlet. Kept on getting 404s.
  92. // @see https://issues.jboss.org/browse/AS7-367
  93. final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, WEB_APP_CONTEXT_TWO + ".ear");
  94. ear.addAsModule(ejbJar);
  95. ear.addAsModule(war);
  96. ear.addAsModule(otherWar);
  97. logger.info(ear.toString(true));
  98. return ear;
  99. }
  100. /**
  101. * Tests that for a .ear like this one:
  102. * myapp.ear
  103. * |
  104. * |--- web.war
  105. * |
  106. * |--- ejb.jar
  107. * <p/>
  108. * the classes within the web.war have access to the classes in the ejb.jar
  109. *
  110. * @throws Exception
  111. */
  112. @Test
  113. @OperateOnDeployment("ear-with-single-war")
  114. public void testEjbClassAvailableInServlet() throws Exception {
  115. final HttpClient httpClient = new DefaultHttpClient();
  116. final String message = "JBossAS7";
  117. final String requestURL = managementClient.getWebUri() + "/" + WEB_APP_CONTEXT_ONE + HelloWorldServlet.URL_PATTERN + "?" + HelloWorldServlet.PARAMETER_NAME + "=" + message;
  118. final HttpGet request = new HttpGet(requestURL);
  119. final HttpResponse response = httpClient.execute(request);
  120. final HttpEntity entity = response.getEntity();
  121. Assert.assertNotNull("Response message from servlet was null", entity);
  122. final String responseMessage = EntityUtils.toString(entity);
  123. Assert.assertEquals("Unexpected echo message from servlet", message, responseMessage);
  124. }
  125. /**
  126. * Tests that for a .ear like this one:
  127. * myapp.ear
  128. * |
  129. * |--- web.war
  130. * |
  131. * |--- ejb.jar
  132. * <p/>
  133. * <p/>
  134. * the classes within the ejb.jar *don't* have access to the classes in the web.war
  135. *
  136. * @throws Exception
  137. */
  138. @Test
  139. @OperateOnDeployment("ear-with-single-war")
  140. public void testServletClassNotAvailableToEjbInEar() throws Exception {
  141. final HttpClient httpClient = new DefaultHttpClient();
  142. final String classInWar = HelloWorldServlet.class.getName();
  143. final String requestURL = managementClient.getWebUri() + "/" + WEB_APP_CONTEXT_ONE + EjbInvokingServlet.URL_PATTERN + "?" + EjbInvokingServlet.CLASS_IN_WAR_PARAMETER + "=" + classInWar;
  144. final HttpGet request = new HttpGet(requestURL);
  145. final HttpResponse response = httpClient.execute(request);
  146. final HttpEntity entity = response.getEntity();
  147. Assert.assertNotNull("Response message from servlet was null", entity);
  148. final String responseMessage = EntityUtils.toString(entity);
  149. Assert.assertEquals("Unexpected echo message from servlet", EjbInvokingServlet.SUCCESS_MESSAGE, responseMessage);
  150. }
  151. /**
  152. * Tests that for a .ear like this one:
  153. * myapp.ear
  154. * |
  155. * |--- web-one.war
  156. * |
  157. * |--- web-two.war
  158. * <p/>
  159. * <p/>
  160. * the classes within the web-one.war *don't* have access to the classes in the web-two.war
  161. *
  162. * @throws Exception
  163. */
  164. @Test
  165. @OperateOnDeployment("ear-with-multiple-wars")
  166. public void testWarsDontSeeEachOtherInEar() throws Exception {
  167. final HttpClient httpClient = new DefaultHttpClient();
  168. final String classInOtherWar = HelloWorldServlet.class.getName();
  169. final String requestURL = managementClient.getWebUri() + "/" + OTHER_WEB_APP_CONTEXT + ServletInOtherWar.URL_PATTERN +
  170. "?" + ServletInOtherWar.CLASS_IN_OTHER_WAR_PARAMETER + "=" + classInOtherWar;
  171. final HttpGet request = new HttpGet(requestURL);
  172. final HttpResponse response = httpClient.execute(request);
  173. final HttpEntity entity = response.getEntity();
  174. Assert.assertNotNull("Response message from servlet was null", entity);
  175. final String responseMessage = EntityUtils.toString(entity);
  176. Assert.assertEquals("Unexpected echo message from servlet", ServletInOtherWar.SUCCESS_MESSAGE, responseMessage);
  177. }
  178. }