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