[jboss-cvs] JBossAS SVN: r101734 - in projects/ejb-book/trunk/chxx-interceptors: src/main/java/org/jboss/ejb3/examples/chxx/tuner and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Mar 2 13:22:58 EST 2010
Author: ALRubinger
Date: 2010-03-02 13:22:57 -0500 (Tue, 02 Mar 2010)
New Revision: 101734
Modified:
projects/ejb-book/trunk/chxx-interceptors/pom.xml
projects/ejb-book/trunk/chxx-interceptors/src/main/java/org/jboss/ejb3/examples/chxx/tuner/CachingAuditor.java
projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/CachingInterceptorUnitTestCase.java
projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/InterceptionIntegrationTest.java
Log:
[EJBBOOK-20] Refactor Interceptors examples to run in Arquillian
Modified: projects/ejb-book/trunk/chxx-interceptors/pom.xml
===================================================================
--- projects/ejb-book/trunk/chxx-interceptors/pom.xml 2010-03-02 18:12:06 UTC (rev 101733)
+++ projects/ejb-book/trunk/chxx-interceptors/pom.xml 2010-03-02 18:22:57 UTC (rev 101734)
@@ -25,9 +25,6 @@
<!-- Properties -->
<properties>
- <!-- JBOSS_HOME (We'll unpack into here -->
- <JBOSS_HOME>${project.build.directory}/jboss-${version.org.jboss.jbossas}</JBOSS_HOME>
-
<!-- Versioning -->
</properties>
@@ -38,66 +35,15 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-api</artifactId>
- <!--
- Must exclude jboss-metadata to prevent class leaking onto the
- appCL which breaks booting AS? In an isolated CL context this is
- not a problem EJBBOOK-12
- -->
- <exclusions>
- <exclusion>
- <groupId>jboss.jbossws</groupId>
- <artifactId>jboss-jaxrpc</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-ext-api</artifactId>
- <!-- TODO: Resolve this need for extra configuration -->
- <!--
- Must exclude jboss-metadata to prevent class leaking onto the
- appCL which breaks booting AS? In an isolated CL context this is
- not a problem EJBBOOK-12
- -->
- <exclusions>
- <exclusion>
- <groupId>org.jboss.metadata</groupId>
- <artifactId>jboss-metadata</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.javaee</groupId>
- <artifactId>jboss-ejb-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- EJBBOOK-12 Need the whole JNP Server for just client stuff?
- <dependency>
- <groupId>org.jboss.naming</groupId>
- <artifactId>jnpserver</artifactId>
- <version>5.0.4.GA</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- </exclusion>
- </exclusions>
- </dependency> -->
-
- <dependency>
<groupId>org.jboss.javaee</groupId>
<artifactId>jboss-jms-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-log4j</artifactId>
<scope>provided</scope>
@@ -113,25 +59,22 @@
Test Dependencies
-->
+ <!-- Arquillian Test Harness -->
<dependency>
- <groupId>org.jboss.embedded</groupId>
- <artifactId>jboss-embedded-api</artifactId>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-container-openejb</artifactId>
</dependency>
-
<dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-impl-base</artifactId>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
</dependency>
- <!-- TODO: Remove the dependency on the full AS depchain; it pollutes the CP. EJBBOOK-12 -->
+ <!-- JUnit -->
<dependency>
- <groupId>org.jboss.embedded</groupId>
- <artifactId>jboss-embedded-depchain</artifactId>
- <scope>test</scope>
- <version>${version.org.jboss.embedded}</version>
- <type>pom</type>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
</dependency>
-
+
</dependencies>
<profiles>
@@ -140,6 +83,9 @@
<!-- Declare the "Integration Test" Profile -->
<id>it</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
<build>
@@ -156,9 +102,6 @@
<goal>test</goal>
</goals>
<configuration>
- <additionalClasspathElements>
- <additionalClasspathElement>${JBOSS_HOME}/bin/run.jar</additionalClasspathElement>
- </additionalClasspathElements>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<trimStackTrace>false</trimStackTrace>
<printSummary>true</printSummary>
@@ -166,58 +109,11 @@
<include>**/*IntegrationTest.java</include>
</includes>
<forkMode>always</forkMode>
- <argLine>-Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed -Djboss.home=${JBOSS_HOME}</argLine>
</configuration>
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <!-- Get AS and put into "target" -->
- <execution>
- <id>unpack</id>
- <phase>pre-integration-test</phase> <!-- So run before testing -->
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.jboss.jbossas</groupId>
- <artifactId>jboss-as-distribution</artifactId>
- <version>${version.org.jboss.jbossas}</version>
- <type>zip</type>
- <overWrite>false</overWrite>
- <outputDirectory>${project.build.directory}</outputDirectory>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- <!-- Other deps, not part of AS, into "target/deps" -->
- <execution>
- <id>copy</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.jboss.embedded</groupId>
- <artifactId>jboss-embedded-core</artifactId>
- <version>${version.org.jboss.embedded}</version>
- <overWrite>false</overWrite>
- <outputDirectory>${project.build.directory}/deps</outputDirectory>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
</plugins>
</build>
Modified: projects/ejb-book/trunk/chxx-interceptors/src/main/java/org/jboss/ejb3/examples/chxx/tuner/CachingAuditor.java
===================================================================
--- projects/ejb-book/trunk/chxx-interceptors/src/main/java/org/jboss/ejb3/examples/chxx/tuner/CachingAuditor.java 2010-03-02 18:12:06 UTC (rev 101733)
+++ projects/ejb-book/trunk/chxx-interceptors/src/main/java/org/jboss/ejb3/examples/chxx/tuner/CachingAuditor.java 2010-03-02 18:22:57 UTC (rev 101734)
@@ -28,7 +28,7 @@
import java.util.logging.Logger;
import javax.annotation.Resource;
-import javax.ejb.EJBContext;
+import javax.ejb.SessionContext;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
@@ -75,7 +75,7 @@
* manually populated by unit tests
*/
@Resource
- EJBContext beanContext;
+ SessionContext beanContext;
//-------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
@@ -97,7 +97,6 @@
{
caller = beanContext.getCallerPrincipal();
}
- //TODO EJBTHREE-1996 Should not throw NPE
catch (final NullPointerException npe)
{
caller = new Principal()
Modified: projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/CachingInterceptorUnitTestCase.java
===================================================================
--- projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/CachingInterceptorUnitTestCase.java 2010-03-02 18:12:06 UTC (rev 101733)
+++ projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/CachingInterceptorUnitTestCase.java 2010-03-02 18:22:57 UTC (rev 101734)
@@ -26,12 +26,15 @@
import java.util.Properties;
import java.util.logging.Logger;
-import javax.ejb.EJBContext;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.EJBObject;
+import javax.ejb.SessionContext;
import javax.ejb.TimerService;
import javax.interceptor.InvocationContext;
import javax.transaction.UserTransaction;
+import javax.xml.rpc.handler.MessageContext;
import junit.framework.TestCase;
@@ -97,7 +100,7 @@
{
interceptor = new CachingAuditor();
// Manually set the EJBContext to a mock view which only supports returning a principal
- interceptor.beanContext = new EJBContext()
+ interceptor.beanContext = new SessionContext()
{
/**
@@ -180,6 +183,42 @@
{
throw UNSUPPORTED;
}
+
+ @Override
+ public <T> T getBusinessObject(Class<T> businessInterface) throws IllegalStateException
+ {
+ throw UNSUPPORTED;
+ }
+
+ @Override
+ public EJBLocalObject getEJBLocalObject() throws IllegalStateException
+ {
+ throw UNSUPPORTED;
+ }
+
+ @Override
+ public EJBObject getEJBObject() throws IllegalStateException
+ {
+ throw UNSUPPORTED;
+ }
+
+ @Override
+ public Class getInvokedBusinessInterface() throws IllegalStateException
+ {
+ throw UNSUPPORTED;
+ }
+
+ @Override
+ public MessageContext getMessageContext() throws IllegalStateException
+ {
+ throw UNSUPPORTED;
+ }
+
+ @Override
+ public boolean isCancelled() throws IllegalStateException
+ {
+ throw UNSUPPORTED;
+ }
};
}
Modified: projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/InterceptionIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/InterceptionIntegrationTest.java 2010-03-02 18:12:06 UTC (rev 101733)
+++ projects/ejb-book/trunk/chxx-interceptors/src/test/java/org/jboss/ejb3/examples/chxx/tuner/InterceptionIntegrationTest.java 2010-03-02 18:22:57 UTC (rev 101734)
@@ -21,40 +21,23 @@
*/
package org.jboss.ejb3.examples.chxx.tuner;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.UndeclaredThrowableException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
import java.util.logging.Logger;
+import javax.ejb.EJB;
import javax.interceptor.Interceptors;
-import javax.naming.Context;
-import javax.naming.InitialContext;
import javax.naming.NamingException;
import junit.framework.TestCase;
-import org.jboss.bootstrap.api.lifecycle.LifecycleState;
-import org.jboss.ejb3.examples.chxx.tuner.CachingAuditor;
-import org.jboss.ejb3.examples.chxx.tuner.Channel2AccessPolicy;
-import org.jboss.ejb3.examples.chxx.tuner.Channel2ClosedException;
-import org.jboss.ejb3.examples.chxx.tuner.Channel2Restrictor;
-import org.jboss.ejb3.examples.chxx.tuner.TunerBean;
-import org.jboss.ejb3.examples.chxx.tuner.TunerLocalBusiness;
-import org.jboss.embedded.api.server.JBossASEmbeddedServer;
-import org.jboss.embedded.api.server.JBossASEmbeddedServerFactory;
-import org.jboss.embedded.api.server.JBossHomeClassLoader;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* Integration test ensuring that an EJB with {@link Interceptors}
@@ -63,6 +46,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
+ at RunWith(Arquillian.class)
public class InterceptionIntegrationTest
{
@@ -75,28 +59,6 @@
*/
private static final Logger log = Logger.getLogger(InterceptionIntegrationTest.class.getName());
- /**
- * The CL of the test as originally loaded
- */
- private static ClassLoader originalClassLoader;
-
- /**
- * The server instance
- */
- private static JBossASEmbeddedServer server;
-
- /**
- * Name of the system property for JBOSS_HOME
- * @deprecated EJBBOOK-14
- */
- @Deprecated
- private static final String NAME_SYSPROP_JBOSS_HOME = "jboss.home";
-
- /**
- * The JNDI Context
- */
- private static Context NAMING_CONTEXT;
-
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -104,122 +66,22 @@
/**
* Archive representing the deployment
*/
- private JavaArchive deployment;
+ @Deployment
+ public static JavaArchive createDeployment()
+ {
+ final JavaArchive deployment = Archives.create("echo.jar", JavaArchive.class).addClasses(
+ TunerLocalBusiness.class, TunerBean.class, CachingAuditor.class, Channel2Restrictor.class);
+ log.info(deployment.toString(true));
+ return deployment;
+ }
/**
* The bean to invoke upon
*/
+ @EJB
private TunerLocalBusiness bean;
//-------------------------------------------------------------------------------------||
- // Lifecycle --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates and starts a new JBossAS Server Embedded within this JVM
- */
- //TODO EJBBOOK-15
- @BeforeClass
- public static void createAndStartJBossASAndSetNamingContext() throws Exception
- {
- // Get JBOSS_HOME
- final URL jbossHome = getJBossHome();
-
- // Get additional binaries which need CL visibility (ie. jboss-embedded-core,
- // which is placed under "target/deps" by the build). These
- // binaries are not presently available under $JBOSS_HOME
- final Set<URL> additionalUrls = new HashSet<URL>();
- final URL source = InterceptionIntegrationTest.class.getProtectionDomain().getCodeSource().getLocation();
- final URL target = new URL(source, "..");
- final URL additionalDeps = new URL(target, "deps");
- final File deps = new File(additionalDeps.toURI());
- TestCase.assertTrue("Dependencies location does not exist: " + deps, deps.exists());
- TestCase.assertTrue("Dependencies location is not a directory: " + deps, deps.isDirectory());
- for (final File child : deps.listFiles())
- {
- additionalUrls.add(child.toURI().toURL());
- log.info("Booting with: " + child);
- }
-
- // Make the new ClassLoader
- originalClassLoader = SecurityActions.getThreadContextClassLoader();
- final ClassLoader jbossHomeClassLoader = JBossHomeClassLoader.newInstance(jbossHome, additionalUrls
- .toArray(new URL[]
- {}), originalClassLoader);
-
- // Make Server
- server = JBossASEmbeddedServerFactory.createServer(jbossHomeClassLoader);
- log.info("Created: " + server);
-
- // Start
- log.info("Starting Server: " + server);
-
- // Set TCCL
- SecurityActions.setThreadContextClassLoader(jbossHomeClassLoader);
-
- // Start the Server
- server.start();
-
- // Set Naming Context
- NAMING_CONTEXT = new InitialContext();
- }
-
- /**
- * Stops the Application Server
- */
- @AfterClass
- public static void stopJBossAS() throws Exception
- {
- if (server != null && server.getState().equals(LifecycleState.STARTED))
- {
- try
- {
- server.shutdown();
- }
- finally
- {
- // Reset the TCCL
- Thread.currentThread().setContextClassLoader(originalClassLoader);
- }
- }
- }
-
- /**
- * Deploys the EJB into the server and looks up an invokable reference
- * @throws Exception
- */
- @Before
- public void deployAndGetBean() throws Exception
- {
-
- // Create the archive
- deployment = Archives.create("echo.jar", JavaArchive.class).addClasses(TunerLocalBusiness.class, TunerBean.class,
- CachingAuditor.class, Channel2Restrictor.class);
-
- // Deploy
- server.deploy(deployment);
-
- // Lookup
- bean = (TunerLocalBusiness) NAMING_CONTEXT.lookup(TunerLocalBusiness.JNDI_NAME);
- }
-
- /**
- * Undeploys the EJB from the server
- * @throws Exception
- */
- @After
- public void undeploy() throws Exception
- {
- // If we've created the running server and deployed into it
- if (deployment != null && server != null && server.getState().equals(LifecycleState.STARTED))
- {
- // Undeploy
- server.undeploy(deployment);
- }
-
- }
-
- //-------------------------------------------------------------------------------------||
// Tests ------------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -285,38 +147,4 @@
// Test
TestCase.assertEquals("Unexpected content obtained from channel " + channel, channel, stream.read());
}
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Obtains $JBOSS_HOME from the system property
- *
- * @deprecated EJBBOOK-14
- * @return
- */
- @Deprecated
- private static URL getJBossHome()
- {
- final String sysProp = NAME_SYSPROP_JBOSS_HOME;
- final String jbossHomeString = SecurityActions.getSystemProperty(sysProp);
- if (jbossHomeString == null)
- {
- throw new IllegalStateException("System property \"" + sysProp + "\" must be present in the environment");
- }
- final File jbossHomeFile = new File(jbossHomeString);
- if (!jbossHomeFile.exists())
- {
- throw new IllegalStateException("JBOSS_HOME does not exist: " + jbossHomeFile.getAbsolutePath());
- }
- try
- {
- return jbossHomeFile.toURI().toURL();
- }
- catch (final MalformedURLException murle)
- {
- throw new RuntimeException("Could not get JBOSS_HOME", murle);
- }
- }
}
More information about the jboss-cvs-commits
mailing list