[jboss-svn-commits] JBoss Common SVN: r4330 - arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Apr 24 21:10:38 EDT 2010
Author: aslak
Date: 2010-04-24 21:10:38 -0400 (Sat, 24 Apr 2010)
New Revision: 4330
Modified:
arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedContainer.java
arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedTestEnricher.java
Log:
ARQ-103 Changed the reloaded container to use the Context for Shared State
Modified: arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedContainer.java
===================================================================
--- arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedContainer.java 2010-04-24 20:48:13 UTC (rev 4329)
+++ arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedContainer.java 2010-04-25 01:10:38 UTC (rev 4330)
@@ -27,7 +27,6 @@
import org.jboss.arquillian.spi.DeployableContainer;
import org.jboss.arquillian.spi.DeploymentException;
import org.jboss.arquillian.spi.LifecycleException;
-import org.jboss.arquillian.spi.TestEnricher;
import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
import org.jboss.bootstrap.api.lifecycle.LifecycleState;
import org.jboss.bootstrap.api.mc.server.MCServer;
@@ -73,40 +72,17 @@
*/
private static final String VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER = "true";
- /**
- * Put the {@link MCServer} into Thread scope such that we might access it from the
- * {@link ReloadedTestEnricher}; hacky, but there's no way to create a {@link TestEnricher}
- * with construction arguments.
- *
- * @deprecated Remove when we can
- * @see http://community.jboss.org/message/537913
- */
- @Deprecated
- static final ThreadLocal<MCServer> MC_SERVER = new ThreadLocal<MCServer>();
-
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- /**
- * Microcontainer Server into which deployments will be made
- */
- private MCServer server;
-
- /**
- * Deployer capable of processing ShrinkWrap {@link Archive}s
- */
- private ShrinkWrapDeployer deployer;
-
- private JBossReloadedConfiguration configuration;
//-------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
-
public void setup(Context context, Configuration configuration)
{
- this.configuration = configuration.getContainerConfig(JBossReloadedConfiguration.class);
+ //configuration.getContainerConfig(JBossReloadedConfiguration.class);
}
public ContainerMethodExecutor deploy(Context context, final Archive<?> archive) throws DeploymentException
@@ -114,7 +90,7 @@
// Deploy
try
{
- deployer.deploy(archive);
+ context.get(ShrinkWrapDeployer.class).deploy(archive);
}
catch (org.jboss.deployers.spi.DeploymentException e)
{
@@ -141,8 +117,6 @@
// Create the Server
final MCServer server = MCServerFactory.createServer();
- this.server = server;
- MC_SERVER.set(server);
// Add the required bootstrap descriptors
final List<BootstrapDescriptor> descriptors = server.getConfiguration().getBootstrapDescriptors();
@@ -165,12 +139,14 @@
// Get the ShrinkWrapDeployer
final ShrinkWrapDeployer deployer = (ShrinkWrapDeployer) server.getKernel().getController().getInstalledContext(
NAME_MC_SHRINKWRAP_DEPLOYER).getTarget();
- this.deployer = deployer;
+ context.add(MCServer.class, server);
+ context.add(ShrinkWrapDeployer.class, deployer);
}
public void stop(Context context) throws LifecycleException
{
+ MCServer server = context.get(MCServer.class);
// If we've got a server
if (server != null && server.getState().equals(LifecycleState.STARTED))
{
@@ -188,19 +164,10 @@
public void undeploy(Context context, final Archive<?> archive) throws DeploymentException
{
- //TODO Remove this hack
- // http://community.jboss.org/thread/150796?tstart=0
- /*
- * Here we have to remove the test instance which was installed into MC during enrichment.
- * Should instead be done during a test enricher teardown (a la the opposite lifecycle event
- * in the same component).
- */
- server.getKernel().getController().uninstall(ReloadedTestEnricher.BIND_NAME_TEST);
-
// Undeploy
try
{
- deployer.undeploy(archive);
+ context.get(ShrinkWrapDeployer.class).undeploy(archive);
}
catch (org.jboss.deployers.spi.DeploymentException e)
{
Modified: arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedTestEnricher.java
===================================================================
--- arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedTestEnricher.java 2010-04-24 20:48:13 UTC (rev 4329)
+++ arquillian/trunk/containers/reloaded/src/main/java/org/jboss/arquillian/container/reloaded/ReloadedTestEnricher.java 2010-04-25 01:10:38 UTC (rev 4330)
@@ -20,6 +20,9 @@
import org.jboss.arquillian.spi.Context;
import org.jboss.arquillian.spi.TestEnricher;
+import org.jboss.arquillian.spi.event.container.BeforeUnDeploy;
+import org.jboss.arquillian.spi.event.container.ContainerEvent;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
import org.jboss.beans.info.spi.BeanAccessMode;
import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
@@ -58,7 +61,7 @@
public void enrich(final Context context, final Object testCase)
{
// Obtain the server as set from the container
- final MCServer server = ReloadedContainer.MC_SERVER.get();
+ final MCServer server = context.get(MCServer.class);
assert server != null : "MC Server was not set by the container";
// Get the Controller
@@ -70,6 +73,7 @@
try
{
controller.install(bmdb.getBeanMetaData(), testCase);
+ context.register(BeforeUnDeploy.class, new TestCaseUnInstaller());
}
catch (final Throwable e)
{
@@ -84,4 +88,18 @@
{
return new Object[method.getParameterTypes().length];
}
+
+ /**
+ * Uninstall the installed test case from the MCServer before undeploying.
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ private static class TestCaseUnInstaller implements EventHandler<ContainerEvent>
+ {
+ public void callback(Context context, ContainerEvent event) throws Exception
+ {
+ context.get(MCServer.class).getKernel().getController().uninstall(ReloadedTestEnricher.BIND_NAME_TEST);
+ }
+ }
}
More information about the jboss-svn-commits
mailing list