/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/packaging/multimodule/ViewClassPackagingTestCase.java

http://github.com/jbossas/jboss-as · Java · 174 lines · 73 code · 38 blank · 63 comment · 0 complexity · 1fd5de25ddd9563b47efa59097f73a50 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.ejb.packaging.multimodule;
  23. import org.jboss.arquillian.container.test.api.Deployment;
  24. import org.jboss.arquillian.junit.Arquillian;
  25. import org.jboss.logging.Logger;
  26. import org.jboss.shrinkwrap.api.ShrinkWrap;
  27. import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
  28. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  29. import org.junit.Assert;
  30. import org.junit.Test;
  31. import org.junit.runner.RunWith;
  32. import javax.naming.Context;
  33. import javax.naming.InitialContext;
  34. /**
  35. * Tests that a deployment containing EJB interfaces in a separate jar, than the bean implementation, is deployed correctly
  36. * with the correct business interface views setup for the EJB.
  37. *
  38. * @see https://issues.jboss.org/browse/AS7-1112
  39. * <p/>
  40. * User: Jaikiran Pai
  41. */
  42. @RunWith(Arquillian.class)
  43. public class ViewClassPackagingTestCase {
  44. private static final String APP_NAME = "ejb-packaging-test";
  45. private static final String MODULE_NAME = "ejb-jar";
  46. /**
  47. * java:global/ namespace
  48. */
  49. private static final String JAVA_GLOBAL_NAMESPACE_PREFIX = "java:global/";
  50. /**
  51. * java:app/ namespace
  52. */
  53. private static final String JAVA_APP_NAMESPACE_PREFIX = "java:app/";
  54. /**
  55. * java:module/ namespace
  56. */
  57. private static final String JAVA_MODULE_NAMESPACE_PREFIX = "java:module/";
  58. private static final Logger logger = Logger.getLogger(ViewClassPackagingTestCase.class);
  59. @Deployment
  60. public static EnterpriseArchive createDeployment() {
  61. final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
  62. ejbJar.addClasses(MrBean.class, LocalBeanInterfaceInEjbJar.class, RemoteBeanInterfaceInEjbJar.class, ViewClassPackagingTestCase.class);
  63. final JavaArchive beanInterfacesLibraryJar = ShrinkWrap.create(JavaArchive.class, "bean-interfaces-library.jar");
  64. beanInterfacesLibraryJar.addClasses(LocalBeanInterfaceInEarLib.class, RemoteBeanInterfaceInEarLib.class);
  65. final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
  66. ear.addAsModule(ejbJar);
  67. ear.addAsLibrary(beanInterfacesLibraryJar);
  68. logger.info(ear.toString(true));
  69. return ear;
  70. }
  71. /**
  72. * Tests that all possible local view bindings of a Stateless bean are available, when deployed through a .ear
  73. *
  74. * @throws Exception
  75. */
  76. @Test
  77. public void testBeanLocalViewBindings() throws Exception {
  78. Context ctx = new InitialContext();
  79. String ejbName = MrBean.class.getSimpleName();
  80. // global bindings
  81. // 1. local business interface
  82. LocalBeanInterfaceInEarLib localBusinessInterfaceInEarLib = (LocalBeanInterfaceInEarLib) ctx.lookup(JAVA_GLOBAL_NAMESPACE_PREFIX + APP_NAME + "/" + MODULE_NAME + "/" + ejbName + "!" + LocalBeanInterfaceInEarLib.class.getName());
  83. Assert.assertNotNull("Null object returned for local business interface lookup in java:global namespace", localBusinessInterfaceInEarLib);
  84. LocalBeanInterfaceInEjbJar localBusinessInterfaceInEjbJar = (LocalBeanInterfaceInEjbJar) ctx.lookup(JAVA_GLOBAL_NAMESPACE_PREFIX + APP_NAME + "/" + MODULE_NAME + "/" + ejbName + "!" + LocalBeanInterfaceInEjbJar.class.getName());
  85. Assert.assertNotNull("Null object returned for local business interface lookup in java:global namespace", localBusinessInterfaceInEjbJar);
  86. // 2. no-interface view
  87. MrBean noInterfaceView = (MrBean) ctx.lookup(JAVA_GLOBAL_NAMESPACE_PREFIX + APP_NAME + "/" + MODULE_NAME + "/" + ejbName + "!" + MrBean.class.getName());
  88. Assert.assertNotNull("Null object returned for no-interface view lookup in java:global namespace", noInterfaceView);
  89. // app bindings
  90. // 1. local business interface
  91. LocalBeanInterfaceInEarLib localEarLibBusinessInterfaceInAppNamespace = (LocalBeanInterfaceInEarLib) ctx.lookup(JAVA_APP_NAMESPACE_PREFIX + MODULE_NAME + "/" + ejbName + "!" + LocalBeanInterfaceInEarLib.class.getName());
  92. Assert.assertNotNull("Null object returned for local business interface lookup in java:app namespace", localEarLibBusinessInterfaceInAppNamespace);
  93. LocalBeanInterfaceInEjbJar localEjbJarBusinessInterfaceInAppNamespace = (LocalBeanInterfaceInEjbJar) ctx.lookup(JAVA_APP_NAMESPACE_PREFIX + MODULE_NAME + "/" + ejbName + "!" + LocalBeanInterfaceInEjbJar.class.getName());
  94. Assert.assertNotNull("Null object returned for local business interface lookup in java:app namespace", localEjbJarBusinessInterfaceInAppNamespace);
  95. // 2. no-interface view
  96. MrBean noInterfaceViewInAppNamespace = (MrBean) ctx.lookup(JAVA_APP_NAMESPACE_PREFIX + MODULE_NAME + "/" + ejbName + "!" + MrBean.class.getName());
  97. Assert.assertNotNull("Null object returned for no-interface view lookup in java:app namespace", noInterfaceViewInAppNamespace);
  98. // module bindings
  99. // 1. local business interface
  100. LocalBeanInterfaceInEarLib localEarLibBusinessInterfaceInModuleNamespace = (LocalBeanInterfaceInEarLib) ctx.lookup(JAVA_MODULE_NAMESPACE_PREFIX + ejbName + "!" + LocalBeanInterfaceInEarLib.class.getName());
  101. Assert.assertNotNull("Null object returned for local business interface lookup in java:module namespace", localEarLibBusinessInterfaceInModuleNamespace);
  102. LocalBeanInterfaceInEjbJar localEjbJarBusinessInterfaceInModuleNamespace = (LocalBeanInterfaceInEjbJar) ctx.lookup(JAVA_MODULE_NAMESPACE_PREFIX + ejbName + "!" + LocalBeanInterfaceInEjbJar.class.getName());
  103. Assert.assertNotNull("Null object returned for local business interface lookup in java:module namespace", localEjbJarBusinessInterfaceInModuleNamespace);
  104. // 2. no-interface view
  105. MrBean noInterfaceViewInModuleNamespace = (MrBean) ctx.lookup(JAVA_MODULE_NAMESPACE_PREFIX + ejbName + "!" + MrBean.class.getName());
  106. Assert.assertNotNull("Null object returned for no-interface view lookup in java:module namespace", noInterfaceViewInModuleNamespace);
  107. }
  108. /**
  109. * Tests that all possible remote view bindings of a Stateless bean are available, when deployed through a .ear
  110. *
  111. * @throws Exception
  112. */
  113. @Test
  114. public void testRemoteBindingsOnSLSB() throws Exception {
  115. Context ctx = new InitialContext();
  116. String ejbName = MrBean.class.getSimpleName();
  117. // global bindings
  118. // 1. remote business interface
  119. RemoteBeanInterfaceInEarLib remoteBusinessInterfaceInEarLib = (RemoteBeanInterfaceInEarLib) ctx.lookup(JAVA_GLOBAL_NAMESPACE_PREFIX + APP_NAME + "/" + MODULE_NAME + "/" + ejbName + "!" + RemoteBeanInterfaceInEarLib.class.getName());
  120. Assert.assertNotNull("Null object returned for remote business interface lookup in java:global namespace", remoteBusinessInterfaceInEarLib);
  121. RemoteBeanInterfaceInEjbJar remoteBusinessInterfaceInEjbJar = (RemoteBeanInterfaceInEjbJar) ctx.lookup(JAVA_GLOBAL_NAMESPACE_PREFIX + APP_NAME + "/" + MODULE_NAME + "/" + ejbName + "!" + RemoteBeanInterfaceInEjbJar.class.getName());
  122. Assert.assertNotNull("Null object returned for remote business interface lookup in java:global namespace", remoteBusinessInterfaceInEjbJar);
  123. // app bindings
  124. // 1. remote business interface
  125. RemoteBeanInterfaceInEarLib remoteEarLibBusinessInterfaceInAppNamespace = (RemoteBeanInterfaceInEarLib) ctx.lookup(JAVA_APP_NAMESPACE_PREFIX + MODULE_NAME + "/" + ejbName + "!" + RemoteBeanInterfaceInEarLib.class.getName());
  126. Assert.assertNotNull("Null object returned for remote business interface lookup in java:app namespace", remoteEarLibBusinessInterfaceInAppNamespace);
  127. RemoteBeanInterfaceInEjbJar remoteEjbJarBusinessInterfaceInAppNamespace = (RemoteBeanInterfaceInEjbJar) ctx.lookup(JAVA_APP_NAMESPACE_PREFIX + MODULE_NAME + "/" + ejbName + "!" + RemoteBeanInterfaceInEjbJar.class.getName());
  128. Assert.assertNotNull("Null object returned for remote business interface lookup in java:app namespace", remoteEjbJarBusinessInterfaceInAppNamespace);
  129. // module bindings
  130. // 1. remote business interface
  131. RemoteBeanInterfaceInEarLib remoteEarLibBusinessInterfaceInModuleNamespace = (RemoteBeanInterfaceInEarLib) ctx.lookup(JAVA_MODULE_NAMESPACE_PREFIX + ejbName + "!" + RemoteBeanInterfaceInEarLib.class.getName());
  132. Assert.assertNotNull("Null object returned for remote business interface lookup in java:module namespace", remoteEarLibBusinessInterfaceInModuleNamespace);
  133. RemoteBeanInterfaceInEjbJar remoteEjbJarBusinessInterfaceInModuleNamespace = (RemoteBeanInterfaceInEjbJar) ctx.lookup(JAVA_MODULE_NAMESPACE_PREFIX + ejbName + "!" + RemoteBeanInterfaceInEjbJar.class.getName());
  134. Assert.assertNotNull("Null object returned for remote business interface lookup in java:module namespace", remoteEjbJarBusinessInterfaceInModuleNamespace);
  135. }
  136. }