PageRenderTime 20ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/smcgowan/wildfly
Java | 200 lines | 100 code | 25 blank | 75 comment | 0 complexity | a71f8620327519343a4e564097276580 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.test.integration.deployment.classloading.ear.subdeployments.ejb.EJBBusinessInterface;
  34. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.SimpleSLSB;
  35. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.EjbInvokingServlet;
  36. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.HelloWorldServlet;
  37. import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.ServletInOtherWar;
  38. import org.jboss.logging.Logger;
  39. import org.jboss.shrinkwrap.api.ShrinkWrap;
  40. import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
  41. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  42. import org.jboss.shrinkwrap.api.spec.WebArchive;
  43. import org.junit.Assert;
  44. import org.junit.Test;
  45. import org.junit.runner.RunWith;
  46. /**
  47. * Tests various scenarios for class access between subdeployments within a .ear.
  48. *
  49. * @see https://issues.jboss.org/browse/AS7-306
  50. * User: Jaikiran Pai
  51. */
  52. @RunWith(Arquillian.class)
  53. @RunAsClient
  54. public class SubDeploymentAvailableInClassPathTestCase {
  55. private static final Logger logger = Logger.getLogger(SubDeploymentAvailableInClassPathTestCase.class);
  56. private static final String BASE_URL = "http://localhost:8080/";
  57. private static final String WEB_APP_CONTEXT_ONE = "war-access-to-ejb";
  58. private static final String WEB_APP_CONTEXT_TWO = "war-access-to-war";
  59. private static final String OTHER_WEB_APP_CONTEXT = "other-war";
  60. @Deployment(name = "ear-with-single-war", testable = false)
  61. public static EnterpriseArchive createEar() {
  62. final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar");
  63. ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class);
  64. final WebArchive war = ShrinkWrap.create(WebArchive.class, WEB_APP_CONTEXT_ONE + ".war");
  65. war.addClasses(HelloWorldServlet.class, EjbInvokingServlet.class);
  66. // TODO: Currently, due to an issue in AS7 integration with Arquillian, the web-app context and the
  67. // .ear name should be the same or else you run into test deployment failures like:
  68. // Caused by: java.lang.IllegalStateException: Error launching test at
  69. // 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.
  70. // @see https://issues.jboss.org/browse/AS7-367
  71. final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, WEB_APP_CONTEXT_ONE + ".ear");
  72. ear.addAsModule(ejbJar);
  73. ear.addAsModule(war);
  74. logger.info(ear.toString(true));
  75. return ear;
  76. }
  77. @Deployment(name = "ear-with-multiple-wars", testable = false)
  78. public static EnterpriseArchive createEarWithMultipleWars() {
  79. final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar");
  80. ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class);
  81. final WebArchive war = ShrinkWrap.create(WebArchive.class, WEB_APP_CONTEXT_TWO + ".war");
  82. war.addClasses(HelloWorldServlet.class, EjbInvokingServlet.class);
  83. final WebArchive otherWar = ShrinkWrap.create(WebArchive.class, OTHER_WEB_APP_CONTEXT + ".war");
  84. otherWar.addClass(ServletInOtherWar.class);
  85. // TODO: Currently, due to an issue in AS7 integration with Arquillian, the web-app context and the
  86. // .ear name should be the same or else you run into test deployment failures like:
  87. // Caused by: java.lang.IllegalStateException: Error launching test at
  88. // 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.
  89. // @see https://issues.jboss.org/browse/AS7-367
  90. final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, WEB_APP_CONTEXT_TWO + ".ear");
  91. ear.addAsModule(ejbJar);
  92. ear.addAsModule(war);
  93. ear.addAsModule(otherWar);
  94. logger.info(ear.toString(true));
  95. return ear;
  96. }
  97. /**
  98. * Tests that for a .ear like this one:
  99. * myapp.ear
  100. * |
  101. * |--- web.war
  102. * |
  103. * |--- ejb.jar
  104. * <p/>
  105. * the classes within the web.war have access to the classes in the ejb.jar
  106. *
  107. * @throws Exception
  108. */
  109. @Test
  110. @OperateOnDeployment("ear-with-single-war")
  111. public void testEjbClassAvailableInServlet() throws Exception {
  112. final HttpClient httpClient = new DefaultHttpClient();
  113. final String message = "JBossAS7";
  114. final String requestURL = BASE_URL + WEB_APP_CONTEXT_ONE + HelloWorldServlet.URL_PATTERN + "?" + HelloWorldServlet.PARAMETER_NAME + "=" + message;
  115. final HttpGet request = new HttpGet(requestURL);
  116. final HttpResponse response = httpClient.execute(request);
  117. final HttpEntity entity = response.getEntity();
  118. Assert.assertNotNull("Response message from servlet was null", entity);
  119. final String responseMessage = EntityUtils.toString(entity);
  120. Assert.assertEquals("Unexpected echo message from servlet", message, responseMessage);
  121. }
  122. /**
  123. * Tests that for a .ear like this one:
  124. * myapp.ear
  125. * |
  126. * |--- web.war
  127. * |
  128. * |--- ejb.jar
  129. * <p/>
  130. * <p/>
  131. * the classes within the ejb.jar *don't* have access to the classes in the web.war
  132. *
  133. * @throws Exception
  134. */
  135. @Test
  136. @OperateOnDeployment("ear-with-single-war")
  137. public void testServletClassNotAvailableToEjbInEar() throws Exception {
  138. final HttpClient httpClient = new DefaultHttpClient();
  139. final String classInWar = HelloWorldServlet.class.getName();
  140. final String requestURL = BASE_URL + WEB_APP_CONTEXT_ONE + EjbInvokingServlet.URL_PATTERN + "?" + EjbInvokingServlet.CLASS_IN_WAR_PARAMETER + "=" + classInWar;
  141. final HttpGet request = new HttpGet(requestURL);
  142. final HttpResponse response = httpClient.execute(request);
  143. final HttpEntity entity = response.getEntity();
  144. Assert.assertNotNull("Response message from servlet was null", entity);
  145. final String responseMessage = EntityUtils.toString(entity);
  146. Assert.assertEquals("Unexpected echo message from servlet", EjbInvokingServlet.SUCCESS_MESSAGE, responseMessage);
  147. }
  148. /**
  149. * Tests that for a .ear like this one:
  150. * myapp.ear
  151. * |
  152. * |--- web-one.war
  153. * |
  154. * |--- web-two.war
  155. * <p/>
  156. * <p/>
  157. * the classes within the web-one.war *don't* have access to the classes in the web-two.war
  158. *
  159. * @throws Exception
  160. */
  161. @Test
  162. @OperateOnDeployment("ear-with-multiple-wars")
  163. public void testWarsDontSeeEachOtherInEar() throws Exception {
  164. final HttpClient httpClient = new DefaultHttpClient();
  165. final String classInOtherWar = HelloWorldServlet.class.getName();
  166. final String requestURL = BASE_URL + OTHER_WEB_APP_CONTEXT + ServletInOtherWar.URL_PATTERN +
  167. "?" + ServletInOtherWar.CLASS_IN_OTHER_WAR_PARAMETER + "=" + classInOtherWar;
  168. final HttpGet request = new HttpGet(requestURL);
  169. final HttpResponse response = httpClient.execute(request);
  170. final HttpEntity entity = response.getEntity();
  171. Assert.assertNotNull("Response message from servlet was null", entity);
  172. final String responseMessage = EntityUtils.toString(entity);
  173. Assert.assertEquals("Unexpected echo message from servlet", ServletInOtherWar.SUCCESS_MESSAGE, responseMessage);
  174. }
  175. }