PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/osgi/ejb3/StatelessBeanIntegrationTestCase.java

#
Java | 123 lines | 83 code | 13 blank | 27 comment | 0 complexity | 5c923d8abee7a638cd0e0b3b6348b4ce MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2010, 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.osgi.ejb3;
  23. import static org.junit.Assert.assertEquals;
  24. import static org.junit.Assert.assertNotNull;
  25. import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
  26. import java.io.InputStream;
  27. import javax.inject.Inject;
  28. import javax.naming.InitialContext;
  29. import org.jboss.arquillian.container.test.api.Deployer;
  30. import org.jboss.arquillian.container.test.api.Deployment;
  31. import org.jboss.arquillian.junit.Arquillian;
  32. import org.jboss.arquillian.test.api.ArquillianResource;
  33. import org.jboss.as.test.integration.osgi.xservice.api.Echo;
  34. import org.jboss.as.test.integration.osgi.xservice.bundle.TargetBundleActivator;
  35. import org.jboss.logging.Logger;
  36. import org.jboss.modules.Module;
  37. import org.jboss.osgi.spi.OSGiManifestBuilder;
  38. import org.jboss.shrinkwrap.api.ShrinkWrap;
  39. import org.jboss.shrinkwrap.api.asset.Asset;
  40. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  41. import org.junit.Test;
  42. import org.junit.runner.RunWith;
  43. import org.osgi.framework.Bundle;
  44. import org.osgi.framework.BundleActivator;
  45. import org.osgi.framework.BundleContext;
  46. import org.osgi.framework.ServiceReference;
  47. /**
  48. * Testcase for basic EJB3 / OSGi integration
  49. *
  50. * @author thomas.diesler@jboss.com
  51. * @since 13-May-2011
  52. */
  53. @RunWith(Arquillian.class)
  54. public class StatelessBeanIntegrationTestCase {
  55. static final String EJB3_DEPLOYMENT_NAME = "ejb3-osgi.jar";
  56. @Inject
  57. public Bundle bundle;
  58. @ArquillianResource
  59. public Deployer deployer;
  60. @Deployment
  61. public static JavaArchive createDeployment() {
  62. final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "ejb3-osgi-target");
  63. archive.addClasses(Echo.class, TargetBundleActivator.class);
  64. archive.setManifest(new Asset() {
  65. public InputStream openStream() {
  66. OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
  67. builder.addBundleSymbolicName(archive.getName());
  68. builder.addBundleManifestVersion(2);
  69. builder.addBundleActivator(TargetBundleActivator.class);
  70. builder.addImportPackages(BundleActivator.class, Logger.class, Module.class, InitialContext.class);
  71. return builder.openStream();
  72. }
  73. });
  74. return archive;
  75. }
  76. @Test
  77. public void testTargetBundle() throws Exception {
  78. bundle.start();
  79. BundleContext context = bundle.getBundleContext();
  80. ServiceReference sref = context.getServiceReference(Echo.class.getName());
  81. Echo service = (Echo) context.getService(sref);
  82. assertEquals("foo", service.echo("foo"));
  83. }
  84. @Test
  85. public void testStatelessBean() throws Exception {
  86. deployer.deploy(EJB3_DEPLOYMENT_NAME);
  87. try {
  88. String jndiname = "java:global/ejb3-osgi/SimpleStatelessSessionBean!org.jboss.as.test.integration.osgi.ejb3.SimpleStatelessSessionBean";
  89. Echo service = (Echo) new InitialContext().lookup(jndiname);
  90. assertNotNull("StatelessBean not null", service);
  91. assertEquals("ejb3-osgi-target", service.echo(BUNDLE_SYMBOLICNAME));
  92. assertEquals("foo", service.echo("foo"));
  93. } finally {
  94. deployer.undeploy(EJB3_DEPLOYMENT_NAME);
  95. }
  96. }
  97. @Deployment(name = EJB3_DEPLOYMENT_NAME, managed = false, testable = false)
  98. public static JavaArchive getTestArchive() {
  99. final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, EJB3_DEPLOYMENT_NAME);
  100. archive.addClass(SimpleStatelessSessionBean.class);
  101. archive.setManifest(new Asset() {
  102. public InputStream openStream() {
  103. OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
  104. builder.addManifestHeader("Dependencies", "org.osgi.core,deployment.ejb3-osgi-target:0.0.0");
  105. return builder.openStream();
  106. }
  107. });
  108. return archive;
  109. }
  110. }