[jboss-cvs] JBossAS SVN: r99779 - in projects/reloaded/trunk/vdf-bootstrap-minimal/src: main/java/org and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 21 16:18:32 EST 2010


Author: ALRubinger
Date: 2010-01-21 16:18:31 -0500 (Thu, 21 Jan 2010)
New Revision: 99779

Added:
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedDescriptors.java
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerTestBase.java
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java
Removed:
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/Descriptors.java
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java
   projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java
Log:
[RELOADED-10] Make a better user view

Deleted: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/Descriptors.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/Descriptors.java	2010-01-21 21:09:32 UTC (rev 99778)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/Descriptors.java	2010-01-21 21:18:31 UTC (rev 99779)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
-  *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-import org.jboss.deployers.client.spi.main.MainDeployer;
-
-/**
- * Contains contracted names of the {@link ClassLoader}
- * resources which are Microcontainer descriptors 
- * containing the components needed to boot the Virtual
- * Deployment Framework
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- */
-public interface Descriptors
-{
-   /**
-    * Name of the resource containing a Microcontainer
-    * deployment descriptor capable of launching VDF elements
-    * required for {@link MainDeployer} support
-    */
-   String RESOURCE_NAME_VDF = "org.jboss.reloaded_vdf.xml";
-
-   /**
-    * Name of the resource containing a Microcontainer
-    * deployment descriptor capable of launching VFS-based
-    * ClassLoading
-    */
-   String RESOURCE_NAME_CLASSLOADING = "org.jboss.reloaded_classloading.xml";
-}

Copied: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedDescriptors.java (from rev 99777, projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/Descriptors.java)
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedDescriptors.java	                        (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedDescriptors.java	2010-01-21 21:18:31 UTC (rev 99779)
@@ -0,0 +1,138 @@
+package org.jboss.reloaded.api;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
+import org.jboss.bootstrap.api.descriptor.ClassLoaderResourceBootstrapDescriptor;
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+
+/**
+ * Contains convenience methods for obtaining {@link BootstrapDescriptor}s 
+ * used in constructing a runtime equipped with the
+ * Virtual Deployment Framework from a plain {@link MCServer}.  Typical
+ * usage is:
+ * 
+ * <code>// Create a server
+ * final MCServer mcServer = MCServerFactory.createServer();
+ * 
+ * // Add the required bootstrap descriptors
+ * final List<BootstrapDescriptor> descriptors = mcServer.getConfiguration().getBootstrapDescriptors();
+ * descriptors.add(ReloadedDescriptors.getClassLoadingDescriptor());
+ * descriptors.add(ReloadedDescriptors.getVdfDescriptor());
+ * 
+ * // Start
+ * mcServer.start();</code>
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ */
+public final class ReloadedDescriptors
+{
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Name of the resource containing a Microcontainer
+    * deployment descriptor capable of launching VDF elements
+    * required for {@link MainDeployer} support
+    */
+   private static String RESOURCE_NAME_VDF = "org.jboss.reloaded_vdf.xml";
+
+   /**
+    * Name of the resource containing a Microcontainer
+    * deployment descriptor capable of launching VFS-based
+    * ClassLoading
+    */
+   public static String RESOURCE_NAME_CLASSLOADING = "org.jboss.reloaded_classloading.xml";
+
+   //-------------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Obtains a {@link BootstrapDescriptor} containing components necessary 
+    * for starting the Virtual Deployment Framework and {@link MainDeployer}.
+    * The descriptor will be found as a {@link ClassLoader} resource
+    * of name {@link ReloadedDescriptors#RESOURCE_NAME_VDF} from the Thread
+    * Context ClassLoader
+    * @return
+    */
+   public static BootstrapDescriptor getVdfDescriptor()
+   {
+      // Return
+      return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_VDF);
+   }
+
+   /**
+    * Obtains a {@link BootstrapDescriptor} containing components necessary 
+    * for starting the Virtual Deployment Framework and {@link MainDeployer}.
+    * The descriptor will be found as a {@link ClassLoader} resource
+    * of name {@link ReloadedDescriptors#RESOURCE_NAME_VDF} from the specified
+    * @return
+    * @param cl {@link ClassLoader} used to obtain the resource
+    * @throws IllegalArgumentException If the {@link ClassLoader} is not specified
+    */
+   public static BootstrapDescriptor getVdfDescriptor(final ClassLoader cl)
+   {
+      // Precondition check
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader must be specified");
+      }
+
+      // Return
+      return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_VDF, cl);
+   }
+
+   /**
+    * Obtains a {@link BootstrapDescriptor} containing components necessary 
+    * for starting VFS-based ClassLoading Services
+    * @return
+    */
+   public static BootstrapDescriptor getClassLoadingDescriptor()
+   {
+      // Return
+      return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_CLASSLOADING);
+   }
+
+   /**
+    * Obtains a {@link BootstrapDescriptor} containing components necessary 
+    * for starting VFS-based ClassLoading Services.
+    * The descriptor will be found as a {@link ClassLoader} resource
+    * of name {@link ReloadedDescriptors#RESOURCE_NAME_CLASSLOADING} from the specified
+    * @return
+    * @param cl {@link ClassLoader} used to obtain the resource
+    * @throws IllegalArgumentException If the {@link ClassLoader} is not specified
+    */
+   public static BootstrapDescriptor getClassLoadingDescriptor(final ClassLoader cl)
+   {
+      // Precondition check
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader must be specified");
+      }
+
+      // Return
+      return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_CLASSLOADING, cl);
+   }
+
+}

Deleted: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java	2010-01-21 21:09:32 UTC (rev 99778)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java	2010-01-21 21:18:31 UTC (rev 99779)
@@ -1,153 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.Deployer;
-import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.kernel.Kernel;
-import org.jboss.logging.Logger;
-import org.jboss.shrinkwrap.api.Archives;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-import org.junit.Test;
-
-/**
- * Base support for tests of MainDeployer and VDF
- * in a minimal setup which ensures that we can bring up MC and the
- * Virtual Deployers Framework
- * in an isolated context, supporting installation of new {@link Deployer}
- * instances into the chain which will be used to process incoming {@link Deployment}s
- * made into the {@link MainDeployer}.
- * 
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public abstract class MainDeployerTestBase
-{
-
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   private static final Logger log = Logger.getLogger(MainDeployerTestBase.class);
-
-   /**
-    * Name of the archive we'll deploy
-    */
-   private static final String NAME_ARCHIVE = "testDeployment.jar";
-
-   /**
-    * Extension to give to TMP files
-    */
-   private static final String EXTENSION_TMP = ".tmp";
-
-   /**
-    * MC bean name of the {@link MainDeployer}
-    */
-   protected static final String NAME_MC_MAIN_DEPLOYER = "MainDeployer";
-
-   //-------------------------------------------------------------------------------------||
-   // Tests ------------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Ensures that VDF is brought up by:
-    * 1) Installing a new Deployer
-    * 2) Processing a deployment via MainDeployer
-    * 3) Ensuring the new Deployer processes the incoming DeploymentUnit
-    */
-   @Test
-   public void testVdfBoot() throws Throwable
-   {
-
-      // Get the MainDeployer
-      MainDeployer mainDeployer = (MainDeployer) getKernel().getController().getInstalledContext(NAME_MC_MAIN_DEPLOYER)
-            .getTarget();
-      TestCase.assertNotNull(MainDeployer.class.getName() + " instance was not installed into MC", mainDeployer);
-
-      // Install a caching deployer which will remember the last deployment
-      final CachingDeployer deployer = new CachingDeployer();
-      final String deployerName = deployer.getClass().getSimpleName();
-      final BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(deployerName, deployer.getClass().getName());
-      getKernel().getController().install(bmdb.getBeanMetaData(), deployer);
-
-      // Construct a test JAR
-      final JavaArchive cachingDeployerJar = Archives.create(NAME_ARCHIVE, JavaArchive.class);
-
-      // Flush out to a real File
-      final File tmpFile = File.createTempFile(cachingDeployerJar.getName(), EXTENSION_TMP);
-      cachingDeployerJar.as(ZipExporter.class).exportZip(tmpFile,true);
-      tmpFile.deleteOnExit();
-      
-      // Deploy the test JAR
-      final VirtualFile vFile = VFS.createNewRoot(tmpFile.toURI());
-      final VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(vFile);
-      mainDeployer.addDeployment(deployment);
-      mainDeployer.process();
-      mainDeployer.checkComplete();
-
-      // Obtain the last deployed
-      DeploymentUnit lastDeployed = deployer.lastDeployed;
-      TestCase.assertEquals(vFile.toURI().toURL().toExternalForm(), lastDeployed.getName());
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Contracts --------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Obtains the {@link Kernel} in the currently-running server
-    */
-   abstract Kernel getKernel();
-
-   //-------------------------------------------------------------------------------------||
-   // Inner Classes ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Simple {@link Deployer} to cache and make accessible the last-deployed
-    * {@link DeploymentUnit}.  Used to ensure that we can install deployers 
-    * into the chain and that they'll process new {@link Deployment}s.
-    */
-   protected static class CachingDeployer extends AbstractDeployer
-   {
-
-      /**
-       * The last unit deployed
-       */
-      DeploymentUnit lastDeployed;
-
-      public void deploy(final DeploymentUnit unit) throws DeploymentException
-      {
-         log.info("Deploying: " + unit);
-         lastDeployed = unit;
-      }
-
-   }
-}

Deleted: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java	2010-01-21 21:09:32 UTC (rev 99778)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java	2010-01-21 21:18:31 UTC (rev 99779)
@@ -1,136 +0,0 @@
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.List;
-
-import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
-import org.jboss.bootstrap.api.descriptor.ClassLoaderResourceBootstrapDescriptor;
-import org.jboss.bootstrap.api.lifecycle.LifecycleState;
-import org.jboss.bootstrap.api.mc.server.MCServer;
-import org.jboss.bootstrap.api.mc.server.MCServerFactory;
-import org.jboss.kernel.Kernel;
-import org.jboss.logging.Logger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-
-/**
- * Test of MainDeployer/VDF which installs necessary components
- * into by using the jboss-bootstrap API and deployment descriptors.
- * Intended to be used for comparison with direct declarative access
- * as exhibited by {@link MainDeployerDeclarativeUnitTest}
- * 
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class MainDeployerViaBootstrapUnitTest extends MainDeployerTestBase
-{
-
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Logger
-    */
-   private static final Logger log = Logger.getLogger(MainDeployerViaBootstrapUnitTest.class);
-
-   /**
-    * The Server
-    */
-   private static MCServer server;
-
-   /**
-    * Name of the system property signaling JBossXB to ignore order
-    */
-   private static final String NAME_SYSPROP_JBOSSXB_IGNORE_ORDER = "xb.builder.useUnorderedSequence";
-
-   /**
-    * Value to set for JBossXB ordering
-    */
-   private static final String VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER = "true";
-
-   //-------------------------------------------------------------------------------------||
-   // Lifecycle --------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Setup JBossXB
-    * TODO @see comments below so that this step is not necessary
-    */
-   @BeforeClass
-   public static void setupJBossXb()
-   {
-      AccessController.doPrivileged(new PrivilegedAction<Void>()
-      {
-         public Void run()
-         {
-            // Must use unordered sequence else JBossXB will explode
-            //TODO Define a proper vfs.xml which is properly ordered
-            System.setProperty(NAME_SYSPROP_JBOSSXB_IGNORE_ORDER, VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER);
-            return null;
-         }
-      });
-   }
-
-   /**
-    * Creates the server
-    */
-   @BeforeClass
-   public static void createAndConfigureServer()
-   {
-      // Create a server
-      final MCServer mcServer = MCServerFactory.createServer();
-
-      // Add the required bootstrap descriptors
-      final List<BootstrapDescriptor> descriptors = mcServer.getConfiguration().getBootstrapDescriptors();
-      descriptors.add(new ClassLoaderResourceBootstrapDescriptor(Descriptors.RESOURCE_NAME_VDF));
-      descriptors
-            .add(new ClassLoaderResourceBootstrapDescriptor(Descriptors.RESOURCE_NAME_CLASSLOADING));
-
-      log.info("Using bootstrap descriptors:" + descriptors);
-
-      // Set
-      server = mcServer;
-   }
-
-   /**
-    * Starts the server before each test
-    * @throws Exception
-    */
-   @Before
-   public void startServer() throws Exception
-   {
-      long before = System.currentTimeMillis();
-      server.start();
-      long after = System.currentTimeMillis();
-      long total = after - before;
-      log.info("Boot took: " + total + "ms");
-   }
-
-   /**
-    * Stops the server after each test
-    * @throws Exception
-    */
-   @After
-   public void stopServer() throws Exception
-   {
-      if (server != null && server.getState().equals(LifecycleState.STARTED))
-      {
-         server.stop();
-      }
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Required Implementations -----------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * {@inheritDoc}
-    * @see MainDeployerTestBase#getKernel()
-    */
-   @Override
-   Kernel getKernel()
-   {
-      return server.getKernel();
-   }
-}

Copied: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerTestBase.java (from rev 99519, projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java)
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerTestBase.java	                        (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerTestBase.java	2010-01-21 21:18:31 UTC (rev 99779)
@@ -0,0 +1,154 @@
+package org.jboss.reloaded.api;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.kernel.Kernel;
+import org.jboss.logging.Logger;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.junit.Test;
+
+/**
+ * Base support for tests of MainDeployer and VDF
+ * in a minimal setup which ensures that we can bring up MC and the
+ * Virtual Deployers Framework
+ * in an isolated context, supporting installation of new {@link Deployer}
+ * instances into the chain which will be used to process incoming {@link Deployment}s
+ * made into the {@link MainDeployer}.
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class MainDeployerTestBase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(MainDeployerTestBase.class);
+
+   /**
+    * Name of the archive we'll deploy
+    */
+   private static final String NAME_ARCHIVE = "testDeployment.jar";
+
+   /**
+    * Extension to give to TMP files
+    */
+   private static final String EXTENSION_TMP = ".tmp";
+
+   /**
+    * MC bean name of the {@link MainDeployer}
+    */
+   protected static final String NAME_MC_MAIN_DEPLOYER = "MainDeployer";
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that VDF is brought up by:
+    * 1) Installing a new Deployer
+    * 2) Processing a deployment via MainDeployer
+    * 3) Ensuring the new Deployer processes the incoming DeploymentUnit
+    */
+   @Test
+   public void testVdfBoot() throws Throwable
+   {
+
+      // Get the MainDeployer
+      MainDeployer mainDeployer = (MainDeployer) getKernel().getController().getInstalledContext(NAME_MC_MAIN_DEPLOYER)
+            .getTarget();
+      TestCase.assertNotNull(MainDeployer.class.getName() + " instance was not installed into MC", mainDeployer);
+
+      // Install a caching deployer which will remember the last deployment
+      final CachingDeployer deployer = new CachingDeployer();
+      final String deployerName = deployer.getClass().getSimpleName();
+      final BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(deployerName, deployer.getClass().getName());
+      getKernel().getController().install(bmdb.getBeanMetaData(), deployer);
+
+      // Construct a test JAR
+      final JavaArchive cachingDeployerJar = Archives.create(NAME_ARCHIVE, JavaArchive.class).addClass(this.getClass());
+
+      // Flush out to a real File
+      final File tmpFile = File.createTempFile(cachingDeployerJar.getName(), EXTENSION_TMP);
+      cachingDeployerJar.as(ZipExporter.class).exportZip(tmpFile, true);
+      tmpFile.deleteOnExit();
+
+      // Deploy the test JAR
+      final VirtualFile vFile = VFS.createNewRoot(tmpFile.toURI());
+      final VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(vFile);
+      mainDeployer.addDeployment(deployment);
+      mainDeployer.process();
+      mainDeployer.checkComplete();
+
+      // Obtain the last deployed
+      DeploymentUnit lastDeployed = deployer.lastDeployed;
+      TestCase.assertEquals(vFile.toURI().toURL().toExternalForm(), lastDeployed.getName());
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Contracts --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the {@link Kernel} in the currently-running server
+    */
+   abstract Kernel getKernel();
+
+   //-------------------------------------------------------------------------------------||
+   // Inner Classes ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Simple {@link Deployer} to cache and make accessible the last-deployed
+    * {@link DeploymentUnit}.  Used to ensure that we can install deployers 
+    * into the chain and that they'll process new {@link Deployment}s.
+    */
+   protected static class CachingDeployer extends AbstractDeployer
+   {
+
+      /**
+       * The last unit deployed
+       */
+      DeploymentUnit lastDeployed;
+
+      public void deploy(final DeploymentUnit unit) throws DeploymentException
+      {
+         log.info("Deploying: " + unit);
+         lastDeployed = unit;
+      }
+
+   }
+}

Copied: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java (from rev 99777, projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java)
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java	                        (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java	2010-01-21 21:18:31 UTC (rev 99779)
@@ -0,0 +1,136 @@
+package org.jboss.reloaded.api;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+
+import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
+import org.jboss.bootstrap.api.lifecycle.LifecycleState;
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.bootstrap.api.mc.server.MCServerFactory;
+import org.jboss.kernel.Kernel;
+import org.jboss.logging.Logger;
+import org.jboss.reloaded.api.ReloadedDescriptors;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * Test of MainDeployer/VDF which installs necessary components
+ * into by using the jboss-bootstrap API and deployment descriptors.
+ * Intended to be used for comparison with direct declarative access
+ * as exhibited by {@link MainDeployerDeclarativeUnitTest}
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MainDeployerViaBootstrapUnitTest extends MainDeployerTestBase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(MainDeployerViaBootstrapUnitTest.class);
+
+   /**
+    * The Server
+    */
+   private static MCServer server;
+
+   /**
+    * Name of the system property signaling JBossXB to ignore order
+    */
+   private static final String NAME_SYSPROP_JBOSSXB_IGNORE_ORDER = "xb.builder.useUnorderedSequence";
+
+   /**
+    * Value to set for JBossXB ordering
+    */
+   private static final String VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER = "true";
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Setup JBossXB
+    * TODO @see comments below so that this step is not necessary
+    */
+   @BeforeClass
+   public static void setupJBossXb()
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            // Must use unordered sequence else JBossXB will explode
+            //TODO Define a proper vfs.xml which is properly ordered
+            System.setProperty(NAME_SYSPROP_JBOSSXB_IGNORE_ORDER, VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER);
+            return null;
+         }
+      });
+   }
+
+   /**
+    * Creates the server
+    */
+   @BeforeClass
+   public static void createAndConfigureServer()
+   {
+      // Create a server
+      final MCServer mcServer = MCServerFactory.createServer();
+
+      // Add the required bootstrap descriptors
+      final List<BootstrapDescriptor> descriptors = mcServer.getConfiguration().getBootstrapDescriptors();
+      descriptors.add(ReloadedDescriptors.getClassLoadingDescriptor());
+      descriptors.add(ReloadedDescriptors.getVdfDescriptor());
+
+      log.info("Using bootstrap descriptors:" + descriptors);
+
+      // Set
+      server = mcServer;
+   }
+
+   /**
+    * Starts the server before each test
+    * @throws Exception
+    */
+   @Before
+   public void startServer() throws Exception
+   {
+      long before = System.currentTimeMillis();
+      server.start();
+      long after = System.currentTimeMillis();
+      long total = after - before;
+      log.info("Boot took: " + total + "ms");
+   }
+
+   /**
+    * Stops the server after each test
+    * @throws Exception
+    */
+   @After
+   public void stopServer() throws Exception
+   {
+      if (server != null && server.getState().equals(LifecycleState.STARTED))
+      {
+         server.stop();
+      }
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see MainDeployerTestBase#getKernel()
+    */
+   @Override
+   Kernel getKernel()
+   {
+      return server.getKernel();
+   }
+}




More information about the jboss-cvs-commits mailing list