[jboss-cvs] JBossAS SVN: r97922 - in projects/reloaded/trunk/vdf-bootstrap-minimal: src/test/java and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 16 23:19:03 EST 2009
Author: ALRubinger
Date: 2009-12-16 23:19:03 -0500 (Wed, 16 Dec 2009)
New Revision: 97922
Added:
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerDeclarativeUnitTest.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestCaseStandaloneHarness.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java
Removed:
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerUnitTest.java
Modified:
projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml
Log:
[RELOADED-10] Repeat the VDF/MainDeployer startup test also using straight MC API calls (skipping XML) to install necessary components. Provide a standalone entry point for use in Profilers.
Modified: projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml 2009-12-17 04:10:45 UTC (rev 97921)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml 2009-12-17 04:19:03 UTC (rev 97922)
@@ -81,6 +81,30 @@
</rules>
</configuration>
</plugin>
+
+ <!--
+ Put all dependencies into a common location. This isn't used
+ for anything in the build, but for MainDeployerTestCaseStandaloneHarness,
+ which we can use in profiling. Then set the profiler classpath to
+ include all these deps.
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/dependency</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerDeclarativeUnitTest.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerDeclarativeUnitTest.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerDeclarativeUnitTest.java 2009-12-17 04:19:03 UTC (rev 97922)
@@ -0,0 +1,239 @@
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.plugins.main.MainDeployerImpl;
+import org.jboss.deployers.plugins.managed.DefaultManagedDeploymentCreator;
+import org.jboss.deployers.spi.deployer.helpers.DefaultManagedObjectCreator;
+import org.jboss.deployers.spi.deployer.managed.ManagedDeploymentCreator;
+import org.jboss.deployers.structure.spi.StructureBuilder;
+import org.jboss.deployers.vfs.deployer.kernel.BeanDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.KernelDeploymentDeployer;
+import org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl;
+import org.jboss.deployers.vfs.plugins.structure.VFSStructureBuilder;
+import org.jboss.deployers.vfs.plugins.structure.explicit.DeclaredStructure;
+import org.jboss.deployers.vfs.plugins.structure.file.FileStructure;
+import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
+import org.jboss.deployers.vfs.spi.structure.helpers.DefaultCandidateStructureVisitorFactory;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * Test of MainDeployer/VDF which installs necessary components
+ * into MC declaratively. Used as the basis for comparison versus
+ * the {@link MainDeployerViaBootstrapUnitTest}, which uses the jboss-bootstrap API
+ * and installs required components into the kernel controller via XML descriptors
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MainDeployerDeclarativeUnitTest extends MainDeployerTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(MainDeployerDeclarativeUnitTest.class);
+
+ /**
+ * Bootstrap
+ */
+ private static AbstractBootstrap bootstrap;
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The Kernel
+ */
+ private Kernel kernel;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates the server
+ */
+ @BeforeClass
+ public static void createBootstrap() throws Exception
+ {
+ bootstrap = new BasicBootstrap();
+
+ }
+
+ /**
+ * Starts the server before each test
+ * @throws Exception
+ */
+ @Before
+ public void startServer() throws Throwable
+ {
+
+ bootstrap.run();
+ kernel = bootstrap.getKernel();
+
+ // Get controller
+ final KernelController controller = kernel.getController();
+
+ /*
+ * Now manually install stuff needed to boot VDF
+ */
+
+ // ManagedObjectFactory
+ final ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
+ final BeanMetaDataBuilder managedObjectFactoryBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "ManagedObjectFactory", managedObjectFactory.getClass().getName()).addMethodInstallCallback(
+ "addInstanceClassFactory").addMethodUninstallCallback("removeInstanceClassFactory");
+ controller.install(managedObjectFactoryBmdb.getBeanMetaData(), managedObjectFactory);
+
+ // ManagedObjectCreator
+ final DefaultManagedObjectCreator managedObjectCreator = new DefaultManagedObjectCreator();
+ managedObjectCreator.setMof(managedObjectFactory);
+ final BeanMetaDataBuilder managedObjectCreatorBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "ManagedObjectCreator", managedObjectCreator.getClass().getName());
+ controller.install(managedObjectCreatorBmdb.getBeanMetaData(), managedObjectCreator);
+
+ // Deployers
+ final DeployersImpl deployers = new DeployersImpl(controller);
+ deployers.setMgtObjectCreator(managedObjectCreator);
+ final BeanMetaDataBuilder deployersBmdb = BeanMetaDataBuilderFactory.createBuilder("Deployers",
+ deployers.getClass().getName()).addMethodInstallCallback("addDeployer").addMethodUninstallCallback(
+ "removeDeployer");
+ controller.install(deployersBmdb.getBeanMetaData(), deployers);
+
+ // StructureBuilder
+ final StructureBuilder structureBuilder = new VFSStructureBuilder();
+ final BeanMetaDataBuilder structureBuilderBmdb = BeanMetaDataBuilderFactory.createBuilder("StructureBuilder",
+ structureBuilder.getClass().getName());
+ controller.install(structureBuilderBmdb.getBeanMetaData(), structureBuilder);
+
+ // StructuralDeployers
+ final VFSStructuralDeployersImpl structuralDeployers = new VFSStructuralDeployersImpl();
+ structuralDeployers.setStructureBuilder(structureBuilder);
+ final BeanMetaDataBuilder structuralDeployersBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "StructuralDeployers", structuralDeployers.getClass().getName()).addMethodInstallCallback("addDeployer")
+ .addMethodUninstallCallback("removeDeployer");
+ controller.install(structuralDeployersBmdb.getBeanMetaData(), structuralDeployers);
+
+ // MainDeployer
+ final MainDeployerImpl mainDeployer = new MainDeployerImpl();
+ mainDeployer.setDeployers(deployers);
+ mainDeployer.setStructuralDeployers(structuralDeployers);
+ final BeanMetaDataBuilder mainDeployerBmdb = BeanMetaDataBuilderFactory.createBuilder(NAME_MC_MAIN_DEPLOYER,
+ mainDeployer.getClass().getName());
+ controller.install(mainDeployerBmdb.getBeanMetaData(), mainDeployer);
+
+ // ManagedDeploymentCreator
+ final ManagedDeploymentCreator defaultMananagedDeploymentCreator = new DefaultManagedDeploymentCreator();
+ final BeanMetaDataBuilder defaultMananagedDeploymentCreatorBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "ManagedDeploymentCreator", defaultMananagedDeploymentCreator.getClass().getName());
+ controller.install(defaultMananagedDeploymentCreatorBmdb.getBeanMetaData(), defaultMananagedDeploymentCreator);
+
+ // DeclaredStructure
+ final DeclaredStructure declaredStructure = new DeclaredStructure();
+ final BeanMetaDataBuilder declaredStructureBmdb = BeanMetaDataBuilderFactory.createBuilder("DeclaredStructure",
+ declaredStructure.getClass().getName());
+ controller.install(declaredStructureBmdb.getBeanMetaData(), declaredStructure);
+
+ // JARFilter
+ final List<String> excludes = new ArrayList<String>();
+ excludes.add(".class");
+ final SuffixesExcludeFilter jarFilter = new SuffixesExcludeFilter(excludes);
+ final BeanMetaDataBuilder jarFilterBmdb = BeanMetaDataBuilderFactory.createBuilder("JARFilter", jarFilter
+ .getClass().getName());
+ controller.install(jarFilterBmdb.getBeanMetaData(), jarFilter);
+
+ // JARStructureCandidates
+ final DefaultCandidateStructureVisitorFactory jarStructureCandidates = new DefaultCandidateStructureVisitorFactory();
+ jarStructureCandidates.setFilter(jarFilter);
+ final BeanMetaDataBuilder jarStructureCandidatesBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "JARStructureCandidates", jarStructureCandidates.getClass().getName());
+ controller.install(jarStructureCandidatesBmdb.getBeanMetaData(), jarStructureCandidates);
+
+ // JARStructure
+ final JARStructure jarStructure = new JARStructure();
+ jarStructure.setCandidateStructureVisitorFactory(jarStructureCandidates);
+ final BeanMetaDataBuilder jarStructureBmdb = BeanMetaDataBuilderFactory.createBuilder("JARStructure",
+ jarStructure.getClass().getName());
+ controller.install(jarStructureBmdb.getBeanMetaData(), jarStructure);
+
+ // FileStructure
+ final Set<String> fileStructureSuffixes = new HashSet<String>();
+ fileStructureSuffixes.add("-service.xml");
+ fileStructureSuffixes.add("-ds.xml");
+ fileStructureSuffixes.add("-beans.xml");
+ fileStructureSuffixes.add("-aop.xml");
+ final FileStructure fileStructure = new FileStructure(fileStructureSuffixes);
+ final BeanMetaDataBuilder fileStructureBmdb = BeanMetaDataBuilderFactory.createBuilder("FileStructure",
+ fileStructure.getClass().getName());
+ controller.install(fileStructureBmdb.getBeanMetaData(), fileStructure);
+
+ // BeanDeployer
+ final BeanDeployer beanDeployer = new BeanDeployer();
+ final BeanMetaDataBuilder beanDeployerBmdb = BeanMetaDataBuilderFactory.createBuilder("BeanDeployer",
+ beanDeployer.getClass().getName());
+ controller.install(beanDeployerBmdb.getBeanMetaData(), beanDeployer);
+
+ // KernelDeploymentDeployer
+ final KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
+ final BeanMetaDataBuilder kernelDeploymentDeployerBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "KernelDeploymentDeployer", kernelDeploymentDeployer.getClass().getName());
+ controller.install(kernelDeploymentDeployerBmdb.getBeanMetaData(), kernelDeploymentDeployer);
+
+ // BeanMetaDataDeployer
+ final BeanMetaDataDeployer beanMetaDataDeployer = new BeanMetaDataDeployer(controller);
+ final BeanMetaDataBuilder beanMetaDataDeployerBmdb = BeanMetaDataBuilderFactory.createBuilder(
+ "BeanMetaDataDeployer", beanMetaDataDeployer.getClass().getName()).addMethodInstallCallback(
+ "addControllerContextCreator").addMethodUninstallCallback("removeControllerContextCreator");
+ controller.install(beanMetaDataDeployerBmdb.getBeanMetaData(), beanMetaDataDeployer);
+
+ /*
+ * We haven't added ClassLoading stuff from vdf.xml
+ */
+
+ }
+
+ /**
+ * Stops the server after each test
+ * @throws Exception
+ */
+ @After
+ public void stopServer() throws Exception
+ {
+ //TODO
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see MainDeployerTestBase#getKernel()
+ */
+ @Override
+ Kernel getKernel()
+ {
+ return kernel;
+ }
+
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestBase.java 2009-12-17 04:19:03 UTC (rev 97922)
@@ -0,0 +1,181 @@
+/*
+ * 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 java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+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.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.io.IOUtil;
+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 ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * 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
+ //TODO Remove this bit when SHRINKWRAP-87 is completed, and use the built-in util
+ final File tmpFile = File.createTempFile(cachingDeployerJar.getName(), EXTENSION_TMP);
+ tmpFile.deleteOnExit();
+ final OutputStream out = new FileOutputStream(tmpFile);
+ final InputStream in = cachingDeployerJar.as(ZipExporter.class).exportZip();
+ try
+ {
+ IOUtil.copy(in, out);
+ }
+ finally
+ {
+ // Close the streams and ignore any problems doing so
+ try
+ {
+ in.close();
+ }
+ catch (IOException ignore)
+ {
+
+ }
+ try
+ {
+ out.close();
+ }
+ catch (IOException ignore)
+ {
+
+ }
+ }
+
+ // 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;
+ }
+
+ }
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestCaseStandaloneHarness.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestCaseStandaloneHarness.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerTestCaseStandaloneHarness.java 2009-12-17 04:19:03 UTC (rev 97922)
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+/**
+ * Standalone client which may act as an entry hook for Profilers.
+ * The Maven build will install all library dependencies under
+ * target/dependency for easy addition to the profiling ClassPath.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MainDeployerTestCaseStandaloneHarness
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Main -------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Entry
+ */
+ public static void main(final String... args)
+ {
+
+ try
+ {
+ new MainDeployerTestCaseStandaloneHarness();
+ }
+ catch (final Throwable t)
+ {
+ throw new RuntimeException("Could not start test", t);
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public MainDeployerTestCaseStandaloneHarness() throws Throwable
+ {
+ final MainDeployerViaBootstrapUnitTest test = new MainDeployerViaBootstrapUnitTest();
+ MainDeployerViaBootstrapUnitTest.setupJBossXb();
+ MainDeployerViaBootstrapUnitTest.createAndConfigureServer();
+ test.startServer();
+ // test.testVdfBoot();
+ test.stopServer();
+ }
+
+}
Deleted: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerUnitTest.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerUnitTest.java 2009-12-17 04:10:45 UTC (rev 97921)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerUnitTest.java 2009-12-17 04:19:03 UTC (rev 97922)
@@ -1,250 +0,0 @@
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import junit.framework.TestCase;
-
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-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.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.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.shrinkwrap.impl.base.io.IOUtil;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * 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 class MainDeployerUnitTest
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(MainDeployerUnitTest.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";
-
- /**
- * Name of the archive we'll deploy
- */
- private static final String NAME_ARCHIVE = "testDeployment.jar";
-
- /**
- * MC bean name of the {@link MainDeployer}
- */
- private static final String NAME_MC_MAIN_DEPLOYER = "MainDeployer";
-
- /**
- * Extension to give to TMP files
- */
- private static final String EXTENSION_TMP = ".tmp";
-
- //-------------------------------------------------------------------------------------||
- // 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();
- // Set the bootstrap home
- final URL bootstrapHome = getBootstrapHome();
- log.info("Using bootstrap home: " + bootstrapHome.toExternalForm());
- mcServer.getConfiguration().bootstrapHome(bootstrapHome);
- // Set
- server = mcServer;
- }
-
- /**
- * Starts the server before each test
- * @throws Exception
- */
- @Before
- public void startServer() throws Exception
- {
- server.start();
- }
-
- /**
- * Stops the server after each test
- * @throws Exception
- */
- @After
- public void stopServer() throws Exception
- {
- if (server != null && server.getState().equals(LifecycleState.STARTED))
- {
- server.stop();
- }
- }
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- @Test
- public void testVdfBoot() throws Throwable
- {
-
- // Get the MainDeployer
- MainDeployer mainDeployer = (MainDeployer) server.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());
- server.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
- //TODO Remove this bit when SHRINKWRAP-87 is completed, and use the built-in util
- final File tmpFile = File.createTempFile(cachingDeployerJar.getName(), EXTENSION_TMP);
- tmpFile.deleteOnExit();
- final OutputStream out = new FileOutputStream(tmpFile);
- final InputStream in = cachingDeployerJar.as(ZipExporter.class).exportZip();
- try
- {
- IOUtil.copy(in, out);
- }
- finally
- {
- // Close the streams and ignore any problems doing so
- try
- {
- in.close();
- }
- catch (IOException ignore)
- {
-
- }
- try
- {
- out.close();
- }
- catch (IOException ignore)
- {
-
- }
- }
-
- // 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());
- }
-
- //-------------------------------------------------------------------------------------||
- // Functional Methods -----------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * 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.
- */
- public 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;
- }
-
- }
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Obtains the location of the bootstrap home
- */
- private static URL getBootstrapHome()
- {
- return MainDeployerUnitTest.class.getProtectionDomain().getCodeSource().getLocation();
- }
-}
Copied: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java (from rev 97915, projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerUnitTest.java)
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/MainDeployerViaBootstrapUnitTest.java 2009-12-17 04:19:03 UTC (rev 97922)
@@ -0,0 +1,141 @@
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+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();
+ // Set the bootstrap home
+ final URL bootstrapHome = getBootstrapHome();
+ log.info("Using bootstrap home: " + bootstrapHome.toExternalForm());
+ mcServer.getConfiguration().bootstrapHome(bootstrapHome);
+ // 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();
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the location of the bootstrap home
+ */
+ private static URL getBootstrapHome()
+ {
+ return MainDeployerViaBootstrapUnitTest.class.getProtectionDomain().getCodeSource().getLocation();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see MainDeployerTestBase#getKernel()
+ */
+ @Override
+ Kernel getKernel()
+ {
+ return server.getKernel();
+ }
+}
More information about the jboss-cvs-commits
mailing list