[jboss-cvs] JBossAS SVN: r63682 - in projects/microcontainer/trunk: deployers-impl and 20 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 27 11:57:36 EDT 2007
Author: adrian at jboss.org
Date: 2007-06-27 11:57:36 -0400 (Wed, 27 Jun 2007)
New Revision: 63682
Added:
projects/microcontainer/trunk/deployers-impl/
projects/microcontainer/trunk/deployers-impl/.classpath
projects/microcontainer/trunk/deployers-impl/.project
projects/microcontainer/trunk/deployers-impl/pom.xml
projects/microcontainer/trunk/deployers-impl/src/
projects/microcontainer/trunk/deployers-impl/src/main/
projects/microcontainer/trunk/deployers-impl/src/main/org/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployerWrapper.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeploymentControllerContext.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
projects/microcontainer/trunk/deployers-impl/src/resources/
projects/microcontainer/trunk/deployers-impl/src/tests/
projects/microcontainer/trunk/deployers-impl/src/tests/org/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment1.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment2.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer1.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer2.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData1.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData2.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer1.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer2.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/ComponentUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerFlowUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerOrderingUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerProtocolUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerWidthFirstUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployersImplUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/MultipleComponentTypeUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/DeployersManagedTestSuite.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestFields.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
Log:
Import refactored deployers code
Added: projects/microcontainer/trunk/deployers-impl/.classpath
===================================================================
--- projects/microcontainer/trunk/deployers-impl/.classpath (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/.classpath 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main"/>
+ <classpathentry kind="src" path="src/tests"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-client-spi"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-core-spi"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-spi"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-client"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-structure-spi"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-classloader"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-dependency"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-managed"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-core/2.0.4.GA/jboss-common-core-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-core/2.0.4.GA/jboss-common-core-2.0.4.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-test/1.0.4-SNAPSHOT/jboss-test-1.0.4-SNAPSHOT.jar" sourcepath="M2_REPO/jboss/jboss-test/1.0.4-SNAPSHOT/jboss-test-1.0.4-SNAPSHOT-sources.jar"/>
+ <classpathentry kind="output" path="output/eclipse-classes"/>
+</classpath>
Added: projects/microcontainer/trunk/deployers-impl/.project
===================================================================
--- projects/microcontainer/trunk/deployers-impl/.project (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/.project 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>jboss-deployers-impl</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: projects/microcontainer/trunk/deployers-impl/pom.xml
===================================================================
--- projects/microcontainer/trunk/deployers-impl/pom.xml (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/pom.xml 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,67 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-microcontainer</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-deployers-impl</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Deployers Impl</name>
+ <url>http://www.jboss.com/products/jbossmc</url>
+ <description>JBoss Deployers Impl</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!-- Global dependencies -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-classloader</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>1.0.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-deployers-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-deployers-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.deployers.plugins.classloading;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.deployers.spi.deployer.helpers.AbstractTopLevelClassLoaderDeployer;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+
+/**
+ * AbstractTopLevelClassLoaderSystemDeployer.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractTopLevelClassLoaderSystemDeployer extends AbstractTopLevelClassLoaderDeployer
+{
+ /** The classloading */
+ private ClassLoading classLoading;
+
+ /** The classloader system */
+ private ClassLoaderSystem system;
+
+ /**
+ * Get the classLoading.
+ *
+ * @return the classLoading.
+ */
+ public ClassLoading getClassLoading()
+ {
+ return classLoading;
+ }
+
+ /**
+ * Set the classLoading.
+ *
+ * @param classLoading the classLoading.
+ */
+ public void setClassLoading(ClassLoading classLoading)
+ {
+ this.classLoading = classLoading;
+ }
+
+ /**
+ * Get the system.
+ *
+ * @return the system.
+ */
+ public ClassLoaderSystem getSystem()
+ {
+ return system;
+ }
+
+ /**
+ * Set the system.
+ *
+ * @param system the system.
+ */
+ public void setSystem(ClassLoaderSystem system)
+ {
+ this.system = system;
+ }
+
+ @Override
+ protected ClassLoader createTopLevelClassLoader(DeploymentContext context) throws Exception
+ {
+ if (classLoading == null)
+ throw new IllegalStateException("The classLoading has not been set");
+ if (system == null)
+ throw new IllegalStateException("The system has not been set");
+
+ Module module = context.getTransientAttachments().getAttachment(Module.class);
+ if (module == null)
+ throw new IllegalStateException("Deployment Context has no module: " + context);
+
+ ClassLoaderPolicy policy = createTopLevelClassLoaderPolicy(context, module);
+
+ ClassLoaderDomain domain;
+ synchronized (this)
+ {
+ String domainName = module.getDomainName();
+ domain = system.getDomain(domainName);
+ if (domain == null)
+ {
+ ClassLoaderDomain parent = null;
+ String parentDomain = module.getParentDomain();
+ if (parentDomain != null)
+ parent = system.getDomain(parentDomain);
+
+ ParentPolicy parentPolicy = module.getParentPolicy();
+
+ domain = system.createAndRegisterDomain(domainName, parentPolicy, parent);
+ }
+ }
+ return system.registerClassLoaderPolicy(domain, policy);
+ }
+
+ @Override
+ protected void removeTopLevelClassLoader(DeploymentContext context) throws Exception
+ {
+ // Remove the classloader
+ ClassLoader classLoader = context.getClassLoader();
+ system.unregisterClassLoader(classLoader);
+
+ // Reset the module to avoid possible memory leaks
+ Module module = context.getTransientAttachments().getAttachment(Module.class);
+ if (module == null)
+ throw new IllegalStateException("Deployment Context has no module: " + context);
+ module.reset();
+ }
+
+ /**
+ * Create a top level classloader policy
+ *
+ * @param context the deployment context
+ * @param module the module
+ * @return the classloader
+ * @throws Exception for any error
+ */
+ protected abstract ClassLoaderPolicy createTopLevelClassLoaderPolicy(DeploymentContext context, Module module) throws Exception;
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.deployers.plugins.classloading;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
+import org.jboss.deployers.structure.spi.classloading.ExportAll;
+
+/**
+ * ClassLoading.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoading
+{
+ /** The classloading domains by name */
+ private Map<String, Domain> domains = new ConcurrentHashMap<String, Domain>();
+
+ /**
+ * Add a deployment context
+ *
+ * @param deploymentContext the deployment context
+ * @throws IllegalArgumentException for a null deployment context
+ */
+ public void addDeploymentContext(DeploymentContext deploymentContext)
+ {
+ if (deploymentContext == null)
+ throw new IllegalArgumentException("Null deployment context");
+
+ DeploymentUnit unit = deploymentContext.getDeploymentUnit();
+ ClassLoaderMetaData metadata = unit.getAttachment(ClassLoaderMetaData.class);
+ if (metadata == null)
+ {
+ metadata = new ClassLoaderMetaData();
+ metadata.setName(deploymentContext.getName());
+ metadata.setExportAll(ExportAll.NON_EMPTY);
+ // TODO default version
+ unit.addAttachment(ClassLoaderMetaData.class, metadata);
+ }
+
+ String domainName = metadata.getDomain();
+ if (domainName == null)
+ {
+ domainName = ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+ metadata.setDomain(domainName);
+ }
+
+ Domain domain;
+ synchronized (domains)
+ {
+ domain = domains.get(domainName);
+ if (domain == null)
+ {
+ domain = new Domain(domainName);
+ domains.put(domainName, domain);
+ }
+ }
+
+ domain.addDeploymentContext(deploymentContext, metadata);
+ }
+
+ /**
+ * Remove a deployment context
+ *
+ * @param deploymentContext the deployment context
+ * @throws IllegalArgumentException for a null deployment context
+ */
+ public void removeDeploymentContext(DeploymentContext deploymentContext)
+ {
+ if (deploymentContext == null)
+ throw new IllegalArgumentException("Null deployment context");
+
+ Module module = deploymentContext.getTransientAttachments().getAttachment(Module.class);
+ if (module == null)
+ throw new IllegalStateException("Deployment Context has no module: " + deploymentContext);
+ module.release();
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.deployers.plugins.classloading;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
+
+/**
+ * Domain.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Domain
+{
+ /** The domain name */
+ private String name;
+
+ /** The registered deployment contexts */
+ private Map<DeploymentContext, Module> contexts = new ConcurrentHashMap<DeploymentContext, Module>();
+
+ /**
+ * Create a new Domain.
+ *
+ * @param name the name
+ * @throws IllegalArgumentException for a null domain
+ */
+ public Domain(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ this.name = name;
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Add a deployment context
+ *
+ * @param deploymentContext the deployment context
+ * @param metadata the classloader metadata
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public void addDeploymentContext(DeploymentContext deploymentContext, ClassLoaderMetaData metadata)
+ {
+ Module module = new Module(this, deploymentContext, metadata);
+ deploymentContext.getTransientAttachments().addAttachment(Module.class, module);
+ contexts.put(deploymentContext, module);
+ module.createDependencies();
+ }
+
+ /**
+ * Remove a deployment context
+ *
+ * @param module the module
+ * @throws IllegalArgumentException for a null parameter
+ */
+ protected void removeModule(Module module)
+ {
+ if (module == null)
+ throw new IllegalArgumentException("Null module");
+ DeploymentContext context = module.getDeploymentContext();
+ contexts.remove(context);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.deployers.plugins.classloading;
+
+import java.util.List;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
+import org.jboss.deployers.structure.spi.classloading.ExportAll;
+
+/**
+ * Module.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Module
+{
+ /** The domain */
+ private Domain domain;
+
+ /** The deployment context */
+ private DeploymentContext deploymentContext;
+
+ /** The classloader metadata */
+ private ClassLoaderMetaData metadata;
+
+ /** The delegates */
+ private List<? extends DelegateLoader> delegates;
+
+ /**
+ * Create a new Module.
+ *
+ * @param domain the domain
+ * @param deploymentContext the deployment context
+ * @param metadata the metadata
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public Module(Domain domain, DeploymentContext deploymentContext, ClassLoaderMetaData metadata)
+ {
+ if (domain == null)
+ throw new IllegalArgumentException("Null domain");
+ if (deploymentContext == null)
+ throw new IllegalArgumentException("Null context");
+ if (metadata == null)
+ throw new IllegalArgumentException("Null metadata");
+ this.domain = domain;
+ this.deploymentContext = deploymentContext;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Get the deploymentContext.
+ *
+ * @return the deploymentContext.
+ */
+ public DeploymentContext getDeploymentContext()
+ {
+ return deploymentContext;
+ }
+
+ /**
+ * Get the domain.
+ *
+ * @return the domain.
+ */
+ public Domain getDomain()
+ {
+ return domain;
+ }
+
+ /**
+ * Get the metadata.
+ *
+ * @return the metadata.
+ */
+ public ClassLoaderMetaData getMetadata()
+ {
+ return metadata;
+ }
+
+ /**
+ * Get the domain name.
+ *
+ * @return the domain name.
+ */
+ public String getDomainName()
+ {
+ return getDomain().getName();
+ }
+
+ /**
+ * Get the parentDomain.
+ *
+ * @return the parentDomain.
+ */
+ public String getParentDomain()
+ {
+ String parentDomain = getMetadata().getParentDomain();
+ if (parentDomain == null)
+ {
+ if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(getDomainName()) == false)
+ return ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+ }
+ return parentDomain;
+ }
+
+ /**
+ * Get the export all for the module
+ *
+ * @return the export all
+ */
+ public ExportAll getExportAll()
+ {
+ return getMetadata().getExportAll();
+ }
+
+ /**
+ * Get delegate policy
+ *
+ * @return the delegation policy
+ */
+ public ParentPolicy getParentPolicy()
+ {
+ if (getMetadata().isJ2seClassLoadingCompliance())
+ return ParentPolicy.BEFORE;
+ else
+ return ParentPolicy.AFTER;
+ }
+
+ /**
+ * Get the delegate loaders for this module
+ *
+ * @return the delegates
+ */
+ public List<? extends DelegateLoader> getDelegates()
+ {
+ return delegates;
+ }
+
+ /**
+ * Create the dependencies for the module
+ */
+ public void createDependencies()
+ {
+ // TODO createDependencies
+ }
+
+ /**
+ * Reset the module
+ */
+ public void reset()
+ {
+ delegates = null;
+ }
+
+ /**
+ * Release the module
+ */
+ public void release()
+ {
+ domain.removeModule(this);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployerWrapper.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployerWrapper.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployerWrapper.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,228 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.deployers.plugins.deployers;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+
+/**
+ * DeployerWrapper.<p>
+ *
+ * To avoid any problems with error handling by the deployers.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerWrapper implements Deployer, ManagedObjectCreator
+{
+ /** The log */
+ private Logger log;
+
+ /** The deployer */
+ private Deployer deployer;
+
+ /** The managed object creator */
+ private ManagedObjectCreator managedObjectCreator;
+
+ /**
+ * Create a new DeployerWrapper.
+ *
+ * @param deployer the deployer
+ */
+ public DeployerWrapper(Deployer deployer)
+ {
+ if (deployer == null)
+ throw new IllegalArgumentException("Null deployer");
+ this.deployer = deployer;
+ if (deployer instanceof ManagedObjectCreator)
+ managedObjectCreator = (ManagedObjectCreator) deployer;
+ this.log = Logger.getLogger(deployer.getClass());
+ }
+
+ /**
+ * Get the managedObjectCreator.
+ *
+ * @return the managedObjectCreator.
+ */
+ public ManagedObjectCreator getManagedObjectCreator()
+ {
+ return managedObjectCreator;
+ }
+
+ /**
+ * Set the managedObjectCreator.
+ *
+ * @param managedObjectCreator the managedObjectCreator.
+ */
+ public void setManagedObjectCreator(ManagedObjectCreator managedObjectCreator)
+ {
+ this.managedObjectCreator = managedObjectCreator;
+ }
+
+ public String getType()
+ {
+ return deployer.getType();
+ }
+
+ public int getRelativeOrder()
+ {
+ return deployer.getRelativeOrder();
+ }
+
+ public void setRelativeOrder(int order)
+ {
+ deployer.setRelativeOrder(order);
+ }
+
+ public boolean isAllInputs()
+ {
+ return deployer.isAllInputs();
+ }
+
+ public boolean isComponentsOnly()
+ {
+ return deployer.isComponentsOnly();
+ }
+
+ public boolean isWantComponents()
+ {
+ return deployer.isWantComponents();
+ }
+
+ public boolean isTopLevelOnly()
+ {
+ return deployer.isTopLevelOnly();
+ }
+
+ public Class<?> getInput()
+ {
+ return deployer.getInput();
+ }
+
+ public Class<?> getOutput()
+ {
+ return deployer.getOutput();
+ }
+
+ public Set<String> getInputs()
+ {
+ Set<String> result = deployer.getInputs();
+ if (result == null)
+ return Collections.emptySet();
+ return result;
+ }
+
+ public Set<String> getOutputs()
+ {
+ Set<String> result = deployer.getOutputs();
+ if (result == null)
+ return Collections.emptySet();
+ return result;
+ }
+
+ public DeploymentStage getStage()
+ {
+ return deployer.getStage();
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+
+ try
+ {
+ log.trace("Deploying: " + unit.getName());
+ deployer.deploy(unit);
+ log.trace("Deployed: " + unit.getName());
+ }
+ catch (Throwable t)
+ {
+ log.error("Error during deploy: " + unit.getName(), t);
+ throw DeploymentException.rethrowAsDeploymentException("Error during deploy: " + unit.getName(), t);
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+
+ try
+ {
+ log.trace("Undeploying: " + unit.getName());
+ deployer.undeploy(unit);
+ log.trace("Undeployed: " + unit.getName());
+ }
+ catch (Throwable t)
+ {
+ log.error("Error during undeploy: " + unit.getName(), t);
+ }
+ }
+
+ public void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects) throws DeploymentException
+ {
+ try
+ {
+ ManagedObjectCreator creator = getManagedObjectCreator();
+ if (creator != null)
+ creator.build(unit, managedObjects);
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error building managed objects for " + unit.getName(), t);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof Deployer == false)
+ return false;
+ if (obj instanceof DeployerWrapper)
+ obj = ((DeployerWrapper) obj).deployer;
+ return deployer.equals(obj);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return deployer.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return deployer.toString();
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,914 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.deployers.plugins.deployers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.client.spi.IncompleteDeploymentException;
+import org.jboss.deployers.client.spi.IncompleteDeployments;
+import org.jboss.deployers.client.spi.MissingDependency;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.deployers.spi.Ordered;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.deployer.Deployers;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+
+/**
+ * DeployersImpl.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployersImpl implements Deployers, ControllerContextActions
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(DeployersImpl.class);
+
+ /** The dependency state machine */
+ private AbstractController controller;
+
+ /** The deployment stages by name */
+ private Map<String, DeploymentStage> stages = new ConcurrentHashMap<String, DeploymentStage>();
+
+ /** The deployers */
+ private Set<DeployerWrapper> deployers = new HashSet<DeployerWrapper>();
+
+ /** The deployers by stage and type */
+ private Map<String, List<Deployer>> deployersByStage = new HashMap<String, List<Deployer>>();
+
+ /**
+ * Create a new DeployersImpl.
+ *
+ * @param controller the controller
+ * @throws IllegalArgumentException for a null controller
+ */
+ public DeployersImpl(AbstractController controller)
+ {
+ this(controller, null);
+ }
+
+ /**
+ * Create a new DeployersImpl.
+ *
+ * @param controller the controller
+ * @param deployers the deployers
+ * @throws IllegalArgumentException for a null controller
+ */
+ public DeployersImpl(AbstractController controller, Set<Deployer> deployers)
+ {
+ if (controller == null)
+ throw new IllegalArgumentException("Null controller");
+ this.controller = controller;
+
+ // Add the standard stages
+ addDeploymentStage(DeploymentStages.NOT_INSTALLED);
+ addDeploymentStage(DeploymentStages.PARSE);
+ addDeploymentStage(DeploymentStages.DESCRIBE);
+ addDeploymentStage(DeploymentStages.CLASSLOADER);
+ addDeploymentStage(DeploymentStages.POST_CLASSLOADER);
+ addDeploymentStage(DeploymentStages.REAL);
+ addDeploymentStage(DeploymentStages.INSTALLED);
+
+ // Create the deployers
+ if (deployers != null)
+ setDeployers(deployers);
+ }
+
+ /**
+ * Get the deployers.
+ *
+ * @return the deployers.
+ */
+ public Set<DeployerWrapper> getDeployerWrappers()
+ {
+ return deployers;
+ }
+
+ /**
+ * Set the deployers.
+ *
+ * @param deployers the deployers.
+ * @throws IllegalArgumentException for null deployers
+ */
+ public void setDeployers(Set<Deployer> deployers)
+ {
+ if (deployers == null)
+ throw new IllegalArgumentException("Null deployers");
+
+ // Remove all the old deployers that are not in the new set
+ HashSet<Deployer> oldDeployers = new HashSet<Deployer>(this.deployers);
+ oldDeployers.removeAll(deployers);
+ for (Deployer deployer : oldDeployers)
+ removeDeployer(deployer);
+
+ // Add all the new deployers that were not already present
+ HashSet<Deployer> newDeployers = new HashSet<Deployer>(deployers);
+ newDeployers.removeAll(this.deployers);
+ for (Deployer deployer : newDeployers)
+ addDeployer(deployer);
+ }
+
+ /**
+ * Add a deployer
+ *
+ * @param deployer the deployer
+ */
+ public synchronized void addDeployer(Deployer deployer)
+ {
+ if (deployer == null)
+ throw new IllegalArgumentException("Null deployer");
+
+ DeploymentStage stage = deployer.getStage();
+ if (stage == null)
+ throw new IllegalArgumentException("Deployer has no stage: " + deployer);
+
+ addDeploymentStage(stage);
+
+ DeployerWrapper wrapper = new DeployerWrapper(deployer);
+
+ // Ignore duplicates
+ if (deployers.contains(wrapper))
+ return;
+
+ String stageName = stage.getName();
+ List<Deployer> deployers = deployersByStage.get(stageName);
+ if (deployers == null)
+ deployers = Collections.emptyList();
+ deployers = sort(deployers, wrapper);
+ deployersByStage.put(stageName, deployers);
+
+ this.deployers.add(wrapper);
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("Added deployer ").append(deployer).append(" for stage ").append(stageName).append('\n');
+ for (Deployer temp : getDeployersList(stageName))
+ {
+ builder.append(temp);
+ builder.append("{inputs=").append(temp.getInputs());
+ builder.append(" outputs=").append(temp.getOutputs());
+ builder.append("}\n");
+ }
+ log.debug(builder);
+ }
+
+ /**
+ * Remove a deployer
+ *
+ * @param deployer the deployer
+ */
+ public synchronized void removeDeployer(Deployer deployer)
+ {
+ if (deployer == null)
+ throw new IllegalArgumentException("Null deployer");
+ deployers.remove(new DeployerWrapper(deployer));
+
+ DeploymentStage stage = deployer.getStage();
+ if (stage == null)
+ {
+ log.warn("Deployer has no stage: " + deployer);
+ return;
+ }
+
+ String stageName = stage.getName();
+ List<Deployer> deployers = deployersByStage.get(stageName);
+ if (deployers == null)
+ return;
+
+ deployers.remove(deployer);
+ if (deployers.isEmpty())
+ deployersByStage.remove(stageName);
+
+ log.debug("Removed deployer " + deployer + " from stage " + stageName);
+ }
+
+ /**
+ * Add a deployment stage
+ *
+ * @param stage the deployment stage
+ */
+ protected synchronized void addDeploymentStage(DeploymentStage stage)
+ {
+ if (stage == null)
+ throw new IllegalArgumentException("Null stage");
+
+ // Already done?
+ String stageName = stage.getName();
+ if (stages.containsKey(stageName))
+ return;
+
+ ControllerState preceeds = null;
+ String before = stage.getBefore();
+ String after = stage.getAfter();
+ if (before != null || after != null)
+ {
+ // Determine where to put the stage
+ List<ControllerState> states = controller.getStates();
+ for (int i = 0; i < states.size(); ++i)
+ {
+ ControllerState state = states.get(i);
+ String stateName = state.getStateString();
+ if (before != null && before.equals(stateName))
+ {
+ preceeds = state;
+ break;
+ }
+ if (after != null && after.equals(stateName))
+ {
+ if (i < states.size()-1)
+ {
+ preceeds = states.get(i+1);
+ break;
+ }
+ }
+ }
+ }
+
+ controller.addState(new ControllerState(stageName), preceeds);
+ stages.put(stageName, stage);
+ log.debug("Added stage " + stageName + " before " + preceeds);
+ }
+
+ public Map<String, ManagedObject> getManagedObjects(DeploymentContext context) throws DeploymentException
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+
+ Map<String, ManagedObject> managedObjects = new HashMap<String, ManagedObject>();
+ for (DeployerWrapper deployer : deployers)
+ deployer.build(context.getDeploymentUnit(), managedObjects);
+
+ return managedObjects;
+ }
+
+ /**
+ * Get the ManagedObjectBuilder for a deployer.
+ *
+ * @param deployer - the deployer to set the ManagedObjectBuilder for.
+ * @return managedObjectBuilder for deployer, may be null
+ * @throws IllegalArgumentException for a null deployer
+ */
+ public ManagedObjectCreator getDeployerManagedObjectBuilder(Deployer deployer)
+ {
+ if (deployer == null)
+ throw new IllegalArgumentException("Null deployer");
+
+ ManagedObjectCreator result = null;
+ for (DeployerWrapper wrapper : deployers)
+ {
+ if (wrapper.equals(deployer))
+ result = wrapper.getManagedObjectCreator();
+ }
+ return result;
+ }
+
+ /**
+ * Set the ManagedObjectBuilder for a deployer. This allows one to override the given deployer
+ * ManagedObjectBuilder or assign one when the deployer does not provide a ManagedObjectBuilder.
+ *
+ * @param deployer - the deployer to set the ManagedObjectBuilder for.
+ * @param managedObjectCreator the managed object builder to set to the deployer
+ * @throws IllegalArgumentException for a null deployer
+ */
+ public void setDeployerManagedObjectBuilder(Deployer deployer, ManagedObjectCreator managedObjectCreator)
+ {
+ if (deployer == null)
+ throw new IllegalArgumentException("Null deployer");
+
+ for (DeployerWrapper wrapper : deployers)
+ {
+ if (wrapper.equals(deployer))
+ wrapper.setManagedObjectCreator(managedObjectCreator);
+ }
+ }
+
+ public void process(List<DeploymentContext> deploy, List<DeploymentContext> undeploy)
+ {
+ // There is something to undeploy
+ if (undeploy != null && undeploy.isEmpty() == false)
+ {
+ // Build a list in reverse order
+ List<DeploymentControllerContext> toUndeploy = new ArrayList<DeploymentControllerContext>();
+ for (int i = undeploy.size()-1; i >= 0; --i)
+ {
+ DeploymentContext context = undeploy.get(i);
+ context.setState(DeploymentState.UNDEPLOYING);
+ log.debug("Undeploying " + context.getName());
+ DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(DeploymentControllerContext.class);
+ if (deploymentControllerContext == null)
+ {
+ log.warn("DeploymentContext has no DeploymentControllerContext during undeploy request, ignoring: " + context);
+ }
+ else
+ {
+ toUndeploy.add(deploymentControllerContext);
+ }
+ }
+
+ // Go through the states in reverse order
+ List<ControllerState> states = controller.getStates();
+ for (int i = states.size()-1; i >= 0; --i)
+ {
+ ControllerState state = states.get(i);
+ for (DeploymentControllerContext deploymentControllerContext : toUndeploy)
+ {
+ DeploymentContext context = deploymentControllerContext.getDeploymentContext();
+ if (ControllerState.ERROR.equals(context.getState()) == false)
+ {
+ try
+ {
+ controller.change(deploymentControllerContext, state);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during undeploy", t);
+ context.setState(DeploymentState.ERROR);
+ context.setProblem(t);
+ }
+ }
+ }
+ }
+
+ // Uninstall the contexts
+ for (DeploymentControllerContext deploymentControllerContext : toUndeploy)
+ {
+ DeploymentContext context = deploymentControllerContext.getDeploymentContext();
+ context.getTransientAttachments().removeAttachment(DeploymentControllerContext.class);
+ try
+ {
+ controller.uninstall(deploymentControllerContext.getName());
+ context.setState(DeploymentState.UNDEPLOYED);
+ // TODO perform with the deployer that created the classloader?
+ context.removeClassLoader();
+ log.debug("Fully Undeployed " + context.getName());
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during uninstall", t);
+ context.setState(DeploymentState.ERROR);
+ context.setProblem(t);
+ }
+ }
+ }
+
+ // There is something to deploy
+ if (deploy != null && deploy.isEmpty() == false)
+ {
+ // Create the controller contexts
+ for (DeploymentContext context : deploy)
+ {
+ DeploymentControllerContext deploymentControllerContext = new DeploymentControllerContext(context, this);
+ try
+ {
+ controller.install(deploymentControllerContext);
+ context.setState(DeploymentState.DEPLOYING);
+ log.debug("Deploying " + context.getName());
+ context.getTransientAttachments().addAttachment(DeploymentControllerContext.class, deploymentControllerContext);
+ }
+ catch (Throwable t)
+ {
+ context.setState(DeploymentState.ERROR);
+ context.setProblem(t);
+ }
+ }
+
+ // Go through the states in order
+ List<ControllerState> states = controller.getStates();
+ for (ControllerState state : states)
+ {
+ for (DeploymentContext context : deploy)
+ {
+ if (DeploymentState.ERROR.equals(context.getState()) == false)
+ {
+ DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(DeploymentControllerContext.class);
+ try
+ {
+ controller.change(deploymentControllerContext, state);
+ }
+ catch (Throwable t)
+ {
+ context.setState(DeploymentState.ERROR);
+ context.setProblem(t);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the root cause of a throwable
+ *
+ * @param original the original
+ * @return the root
+ */
+ private static Throwable getRootCause(Throwable original)
+ {
+ if (original == null)
+ return null;
+ Throwable result = original;
+ Throwable cause = result.getCause();
+ while (cause != null)
+ {
+ result = cause;
+ cause = cause.getCause();
+ }
+ return result;
+ }
+
+ public void checkComplete(Collection<DeploymentContext> errors, Collection<DeploymentContext> missingDeployer) throws DeploymentException
+ {
+ Map<String, Throwable> deploymentsInError = null;
+ Collection<String> deploymentsMissingDeployer = null;
+ Map<String, Throwable> contextsInError = null;
+ Map<String, Set<MissingDependency>> contextsMissingDependencies = null;
+
+ if (errors != null && errors.isEmpty() == false)
+ {
+ deploymentsInError = new HashMap<String, Throwable>();
+ for (DeploymentContext context : errors)
+ deploymentsInError.put(context.getName(), getRootCause(context.getProblem()));
+ }
+
+ if (missingDeployer != null && missingDeployer.isEmpty() == false)
+ {
+ deploymentsMissingDeployer = new HashSet<String>();
+ for (DeploymentContext context : missingDeployer)
+ deploymentsMissingDeployer.add(context.getName());
+ }
+
+
+ if (controller != null)
+ {
+ List<ControllerState> states = controller.getStates();
+
+ Set<ControllerContext> notInstalled = controller.getNotInstalled();
+ if (notInstalled.isEmpty() == false)
+ {
+ for (Iterator<ControllerContext> i = notInstalled.iterator(); i.hasNext();)
+ {
+ ControllerContext context = i.next();
+ if (context.getState().equals(context.getRequiredState()))
+ i.remove();
+ }
+ if (notInstalled.isEmpty() == false)
+ {
+ contextsInError = new HashMap<String, Throwable>();
+ contextsMissingDependencies = new HashMap<String, Set<MissingDependency>>();
+ for (ControllerContext context : notInstalled)
+ {
+ if (context.getState().equals(ControllerState.ERROR))
+ contextsInError.put(context.getName().toString(), getRootCause(context.getError()));
+ else
+ {
+ String name = context.getName().toString();
+ Set<MissingDependency> dependencies = new HashSet<MissingDependency>();
+ DependencyInfo dependsInfo = context.getDependencyInfo();
+ for (DependencyItem item : dependsInfo.getIDependOn(null))
+ {
+ if (item.isResolved() == false)
+ {
+ String dependency;
+ ControllerState actualState = null;
+ String actualStateString;
+ Object iDependOn = item.getIDependOn();
+ if (iDependOn == null)
+ {
+ dependency = "<UNKNOWN>";
+ actualStateString = "** UNRESOLVED " + item.toHumanReadableString() + " **";
+ }
+ else
+ {
+ dependency = iDependOn.toString();
+ ControllerContext other = controller.getContext(item.getIDependOn(), null);
+ if (other == null)
+ actualStateString = "** NOT FOUND **";
+ else
+ {
+ actualState = other.getState();
+ actualStateString = actualState.getStateString();
+ }
+ }
+ ControllerState requiredState = item.getWhenRequired();
+ String requiredStateString = requiredState.getStateString();
+ int required = states.indexOf(requiredState);
+ int actual = actualState == null ? -1 : states.indexOf(actualState);
+ if (required > actual)
+ {
+ MissingDependency missing = new MissingDependency(name, dependency, requiredStateString, actualStateString);
+ dependencies.add(missing);
+ }
+ }
+ }
+ contextsMissingDependencies.put(name, dependencies);
+ }
+ }
+ }
+ }
+ }
+
+ IncompleteDeployments incomplete = new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies);
+ if (incomplete.isIncomplete())
+ throw new IncompleteDeploymentException(incomplete);
+ }
+
+ public void checkComplete(DeploymentContext context) throws DeploymentException
+ {
+ Map<String, Throwable> deploymentsInError = null;
+ Collection<String> deploymentsMissingDeployer = null;
+ Map<String, Throwable> contextsInError = null;
+ Map<String, Set<MissingDependency>> contextsMissingDependencies = null;
+
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+
+ Throwable problem = context.getProblem();
+ if (problem != null)
+ deploymentsInError = Collections.singletonMap(context.getName(), problem);
+
+ if (context.isDeployed() == false)
+ deploymentsMissingDeployer.add(context.getName());
+
+ // TODO go through controller contexts for the deployment + related contexts
+
+ IncompleteDeployments incomplete = new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies);
+ if (incomplete.isIncomplete())
+ throw new IncompleteDeploymentException(incomplete);
+ }
+
+ public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+ {
+ DeploymentControllerContext deploymentControllerContext = (DeploymentControllerContext) context;
+ String stageName = toState.getStateString();
+
+ DeploymentContext deploymentContext = deploymentControllerContext.getDeploymentContext();
+ try
+ {
+ doInstall(deploymentContext, stageName, true);
+ }
+ finally
+ {
+ if (ControllerState.INSTALLED.equals(toState) && DeploymentState.DEPLOYING.equals(deploymentContext.getState()))
+ {
+ log.debug("Fully Deployed " + context.getName());
+ deploymentContext.setState(DeploymentState.DEPLOYED);
+
+ }
+ }
+ }
+
+ /**
+ * Do the install
+ *
+ * @param context the context
+ * @param stageName the stage
+ * @param doComponents whether to do components
+ * @throws Throwable for any problem
+ */
+ protected void doInstall(DeploymentContext context, String stageName, boolean doComponents) throws Throwable
+ {
+ List<Deployer> theDeployers = getDeployersList(stageName);
+
+ if (log.isTraceEnabled())
+ log.trace("Deployers for " + stageName + " " + theDeployers);
+
+ if (theDeployers.isEmpty() == false)
+ {
+ int i = 0;
+ try
+ {
+ while (i < theDeployers.size())
+ {
+ Deployer deployer = theDeployers.get(i);
+ doInstall(deployer, context, doComponents);
+ ++i;
+ }
+ }
+ catch (Throwable t)
+ {
+ context.setState(DeploymentState.ERROR);
+ context.setProblem(t);
+ for (int j = i-1; j >= 0; --j)
+ {
+ Deployer deployer = theDeployers.get(j);
+ doUninstall(deployer, context, true);
+ }
+ throw t;
+ }
+ }
+ }
+
+ /**
+ * Do the install
+ *
+ * @param deployer the deployer
+ * @param context the context
+ * @param doComponents whether to do components
+ * @throws Throwable for any problem
+ */
+ protected void doInstall(Deployer deployer, DeploymentContext context, boolean doComponents) throws Throwable
+ {
+ // Take a copy of the components so we don't start looping on newly added components
+ // in the component deployers
+ List<DeploymentContext> components = new ArrayList<DeploymentContext>(context.getComponents());
+
+ DeploymentUnit unit = context.getDeploymentUnit();
+ if (isRelevant(deployer, unit, context.isTopLevel(), context.isComponent()))
+ deployer.deploy(unit);
+ else if (log.isTraceEnabled())
+ log.trace("Deployer " + deployer + " not relevant for " + context.getName());
+
+ if (doComponents)
+ {
+ try
+ {
+ if (components != null && components.isEmpty() == false)
+ {
+ for (int i = 0; i < components.size(); ++i)
+ {
+ DeploymentContext component = components.get(i);
+ try
+ {
+ doInstall(deployer, component, true);
+ }
+ catch (DeploymentException e)
+ {
+ // Unwind the previous components
+ for (int j = i-1; j >=0; --j)
+ {
+ component = components.get(j);
+ doUninstall(deployer, component, true);
+ }
+ throw e;
+ }
+ }
+ }
+ }
+ catch (DeploymentException e)
+ {
+ doUninstall(deployer, context, false);
+ throw e;
+ }
+ }
+ }
+
+ public void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+ {
+ DeploymentControllerContext deploymentControllerContext = (DeploymentControllerContext) context;
+ String stageName = fromState.getStateString();
+
+ DeploymentContext deploymentContext = deploymentControllerContext.getDeploymentContext();
+ doUninstall(deploymentContext, stageName, true);
+ }
+
+ /**
+ * Do the uninstall
+ *
+ * @param context the context
+ * @param stageName the stage
+ * @param doComponents whether to do components
+ */
+ protected void doUninstall(DeploymentContext context, String stageName, boolean doComponents)
+ {
+ List<Deployer> theDeployers = getDeployersList(stageName);
+
+ if (log.isTraceEnabled())
+ log.trace("Deployers for " + stageName + " " + theDeployers);
+
+ if (theDeployers.isEmpty() == false)
+ {
+ for (int i = theDeployers.size()-1; i >= 0; --i)
+ {
+ Deployer deployer = theDeployers.get(i);
+ doUninstall(deployer, context, doComponents);
+ }
+ }
+ }
+
+ /**
+ * Do the uninstall
+ *
+ * @param deployer the deployer
+ * @param context the context
+ * @param doComponents whether to do components
+ */
+ protected void doUninstall(Deployer deployer, DeploymentContext context, boolean doComponents)
+ {
+ if (doComponents)
+ {
+ List<DeploymentContext> components = context.getComponents();
+ if (components != null && components.isEmpty() == false)
+ {
+ for (int i = components.size()-1; i >= 0; --i)
+ {
+ DeploymentContext component = components.get(i);
+ doUninstall(deployer, component, doComponents);
+ }
+ }
+ }
+
+ DeploymentUnit unit = context.getDeploymentUnit();
+ if (isRelevant(deployer, unit, context.isTopLevel(), context.isComponent()))
+ deployer.undeploy(unit);
+ else if (log.isTraceEnabled())
+ log.trace("Deployer " + deployer + " not relevant for " + context.getName());
+ }
+
+ /**
+ * Build a list of deployers for this stage
+ *
+ * @param stageName the stage name
+ * @return the deployers
+ */
+ protected synchronized List<Deployer> getDeployersList(String stageName)
+ {
+ List<Deployer> deployers = deployersByStage.get(stageName);
+ if (deployers == null || deployers.isEmpty())
+ return Collections.emptyList();
+
+ return deployers;
+ }
+
+ /**
+ * Test whether a deployer is relevant
+ *
+ * @param deployer deployer
+ * @param unit the deployment unit
+ * @param isTopLevel whether this is a top level deployment
+ * @param isComponent whether this is a component
+ * @return the deployers
+ */
+ protected boolean isRelevant(Deployer deployer, DeploymentUnit unit, boolean isTopLevel, boolean isComponent)
+ {
+ // Deployer only wants top level
+ if (deployer.isTopLevelOnly() && isTopLevel == false)
+ return false;
+
+ // Deployer only wants components
+ if (deployer.isComponentsOnly() && isComponent == false)
+ return false;
+
+ // Deployer doesn't wantwants components
+ if (deployer.isWantComponents() == false && isComponent)
+ return false;
+
+ if (deployer.isAllInputs() == false)
+ {
+ // No attachment for the input type
+ Class<?> input = deployer.getInput();
+ if (input != null && unit.getAttachment(input) == null)
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Sort the deployers
+ *
+ * @param original the original deployers
+ * @param newDeployer the new deployer
+ * @return the sorted deployers
+ */
+ protected List<Deployer> sort(List<Deployer> original, Deployer newDeployer)
+ {
+ List<Deployer> result = new ArrayList<Deployer>(original);
+ result.add(newDeployer);
+
+ // Bubble sort :-)
+ boolean changed = true;
+ while (changed)
+ {
+ changed = false;
+
+ for (int i = 0; i < result.size() -1; ++i)
+ {
+ int j = i+1;
+
+ Deployer one = result.get(i);
+ Deployer two = result.get(j);
+
+ Set<String> oneOutputs = one.getOutputs();
+
+ // Don't move if one outputs something for two
+ boolean swap = true;
+ if (oneOutputs.isEmpty() == false)
+ {
+ Set<String> twoInputs = two.getInputs();
+ for (String output : oneOutputs)
+ {
+ if (twoInputs.contains(output))
+ {
+ swap = false;
+ break;
+ }
+ }
+
+ if (swap == false)
+ continue;
+ }
+
+ // Move if one inputs from two
+ swap = false;
+ Set<String> twoOutputs = two.getOutputs();
+ if (twoOutputs.isEmpty() == false)
+ {
+ Set<String> oneInputs = one.getInputs();
+ for (String output : twoOutputs)
+ {
+ if (oneInputs.contains(output))
+ {
+ swap = true;
+ break;
+ }
+ }
+ }
+
+ // Move if the order is not correct
+ if (Ordered.COMPARATOR.compare(one, two) > 0)
+ swap = true;
+
+ if (swap)
+ {
+ Collections.swap(result, i, j);
+ changed = true;
+ }
+ }
+ }
+
+ // Now check the consistency
+ // The new deployer should be before anything that accepts its outputs
+ Set<String> outputs = newDeployer.getOutputs();
+ if (outputs.isEmpty() == false)
+ {
+ int location = result.indexOf(newDeployer);
+ for (int i = 0; i < location; ++i)
+ {
+ Deployer other = result.get(i);
+ Set<String> otherInputs = other.getInputs();
+ Set<String> otherOutputs = other.getOutputs();
+ if (otherInputs.isEmpty() == false)
+ {
+ for (String input : otherInputs)
+ {
+ // Ignore transient usage
+ if (outputs.contains(input) && otherOutputs.contains(input) == false)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Cannot add ").append(newDeployer).append(" it will cause a loop\n");
+ for (Deployer temp : result)
+ {
+ builder.append(temp);
+ builder.append("{inputs=").append(temp.getInputs());
+ builder.append(" outputs=").append(temp.getOutputs());
+ builder.append("}\n");
+ }
+ throw new IllegalStateException(builder.toString());
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeploymentControllerContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeploymentControllerContext.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeploymentControllerContext.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.deployers.plugins.deployers;
+
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+
+/**
+ * DeploymentControllerContext.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeploymentControllerContext extends AbstractControllerContext
+{
+ /** The deployment context */
+ private DeploymentContext deploymentContext;
+
+ /**
+ * Create a new DeploymentControllerContext.
+ *
+ * @param context the deployment context
+ * @param deployers the deployers
+ */
+ public DeploymentControllerContext(DeploymentContext context, DeployersImpl deployers)
+ {
+ super(context.getName(), deployers);
+ this.deploymentContext = context;
+ setMode(ControllerMode.MANUAL);
+ }
+
+ /**
+ * Get the deploymentContext.
+ *
+ * @return the deploymentContext.
+ */
+ public DeploymentContext getDeploymentContext()
+ {
+ return deploymentContext;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,537 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.deployers.plugins.main;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+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.DeploymentState;
+import org.jboss.deployers.spi.deployer.Deployers;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.StructuralDeployers;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.util.graph.Graph;
+import org.jboss.util.graph.Vertex;
+
+/**
+ * MainDeployerImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1.1 $
+ */
+public class MainDeployerImpl implements MainDeployer, MainDeployerStructure
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(MainDeployerImpl.class);
+
+ /** Whether we are shutdown */
+ private AtomicBoolean shutdown = new AtomicBoolean(false);
+
+ /** The deployers */
+ private Deployers deployers;
+
+ /** The structural deployers */
+ private StructuralDeployers structuralDeployers;
+
+ /** The deployments by name */
+ private Map<String, DeploymentContext> topLevelDeployments = new ConcurrentHashMap<String, DeploymentContext>();
+
+ /** All deployments by name */
+ private Map<String, DeploymentContext> allDeployments = new ConcurrentHashMap<String, DeploymentContext>();
+
+ /** Deployments in error by name */
+ private Map<String, DeploymentContext> errorDeployments = new ConcurrentHashMap<String, DeploymentContext>();
+
+ /** Deployments missing deployers */
+ private Map<String, DeploymentContext> missingDeployers = new ConcurrentHashMap<String, DeploymentContext>();
+
+ /** The undeploy work */
+ private List<DeploymentContext> undeploy = new CopyOnWriteArrayList<DeploymentContext>();
+
+ /** The deploy work */
+ private List<DeploymentContext> deploy = new CopyOnWriteArrayList<DeploymentContext>();
+
+ /**
+ * Get the deployers
+ *
+ * @return the deployers
+ */
+ public synchronized Deployers getDeployers()
+ {
+ return deployers;
+ }
+
+ /**
+ * Set the deployers
+ *
+ * @param deployers the deployers
+ * @throws IllegalArgumentException for null deployers
+ */
+ public synchronized void setDeployers(Deployers deployers)
+ {
+ if (deployers == null)
+ throw new IllegalArgumentException("Null deployers");
+ this.deployers = deployers;
+ }
+
+ /**
+ * Get the structural deployers
+ *
+ * @return the structural deployers
+ */
+ public synchronized StructuralDeployers getStructuralDeployers()
+ {
+ return structuralDeployers;
+ }
+
+ /**
+ * Set the structural deployers
+ *
+ * @param deployers the deployers
+ * @throws IllegalArgumentException for null deployers
+ */
+ public synchronized void setStructuralDeployers(StructuralDeployers deployers)
+ {
+ if (deployers == null)
+ throw new IllegalArgumentException("Null deployers");
+ structuralDeployers = deployers;
+ }
+
+ public Deployment getDeployment(String name)
+ {
+ DeploymentContext context = getTopLevelDeploymentContext(name);
+ if (context == null)
+ return null;
+ return context.getDeployment();
+ }
+
+ public DeploymentContext getDeploymentContext(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ return allDeployments.get(name);
+ }
+
+ public DeploymentContext getDeploymentContext(String name, boolean errorNotFound) throws DeploymentException
+ {
+ DeploymentContext context = getDeploymentContext(name);
+ if (errorNotFound && context == null)
+ throw new DeploymentException("Context " + name + " not found");
+ return context;
+ }
+
+ public DeploymentUnit getDeploymentUnit(String name)
+ {
+ DeploymentContext context = getDeploymentContext(name);
+ if (context == null)
+ return null;
+ return context.getDeploymentUnit();
+ }
+
+ public DeploymentUnit getDeploymentUnit(String name, boolean errorNotFound) throws DeploymentException
+ {
+ DeploymentUnit unit = getDeploymentUnit(name);
+ if (errorNotFound && unit == null)
+ throw new DeploymentException("Unit " + name + " not found");
+ return unit;
+ }
+
+ /**
+ * Get a top level deployment context by name
+ *
+ * @param name the name
+ * @return the context
+ */
+ public DeploymentContext getTopLevelDeploymentContext(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ return topLevelDeployments.get(name);
+ }
+
+ public Collection<DeploymentContext> getAll()
+ {
+ return Collections.unmodifiableCollection(allDeployments.values());
+ }
+
+ public Collection<DeploymentContext> getErrors()
+ {
+ return Collections.unmodifiableCollection(errorDeployments.values());
+ }
+
+ public Collection<DeploymentContext> getMissingDeployer()
+ {
+ return Collections.unmodifiableCollection(missingDeployers.values());
+ }
+
+ public Collection<Deployment> getTopLevel()
+ {
+ List<Deployment> result = new ArrayList<Deployment>();
+ for (DeploymentContext context : topLevelDeployments.values())
+ {
+ Deployment deployment = context.getDeployment();
+ if (deployment != null)
+ result.add(deployment);
+ else
+ throw new IllegalStateException("Context has no deployment? " + context.getName());
+ }
+ return result;
+ }
+
+ public synchronized void addDeployment(Deployment deployment) throws DeploymentException
+ {
+ if (deployment == null)
+ throw new DeploymentException("Null context");
+
+ if (shutdown.get())
+ throw new DeploymentException("The main deployer is shutdown");
+
+ String name = deployment.getName();
+ log.debug("Add deployment: " + name);
+
+ DeploymentContext previous = topLevelDeployments.get(name);
+ boolean topLevelFound = false;
+ if (previous != null)
+ {
+ log.debug("Removing previous deployment: " + previous.getName());
+ removeContext(previous);
+ topLevelFound = true;
+ }
+
+ if (topLevelFound == false)
+ {
+ previous = allDeployments.get(name);
+ if (previous != null)
+ throw new IllegalStateException("Deployment already exists as a subdeployment: " + name);
+ }
+
+ try
+ {
+ DeploymentContext context = determineStructure(deployment);
+ if (DeploymentState.ERROR.equals(context.getState()))
+ errorDeployments.put(name, context);
+
+ topLevelDeployments.put(name, context);
+ addContext(context);
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error determining deployment structure for " + name, t);
+ }
+ }
+
+ public synchronized boolean removeDeployment(Deployment deployment) throws DeploymentException
+ {
+ if (deployment == null)
+ throw new DeploymentException("Null deployment");
+ return removeDeployment(deployment.getName());
+ }
+
+ public synchronized boolean removeDeployment(String name) throws DeploymentException
+ {
+ if (name == null)
+ throw new DeploymentException("Null name");
+
+ if (shutdown.get())
+ throw new IllegalStateException("The main deployer is shutdown");
+
+ log.debug("Remove deployment context: " + name);
+
+ DeploymentContext context = topLevelDeployments.remove(name);
+ if (context == null)
+ return false;
+
+ removeContext(context);
+
+ return true;
+ }
+
+ public void deploy(Deployment deployment) throws DeploymentException
+ {
+ addDeployment(deployment);
+ // TODO just process this deployment
+ process();
+ checkComplete(deployment);
+ }
+
+ public boolean undeploy(Deployment deployment) throws DeploymentException
+ {
+ if (deployment == null)
+ throw new DeploymentException("Null deployment");
+
+ return undeploy(deployment.getName());
+ }
+
+ public boolean undeploy(String name) throws DeploymentException
+ {
+ boolean result = removeDeployment(name);
+ // TODO just process this deployment
+ process();
+ return result;
+ }
+
+ public void process()
+ {
+ if (shutdown.get())
+ throw new IllegalStateException("The main deployer is shutdown");
+
+ List<DeploymentContext> undeployContexts = null;
+ List<DeploymentContext> deployContexts = null;
+ synchronized (this)
+ {
+ if (deployers == null)
+ throw new IllegalStateException("No deployers");
+
+ if (undeploy.isEmpty() == false)
+ {
+ // Undeploy in reverse order (subdeployments first)
+ undeployContexts = new ArrayList<DeploymentContext>(undeploy.size());
+ for (int i = undeploy.size() -1; i >= 0; --i)
+ undeployContexts.add(undeploy.get(i));
+ undeploy.clear();
+ }
+ if (deploy.isEmpty() == false)
+ {
+ deployContexts = new ArrayList<DeploymentContext>(deploy);
+ deploy.clear();
+ }
+
+ if (undeployContexts == null && deployContexts == null)
+ {
+ log.debug("Asked to process() when there is nothing to do.");
+ return;
+ }
+ }
+
+ try
+ {
+ deployers.process(deployContexts, undeployContexts);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Unexpected error in process()", t);
+ }
+ }
+
+ public void shutdown()
+ {
+ while (topLevelDeployments.isEmpty() == false)
+ {
+ // Remove all the contexts
+ for (DeploymentContext context : topLevelDeployments.values())
+ {
+ topLevelDeployments.remove(context.getName());
+ removeContext(context);
+ }
+
+ // Do it
+ process();
+ }
+
+ shutdown.set(true);
+ }
+
+ public void checkComplete() throws DeploymentException
+ {
+ if (deployers == null)
+ throw new IllegalStateException("Null deployers");
+
+ deployers.checkComplete(errorDeployments.values(), missingDeployers.values());
+ }
+
+ public void checkComplete(Deployment deployment) throws DeploymentException
+ {
+ if (deployment == null)
+ throw new IllegalArgumentException("Null deployment");
+ checkComplete(deployment.getName());
+ }
+
+ public void checkComplete(String name) throws DeploymentException
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ DeploymentContext context = getDeploymentContext(name);
+ if (context == null)
+ throw new DeploymentException("Deployment not found " + name);
+ if (deployers == null)
+ throw new IllegalStateException("Null deployers");
+ deployers.checkComplete(context);
+ }
+
+ public DeploymentState getDeploymentState(String name)
+ {
+ DeploymentContext context = getDeploymentContext(name);
+ if (context == null)
+ return DeploymentState.UNDEPLOYED;
+ return context.getState();
+ }
+
+ public Map<String, ManagedObject> getManagedObjects(String name) throws DeploymentException
+ {
+ DeploymentContext context = getDeploymentContext(name);
+ if (context == null)
+ throw new IllegalArgumentException("Context not found: " + name);
+
+ return getManagedObjects(context);
+ }
+
+ public Map<String, ManagedObject> getManagedObjects(DeploymentContext context) throws DeploymentException
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+
+ if (deployers == null)
+ throw new IllegalStateException("No deployers");
+
+ return deployers.getManagedObjects(context);
+ }
+
+ public Graph<Map<String, ManagedObject>> getDeepManagedObjects(String name) throws DeploymentException
+ {
+ DeploymentContext context = getDeploymentContext(name);
+ Graph<Map<String, ManagedObject>> managedObjectsGraph = new Graph<Map<String, ManagedObject>>();
+ Vertex<Map<String, ManagedObject>> parent = new Vertex<Map<String, ManagedObject>>(context.getName());
+ managedObjectsGraph.setRootVertex(parent);
+ Map<String, ManagedObject> managedObjects = getManagedObjects(context);
+ parent.setData(managedObjects);
+ processManagedObjects(context, managedObjectsGraph, parent);
+
+ return managedObjectsGraph;
+ }
+
+ /**
+ * Get the managed objects for a context
+ *
+ * @param context the context
+ * @param graph the graph
+ * @param parent the parent node
+ * @throws DeploymentException for any problem
+ */
+ protected void processManagedObjects(DeploymentContext context, Graph<Map<String, ManagedObject>> graph, Vertex<Map<String, ManagedObject>> parent)
+ throws DeploymentException
+ {
+ List<DeploymentContext> children = context.getChildren();
+ for(DeploymentContext child : children)
+ {
+ Vertex<Map<String, ManagedObject>> vertex = new Vertex<Map<String, ManagedObject>>(child.getName());
+ Map<String, ManagedObject> managedObjects = getManagedObjects(context);
+ vertex.setData(managedObjects);
+ graph.addEdge(parent, vertex, 0);
+ processManagedObjects(child, graph, vertex);
+ }
+ }
+
+ /**
+ * Determine the structure of a deployment
+ *
+ * @param deployment the deployment
+ * @return the deployment context
+ * @throws DeploymentException for an error determining the deployment structure
+ */
+ private DeploymentContext determineStructure(Deployment deployment) throws DeploymentException
+ {
+ StructuralDeployers structuralDeployers = getStructuralDeployers();
+ if (structuralDeployers != null)
+ {
+ DeploymentContext result = structuralDeployers.determineStructure(deployment);
+ if (result != null)
+ return result;
+ }
+ throw new DeploymentException("No structural deployers.");
+ }
+
+ /**
+ * Add a context
+ *
+ * @param context the context
+ */
+ private void addContext(DeploymentContext context)
+ {
+ allDeployments.put(context.getName(), context);
+ if (context.getState() == DeploymentState.ERROR)
+ {
+ log.debug("Not scheduling addition of context already in error: " + context.getName() + " reason=" + context.getProblem());
+ return;
+ }
+ context.setState(DeploymentState.DEPLOYING);
+ log.debug("Scheduling deployment: " + context.getName());
+ deploy.add(context);
+
+ // Add all the children
+ List<DeploymentContext> children = context.getChildren();
+ if (children != null)
+ {
+ for (DeploymentContext child : children)
+ addContext(child);
+ }
+ }
+
+ /**
+ * Remove a context
+ *
+ * @param context the context
+ */
+ private void removeContext(DeploymentContext context)
+ {
+ String name = context.getName();
+ allDeployments.remove(name);
+ errorDeployments.remove(name);
+ missingDeployers.remove(name);
+ if (context.getState() == DeploymentState.ERROR)
+ {
+ log.debug("Not scheduling removal of context already in error: " + name);
+ return;
+ }
+ context.setState(DeploymentState.UNDEPLOYING);
+ log.debug("Scheduling undeployment: " + name);
+ undeploy.add(context);
+
+ // Remove all the children
+ List<DeploymentContext> children = context.getChildren();
+ if (children != null)
+ {
+ for (DeploymentContext child : children)
+ removeContext(child);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.
+ */
+package org.jboss.test.deployers;
+
+import java.util.Set;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeploymentFactory;
+import org.jboss.deployers.plugins.deployers.DeployerWrapper;
+import org.jboss.deployers.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.plugins.main.MainDeployerImpl;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.deployer.Deployers;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.StructuralDeployers;
+import org.jboss.deployers.structure.spi.StructureBuilder;
+import org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers;
+import org.jboss.deployers.structure.spi.helpers.AbstractStructureBuilder;
+import org.jboss.test.BaseTestCase;
+
+/**
+ * AbstractDeployerTest.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractDeployerTest extends BaseTestCase
+{
+ public AbstractDeployerTest(String name)
+ {
+ super(name);
+ }
+
+ protected DeployerClient createMainDeployer()
+ {
+ return createMainDeployer(null);
+ }
+
+ protected DeployerClient createMainDeployer(Deployer... deployers)
+ {
+ MainDeployerImpl mainDeployer = new MainDeployerImpl();
+ StructuralDeployers structure = createStructuralDeployers();
+ mainDeployer.setStructuralDeployers(structure);
+ Deployers theDeployers = createDeployers();
+ mainDeployer.setDeployers(theDeployers);
+ if (deployers != null)
+ {
+ for (Deployer deployer : deployers)
+ addDeployer(mainDeployer, deployer);
+ }
+ return mainDeployer;
+ }
+
+ protected StructureBuilder createStructureBuilder()
+ {
+ return new AbstractStructureBuilder();
+ }
+
+ protected StructuralDeployers createStructuralDeployers()
+ {
+ StructureBuilder builder = createStructureBuilder();
+ AbstractStructuralDeployers structure = new AbstractStructuralDeployers();
+ structure.setStructureBuilder(builder);
+ return structure;
+ }
+
+ protected Deployers createDeployers()
+ {
+ AbstractController controller = new AbstractController();
+ return new DeployersImpl(controller);
+ }
+
+ protected void addDeployer(DeployerClient main, Deployer deployer)
+ {
+ MainDeployerImpl mainDeployerImpl = (MainDeployerImpl) main;
+ DeployersImpl deployersImpl = (DeployersImpl) mainDeployerImpl.getDeployers();
+ deployersImpl.addDeployer(deployer);
+ }
+
+ protected void removeDeployer(DeployerClient main, Deployer deployer)
+ {
+ MainDeployerImpl mainDeployerImpl = (MainDeployerImpl) main;
+ DeployersImpl deployersImpl = (DeployersImpl) mainDeployerImpl.getDeployers();
+ deployersImpl.removeDeployer(deployer);
+ }
+
+ protected void setDeployers(DeployerClient main, Set<Deployer> deployers)
+ {
+ MainDeployerImpl mainDeployerImpl = (MainDeployerImpl) main;
+ DeployersImpl deployersImpl = (DeployersImpl) mainDeployerImpl.getDeployers();
+ deployersImpl.setDeployers(deployers);
+ }
+
+ protected Set<DeployerWrapper> getDeployers(DeployerClient main)
+ {
+ MainDeployerImpl mainDeployerImpl = (MainDeployerImpl) main;
+ DeployersImpl deployersImpl = (DeployersImpl) mainDeployerImpl.getDeployers();
+ return deployersImpl.getDeployerWrappers();
+ }
+
+ protected DeploymentContext getDeploymentContext(DeployerClient main, String name)
+ {
+ MainDeployerImpl mainDeployerImpl = (MainDeployerImpl) main;
+ return mainDeployerImpl.getDeploymentContext(name);
+ }
+
+ protected DeploymentContext assertDeploymentContext(DeployerClient main, String name)
+ {
+ DeploymentContext context = getDeploymentContext(main, name);
+ assertNotNull(name + " not found", context);
+ return context;
+ }
+
+ protected Deployment createSimpleDeployment(String name)
+ {
+ AbstractDeployment unit = new AbstractDeployment(name);
+ DeploymentFactory factory = new DeploymentFactory();
+ factory.addContext(unit, "");
+ return unit;
+ }
+
+ @Override
+ protected void configureLogging()
+ {
+ enableTrace("org.jboss.deployers");
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers;
+
+import org.jboss.test.deployers.deployer.DeployersDeployerTestSuite;
+import org.jboss.test.deployers.managed.DeployersManagedTestSuite;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Deployers Impl Test Suite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class DeployersImplTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Deployers Impl Tests");
+
+ suite.addTest(DeployersDeployerTestSuite.suite());
+ suite.addTest(DeployersManagedTestSuite.suite());
+
+ return suite;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.deployers.deployer.test.ComponentUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployerClassLoaderUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployerFlowUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployerOrderingUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployerProtocolUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployerWidthFirstUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployersImplUnitTestCase;
+import org.jboss.test.deployers.deployer.test.MultipleComponentTypeUnitTestCase;
+
+/**
+ * Deployers Deployer Test Suite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class DeployersDeployerTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Deployers Deployer Tests");
+
+ suite.addTest(DeployerProtocolUnitTestCase.suite());
+ suite.addTest(DeployerOrderingUnitTestCase.suite());
+ suite.addTest(DeployerFlowUnitTestCase.suite());
+ suite.addTest(DeployerWidthFirstUnitTestCase.suite());
+ suite.addTest(DeployerClassLoaderUnitTestCase.suite());
+ suite.addTest(DeployersImplUnitTestCase.suite());
+ suite.addTest(ComponentUnitTestCase.suite());
+ suite.addTest(MultipleComponentTypeUnitTestCase.suite());
+
+ return suite;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractTopLevelClassLoaderDeployer;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+
+/**
+ * TestDeployerOrdering.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestClassLoaderDeployer extends AbstractTopLevelClassLoaderDeployer implements ClassLoaderFactory
+{
+ public ClassLoader cl = new URLClassLoader(new URL[0]);
+
+ public ClassLoader createTopLevelClassLoader(DeploymentContext context) throws DeploymentException
+ {
+ log.debug("Created classloader: " + context.getName());
+ return cl;
+ }
+
+ public void removeTopLevelClassLoader(DeploymentContext context) throws Exception
+ {
+ log.debug("Removed classloader: " + context.getName());
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment1.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment1.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment1.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 61417 $
+ */
+public class TestDeployment1
+{
+ ArrayList<TestMetaData1> beans = new ArrayList<TestMetaData1>();
+
+ public void addBean(TestMetaData1 data)
+ {
+ beans.add(data);
+ }
+
+ public List<TestMetaData1> getBeans()
+ {
+ return beans;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment2.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment2.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeployment2.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 61417 $
+ */
+public class TestDeployment2
+{
+ ArrayList<TestMetaData2> beans = new ArrayList<TestMetaData2>();
+
+ public void addBean(TestMetaData2 data)
+ {
+ beans.add(data);
+ }
+
+ public List<TestMetaData2> getBeans()
+ {
+ return beans;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer1.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer1.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer1.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestDeploymentDeployer.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDeploymentDeployer1 extends AbstractComponentDeployer<TestDeployment1, TestMetaData1>
+{
+ public TestDeploymentDeployer1()
+ {
+ setDeploymentVisitor(new TestDeploymentVisitor());
+ setComponentVisitor(new TestMetaDataVisitor());
+ }
+
+ protected static void addTestComponent(DeploymentUnit unit, TestMetaData1 test)
+ {
+ DeploymentUnit component = unit.addComponent(test.getName());
+ component.addAttachment(TestMetaData1.class, test);
+ }
+
+ protected static void removeTestComponent(DeploymentUnit unit, TestMetaData1 test)
+ {
+ unit.removeComponent(test.getName());
+ }
+
+ /**
+ * TestDeploymentVisitor.
+ */
+ public class TestDeploymentVisitor implements DeploymentVisitor<TestDeployment1>
+ {
+ public Class<TestDeployment1> getVisitorType()
+ {
+ return TestDeployment1.class;
+ }
+
+ public void deploy(DeploymentUnit unit, TestDeployment1 deployment) throws DeploymentException
+ {
+ try
+ {
+ List<TestMetaData1> tests = deployment.getBeans();
+ if (tests == null || tests.isEmpty())
+ return;
+
+ for (TestMetaData1 test : tests)
+ addTestComponent(unit, test);
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment, t);
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit, TestDeployment1 deployment)
+ {
+ List<TestMetaData1> tests = deployment.getBeans();
+ if (tests == null)
+ return;
+
+ for (TestMetaData1 test : tests)
+ {
+ unit.removeComponent(test.getName());
+ }
+ }
+ }
+
+ /**
+ * TestMetaDataVisitor.
+ */
+ public static class TestMetaDataVisitor implements DeploymentVisitor<TestMetaData1>
+ {
+ public Class<TestMetaData1> getVisitorType()
+ {
+ return TestMetaData1.class;
+ }
+
+ public void deploy(DeploymentUnit unit, TestMetaData1 deployment) throws DeploymentException
+ {
+ addTestComponent(unit, deployment);
+ }
+
+ public void undeploy(DeploymentUnit unit, TestMetaData1 deployment)
+ {
+ removeTestComponent(unit, deployment);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer2.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer2.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentDeployer2.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestDeploymentDeployer.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDeploymentDeployer2 extends AbstractComponentDeployer<TestDeployment2, TestMetaData2>
+{
+ public TestDeploymentDeployer2()
+ {
+ setDeploymentVisitor(new TestDeploymentVisitor());
+ setComponentVisitor(new TestMetaDataVisitor());
+ }
+
+ protected static void addTestComponent(DeploymentUnit unit, TestMetaData2 test)
+ {
+ DeploymentUnit component = unit.addComponent(test.getName());
+ component.addAttachment(TestMetaData2.class, test);
+ }
+
+ protected static void removeTestComponent(DeploymentUnit unit, TestMetaData2 test)
+ {
+ unit.removeComponent(test.getName());
+ }
+
+ /**
+ * TestDeploymentVisitor.
+ */
+ public class TestDeploymentVisitor implements DeploymentVisitor<TestDeployment2>
+ {
+ public Class<TestDeployment2> getVisitorType()
+ {
+ return TestDeployment2.class;
+ }
+
+ public void deploy(DeploymentUnit unit, TestDeployment2 deployment) throws DeploymentException
+ {
+ try
+ {
+ List<TestMetaData2> tests = deployment.getBeans();
+ if (tests == null || tests.isEmpty())
+ return;
+
+ for (TestMetaData2 test : tests)
+ addTestComponent(unit, test);
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment, t);
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit, TestDeployment2 deployment)
+ {
+ List<TestMetaData2> tests = deployment.getBeans();
+ if (tests == null)
+ return;
+
+ for (TestMetaData2 test : tests)
+ {
+ unit.removeComponent(test.getName());
+ }
+ }
+ }
+
+ /**
+ * TestMetaDataVisitor.
+ */
+ public static class TestMetaDataVisitor implements DeploymentVisitor<TestMetaData2>
+ {
+ public Class<TestMetaData2> getVisitorType()
+ {
+ return TestMetaData2.class;
+ }
+
+ public void deploy(DeploymentUnit unit, TestMetaData2 deployment) throws DeploymentException
+ {
+ addTestComponent(unit, deployment);
+ }
+
+ public void undeploy(DeploymentUnit unit, TestMetaData2 deployment)
+ {
+ removeTestComponent(unit, deployment);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestFlowDeployer.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,113 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestSimpleDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestFlowDeployer extends AbstractRealDeployer
+{
+ private static int order = 0;
+
+ private Map<String, Integer> deployed = new HashMap<String, Integer>();
+ private Map<String, Integer> undeployed = new HashMap<String, Integer>();
+
+ private String name;
+
+ public static void reset()
+ {
+ order = 0;
+ }
+
+ public TestFlowDeployer(String name)
+ {
+ this.name = name;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ public void clear()
+ {
+ deployed.clear();
+ undeployed.clear();
+ }
+
+ public int getDeployOrder()
+ {
+ if (deployed.isEmpty())
+ return -1;
+ return Collections.max(deployed.values());
+ }
+
+ public int getUndeployOrder()
+ {
+ if (undeployed.isEmpty())
+ return -1;
+ return Collections.max(undeployed.values());
+ }
+
+ public Set<String> getDeployedUnits()
+ {
+ return deployed.keySet();
+ }
+
+ public Set<String> getUndeployedUnits()
+ {
+ return undeployed.keySet();
+ }
+
+ public Map<String, Integer> getDeployed()
+ {
+ return deployed;
+ }
+
+ public Map<String, Integer> getUndeployed()
+ {
+ return undeployed;
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ unit.getTypes().add(getType());
+ deployed.put(unit.getName(), ++order);
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ undeployed.put(unit.getName(), ++order);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData1.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData1.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData1.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 61417 $
+ */
+public class TestMetaData1
+{
+ private String name;
+
+ public TestMetaData1(String name)
+ {
+ this.name = name;
+ }
+ public String getName()
+ {
+ return name;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData2.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData2.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestMetaData2.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 61417 $
+ */
+public class TestMetaData2
+{
+ private String name;
+
+ public TestMetaData2(String name)
+ {
+ this.name = name;
+ }
+ public String getName()
+ {
+ return name;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer1.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer1.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer1.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestDeploymentDeployer.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestRealDeployer1 extends AbstractRealDeployerWithInput<TestMetaData1>
+{
+ public List<TestMetaData1> deployed = new ArrayList<TestMetaData1>();
+
+ public TestRealDeployer1()
+ {
+ setDeploymentVisitor(new TestMetaDataVisitor());
+ setComponentsOnly(true);
+ }
+
+ public class TestMetaDataVisitor implements DeploymentVisitor<TestMetaData1>
+ {
+ public Class<TestMetaData1> getVisitorType()
+ {
+ return TestMetaData1.class;
+ }
+
+ public void deploy(DeploymentUnit unit, TestMetaData1 deployment) throws DeploymentException
+ {
+ deployed.add(deployment);
+ }
+
+ public void undeploy(DeploymentUnit unit, TestMetaData1 deployment)
+ {
+ deployed.remove(deployment);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer2.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer2.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestRealDeployer2.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.
+ *
+ * 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.
+ */
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestDeploymentDeployer.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestRealDeployer2 extends AbstractRealDeployerWithInput<TestMetaData2>
+{
+ public List<TestMetaData2> deployed = new ArrayList<TestMetaData2>();
+
+ public TestRealDeployer2()
+ {
+ setDeploymentVisitor(new TestMetaDataVisitor());
+ setWantComponents(true);
+ }
+
+ public class TestMetaDataVisitor implements DeploymentVisitor<TestMetaData2>
+ {
+ public Class<TestMetaData2> getVisitorType()
+ {
+ return TestMetaData2.class;
+ }
+
+ public void deploy(DeploymentUnit unit, TestMetaData2 deployment) throws DeploymentException
+ {
+ deployed.add(deployment);
+ }
+
+ public void undeploy(DeploymentUnit unit, TestMetaData2 deployment)
+ {
+ deployed.remove(deployment);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestSimpleDeployer.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,135 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestSimpleDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestSimpleDeployer extends AbstractRealDeployer
+{
+ private static int order = 0;
+
+ private Map<String, Integer> deployed = new HashMap<String, Integer>();
+ private Map<String, Integer> undeployed = new HashMap<String, Integer>();
+
+ private String name;
+
+ public static void reset()
+ {
+ order = 0;
+ }
+
+ public TestSimpleDeployer()
+ {
+ this(Integer.MAX_VALUE);
+ name = super.toString();
+ }
+
+ public TestSimpleDeployer(String name)
+ {
+ this(Integer.MAX_VALUE);
+ this.name = name;
+ }
+
+ public TestSimpleDeployer(int relativeOrder)
+ {
+ setRelativeOrder(relativeOrder);
+ this.setType("test");
+ name = super.toString();
+ }
+
+ public TestSimpleDeployer(DeploymentStage stage)
+ {
+ setStage(stage);
+ this.setType("test");
+ name = super.toString();
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ public void clear()
+ {
+ deployed.clear();
+ undeployed.clear();
+ }
+
+ public int getDeployOrder()
+ {
+ if (deployed.isEmpty())
+ return -1;
+ return Collections.max(deployed.values());
+ }
+
+ public int getUndeployOrder()
+ {
+ if (undeployed.isEmpty())
+ return -1;
+ return Collections.max(undeployed.values());
+ }
+
+ public Set<String> getDeployedUnits()
+ {
+ return deployed.keySet();
+ }
+
+ public Set<String> getUndeployedUnits()
+ {
+ return undeployed.keySet();
+ }
+
+ public Map<String, Integer> getDeployed()
+ {
+ return deployed;
+ }
+
+ public Map<String, Integer> getUndeployed()
+ {
+ return undeployed;
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ unit.getTypes().add(getType());
+ deployed.put(unit.getName(), ++order);
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ undeployed.put(unit.getName(), ++order);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/ComponentUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/ComponentUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/ComponentUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,102 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import java.util.Collections;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestDeployment1;
+import org.jboss.test.deployers.deployer.support.TestDeploymentDeployer1;
+import org.jboss.test.deployers.deployer.support.TestMetaData1;
+import org.jboss.test.deployers.deployer.support.TestRealDeployer1;
+
+/**
+ * Component tests
+ *
+ * @author adrian at jboss.org
+ * @version $Revision: 61417 $
+ */
+public class ComponentUnitTestCase extends AbstractDeployerTest
+{
+
+ public static Test suite()
+ {
+ return new TestSuite(ComponentUnitTestCase.class);
+ }
+
+ public ComponentUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDeployment() throws Exception
+ {
+ TestDeploymentDeployer1 componentDeployer1 = new TestDeploymentDeployer1();
+ TestRealDeployer1 realDeployer1 = new TestRealDeployer1();
+ DeployerClient main = createMainDeployer(componentDeployer1, realDeployer1);
+
+ Deployment deployment = createSimpleDeployment("deploy");
+ MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
+
+ TestDeployment1 deployment1 = new TestDeployment1();
+ TestMetaData1 component1 = new TestMetaData1("TestBean1");
+ deployment1.addBean(component1);
+ attachments.addAttachment(TestDeployment1.class, deployment1);
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(Collections.singletonList(component1), realDeployer1.deployed);
+
+ main.removeDeployment(deployment);
+ main.process();
+ assertEmpty(realDeployer1.deployed);
+ }
+
+ public void testMetaData() throws Exception
+ {
+ TestDeploymentDeployer1 componentDeployer1 = new TestDeploymentDeployer1();
+ TestRealDeployer1 realDeployer1 = new TestRealDeployer1();
+ DeployerClient main = createMainDeployer(componentDeployer1, realDeployer1);
+
+ Deployment deployment = createSimpleDeployment("deploy");
+ MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
+
+ TestMetaData1 component1 = new TestMetaData1("TestBean1");
+ attachments.addAttachment(TestMetaData1.class, component1);
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(Collections.singletonList(component1), realDeployer1.deployed);
+
+ main.removeDeployment(deployment);
+ main.process();
+ assertEmpty(realDeployer1.deployed);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,97 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeploymentFactory;
+import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestClassLoaderDeployer;
+
+/**
+ * DeployerClassLoaderUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerClassLoaderUnitTestCase extends AbstractDeployerTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(DeployerClassLoaderUnitTestCase.class);
+ }
+
+ public DeployerClassLoaderUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testClassLoader() throws Exception
+ {
+ TestClassLoaderDeployer deployer = new TestClassLoaderDeployer();
+ DeployerClient main = createMainDeployer(deployer);
+
+ Deployment deployment = createSimpleDeployment("single");
+ main.addDeployment(deployment);
+ main.process();
+
+ DeploymentContext context = assertDeploymentContext(main, "single");
+ assertEquals(DeploymentState.DEPLOYED, context.getState());
+ assertEquals(deployer.cl, context.getClassLoader());
+
+ main.removeDeployment(deployment);
+ main.process();
+ assertEquals(DeploymentState.UNDEPLOYED, context.getState());
+ assertNull(context.getClassLoader());
+ }
+
+ public void testSubdeploymentClassLoader() throws Exception
+ {
+ TestClassLoaderDeployer deployer = new TestClassLoaderDeployer();
+ DeployerClient main = createMainDeployer(deployer);
+
+ Deployment deployment = createSimpleDeployment("top");
+ DeploymentFactory factory = new DeploymentFactory();
+ factory.addContext(deployment, "sub");
+ main.addDeployment(deployment);
+ main.process();
+
+ DeploymentContext top = assertDeploymentContext(main, "top");
+ DeploymentContext sub = assertDeploymentContext(main, "top/sub");
+ assertEquals(DeploymentState.DEPLOYED, top.getState());
+ assertEquals(deployer.cl, top.getClassLoader());
+ assertEquals(DeploymentState.DEPLOYED, sub.getState());
+ assertEquals(deployer.cl, sub.getClassLoader());
+
+ main.removeDeployment(deployment);
+ main.process();
+ assertEquals(DeploymentState.UNDEPLOYED, top.getState());
+ assertNull(top.getClassLoader());
+ assertEquals(DeploymentState.UNDEPLOYED, sub.getState());
+ assertNull(sub.getClassLoader());
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerFlowUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerFlowUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerFlowUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,501 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestFlowDeployer;
+
+/**
+ * DeployerOrderingUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerFlowUnitTestCase extends AbstractDeployerTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(DeployerFlowUnitTestCase.class);
+ }
+
+ public DeployerFlowUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ TestFlowDeployer.reset();
+ }
+
+ public void testSimpleInputOutputCorrectOrder() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test");
+ addDeployer(main, deployer1);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test");
+ addDeployer(main, deployer2);
+
+ Deployment deployment = createSimpleDeployment("correctOrder");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(5, deployer1.getDeployOrder());
+ assertEquals(6, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+ }
+
+ public void testSimpleInputOutputWrongOrder() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test");
+ addDeployer(main, deployer2);
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test");
+ addDeployer(main, deployer1);
+
+ Deployment deployment = createSimpleDeployment("wrongOrder");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(5, deployer1.getDeployOrder());
+ assertEquals(6, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+ }
+
+ public void testInputOutputLoop() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setInputs("input1");
+ deployer1.setOutputs("output1");
+ addDeployer(main, deployer1);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("output1");
+ deployer2.setOutputs("output2");
+ addDeployer(main, deployer2);
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setInputs("output2");
+ deployer3.setOutputs("input1");
+ try
+ {
+ addDeployer(main, deployer3);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testInputOutputTransient() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test");
+ addDeployer(main, deployer1);
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setInputs("test");
+ addDeployer(main, deployer3);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test");
+ deployer2.setOutputs("test");
+ addDeployer(main, deployer2);
+
+ Deployment deployment = createSimpleDeployment("transient");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+ assertEquals(-1, deployer3.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(7, deployer1.getDeployOrder());
+ assertEquals(8, deployer2.getDeployOrder());
+ assertEquals(9, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+ }
+
+ public void testInputOutputTransient2() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setInputs("test");
+ deployer1.setOutputs("test");
+ addDeployer(main, deployer1);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test");
+ addDeployer(main, deployer2);
+
+ Deployment deployment = createSimpleDeployment("transient2");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(5, deployer1.getDeployOrder());
+ assertEquals(6, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+ }
+
+ public void testInputOutputMultipleTransient() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer4 = new TestFlowDeployer("4");
+ deployer4.setInputs("test");
+ addDeployer(main, deployer4);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test");
+ deployer2.setOutputs("test");
+ addDeployer(main, deployer2);
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setInputs("test");
+ deployer3.setOutputs("test");
+ addDeployer(main, deployer3);
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test");
+ addDeployer(main, deployer1);
+
+ Deployment deployment = createSimpleDeployment("transient");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(4, deployer4.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+ assertEquals(-1, deployer3.getUndeployOrder());
+ assertEquals(-1, deployer4.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(4, deployer4.getDeployOrder());
+ assertEquals(8, deployer1.getUndeployOrder());
+ assertEquals(7, deployer2.getUndeployOrder());
+ assertEquals(6, deployer3.getUndeployOrder());
+ assertEquals(5, deployer4.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(9, deployer1.getDeployOrder());
+ assertEquals(10, deployer2.getDeployOrder());
+ assertEquals(11, deployer3.getDeployOrder());
+ assertEquals(12, deployer4.getDeployOrder());
+ assertEquals(8, deployer1.getUndeployOrder());
+ assertEquals(7, deployer2.getUndeployOrder());
+ assertEquals(6, deployer3.getUndeployOrder());
+ assertEquals(5, deployer4.getUndeployOrder());
+ }
+
+ public void testMultipleOutput() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test1", "test2");
+ addDeployer(main, deployer1);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test1");
+ addDeployer(main, deployer2);
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setInputs("test2");
+ addDeployer(main, deployer3);
+
+ Deployment deployment = createSimpleDeployment("MultipleOutput");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+ assertEquals(-1, deployer3.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(7, deployer1.getDeployOrder());
+ assertEquals(8, deployer2.getDeployOrder());
+ assertEquals(9, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+ }
+
+ public void testMultipleInput() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setInputs("test1", "test2");
+ addDeployer(main, deployer3);
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test1");
+ addDeployer(main, deployer1);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setOutputs("test2");
+ addDeployer(main, deployer2);
+
+ Deployment deployment = createSimpleDeployment("MultipleInput");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+ assertEquals(-1, deployer3.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(7, deployer1.getDeployOrder());
+ assertEquals(8, deployer2.getDeployOrder());
+ assertEquals(9, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+ }
+
+ public void testChain() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setInputs("test2");
+ addDeployer(main, deployer3);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setInputs("test1");
+ deployer2.setOutputs("test2");
+ addDeployer(main, deployer2);
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test1");
+ addDeployer(main, deployer1);
+
+ Deployment deployment = createSimpleDeployment("Chain");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+ assertEquals(-1, deployer3.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(7, deployer1.getDeployOrder());
+ assertEquals(8, deployer2.getDeployOrder());
+ assertEquals(9, deployer3.getDeployOrder());
+ assertEquals(6, deployer1.getUndeployOrder());
+ assertEquals(5, deployer2.getUndeployOrder());
+ assertEquals(4, deployer3.getUndeployOrder());
+ }
+
+ public void testComplicated() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestFlowDeployer deployer6 = new TestFlowDeployer("6");
+ deployer6.setInputs("test1", "test3");
+ addDeployer(main, deployer6);
+ TestFlowDeployer deployer5 = new TestFlowDeployer("5");
+ deployer5.setInputs("test3");
+ deployer5.setOutputs("test3");
+ addDeployer(main, deployer5);
+ TestFlowDeployer deployer4 = new TestFlowDeployer("4");
+ deployer4.setInputs("test2");
+ deployer4.setOutputs("test3");
+ addDeployer(main, deployer4);
+ TestFlowDeployer deployer3 = new TestFlowDeployer("3");
+ deployer3.setOutputs("test2");
+ addDeployer(main, deployer3);
+ TestFlowDeployer deployer2 = new TestFlowDeployer("2");
+ deployer2.setOutputs("test1");
+ addDeployer(main, deployer2);
+ TestFlowDeployer deployer1 = new TestFlowDeployer("1");
+ deployer1.setOutputs("test1");
+ addDeployer(main, deployer1);
+
+ Deployment deployment = createSimpleDeployment("Complicated");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(4, deployer4.getDeployOrder());
+ assertEquals(5, deployer5.getDeployOrder());
+ assertEquals(6, deployer6.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+ assertEquals(-1, deployer3.getUndeployOrder());
+ assertEquals(-1, deployer4.getUndeployOrder());
+ assertEquals(-1, deployer5.getUndeployOrder());
+ assertEquals(-1, deployer6.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(3, deployer3.getDeployOrder());
+ assertEquals(4, deployer4.getDeployOrder());
+ assertEquals(5, deployer5.getDeployOrder());
+ assertEquals(6, deployer6.getDeployOrder());
+ assertEquals(12, deployer1.getUndeployOrder());
+ assertEquals(11, deployer2.getUndeployOrder());
+ assertEquals(10, deployer3.getUndeployOrder());
+ assertEquals(9, deployer4.getUndeployOrder());
+ assertEquals(8, deployer5.getUndeployOrder());
+ assertEquals(7, deployer6.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(13, deployer1.getDeployOrder());
+ assertEquals(14, deployer2.getDeployOrder());
+ assertEquals(15, deployer3.getDeployOrder());
+ assertEquals(16, deployer4.getDeployOrder());
+ assertEquals(17, deployer5.getDeployOrder());
+ assertEquals(18, deployer6.getDeployOrder());
+ assertEquals(12, deployer1.getUndeployOrder());
+ assertEquals(11, deployer2.getUndeployOrder());
+ assertEquals(10, deployer3.getUndeployOrder());
+ assertEquals(9, deployer4.getUndeployOrder());
+ assertEquals(8, deployer5.getUndeployOrder());
+ assertEquals(7, deployer6.getUndeployOrder());
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerOrderingUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerOrderingUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerOrderingUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestSimpleDeployer;
+
+/**
+ * DeployerOrderingUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerOrderingUnitTestCase extends AbstractDeployerTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(DeployerOrderingUnitTestCase.class);
+ }
+
+ public DeployerOrderingUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ TestSimpleDeployer.reset();
+ }
+
+ public void testCorrectOrder() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestSimpleDeployer deployer1 = new TestSimpleDeployer(1);
+ addDeployer(main, deployer1);
+ TestSimpleDeployer deployer2 = new TestSimpleDeployer(2);
+ addDeployer(main, deployer2);
+
+ Deployment deployment = createSimpleDeployment("correctOrder");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(5, deployer1.getDeployOrder());
+ assertEquals(6, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+ }
+
+ public void testWrongOrder() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ TestSimpleDeployer deployer1 = new TestSimpleDeployer(1);
+ addDeployer(main, deployer1);
+ TestSimpleDeployer deployer2 = new TestSimpleDeployer(2);
+ addDeployer(main, deployer2);
+
+ Deployment deployment = createSimpleDeployment("wrongOrder");
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(-1, deployer1.getUndeployOrder());
+ assertEquals(-1, deployer2.getUndeployOrder());
+
+ main.removeDeployment(deployment);
+ main.process();
+
+ assertEquals(1, deployer1.getDeployOrder());
+ assertEquals(2, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(5, deployer1.getDeployOrder());
+ assertEquals(6, deployer2.getDeployOrder());
+ assertEquals(4, deployer1.getUndeployOrder());
+ assertEquals(3, deployer2.getUndeployOrder());
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerProtocolUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerProtocolUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerProtocolUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,113 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestSimpleDeployer;
+
+/**
+ * DeployerProtocolUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerProtocolUnitTestCase extends AbstractDeployerTest
+{
+ private TestSimpleDeployer deployer = new TestSimpleDeployer();
+
+ public static Test suite()
+ {
+ return new TestSuite(DeployerProtocolUnitTestCase.class);
+ }
+
+ public DeployerProtocolUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDeploy() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment context = createSimpleDeployment("deploy");
+ main.addDeployment(context);
+ main.process();
+ Set<String> expected = new HashSet<String>();
+ expected.add(context.getName());
+ assertEquals(expected, deployer.getDeployedUnits());
+ HashSet<String> types = new HashSet<String>();
+ types.add("test");
+ // TODO types assertEquals(types, context.getTypes());
+ }
+
+ public void testUndeploy() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment context = createSimpleDeployment("undeploy");
+ main.addDeployment(context);
+ main.process();
+ Set<String> expected = new HashSet<String>();
+ expected.add(context.getName());
+ assertEquals(expected, deployer.getDeployedUnits());
+
+ main.removeDeployment(context.getName());
+ main.process();
+ assertEquals(expected, deployer.getUndeployedUnits());
+ }
+
+ public void testRedeploy() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment context = createSimpleDeployment("redeploy");
+ main.addDeployment(context);
+ main.process();
+ Set<String> expected = new HashSet<String>();
+ expected.add(context.getName());
+ assertEquals(expected, deployer.getDeployedUnits());
+
+ main.removeDeployment(context.getName());
+ main.process();
+ assertEquals(expected, deployer.getUndeployedUnits());
+
+ deployer.clear();
+ main.addDeployment(context);
+ main.process();
+ expected.clear();
+ expected.add(context.getName());
+ assertEquals(expected, deployer.getDeployedUnits());
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ return createMainDeployer(deployer);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerWidthFirstUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerWidthFirstUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployerWidthFirstUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestSimpleDeployer;
+
+/**
+ * DeployerWidthFirstUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerWidthFirstUnitTestCase extends AbstractDeployerTest
+{
+ private TestSimpleDeployer deployer1 = new TestSimpleDeployer(1);
+ private TestSimpleDeployer deployer2 = new TestSimpleDeployer(2);
+
+ public static Test suite()
+ {
+ return new TestSuite(DeployerWidthFirstUnitTestCase.class);
+ }
+
+ public DeployerWidthFirstUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDeployWidthFirst() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment context1 = createSimpleDeployment("deploy1");
+ main.addDeployment(context1);
+ Deployment context2 = createSimpleDeployment("deploy2");
+ main.addDeployment(context2);
+ main.process();
+
+ Map<String, Integer> deployed1 = deployer1.getDeployed();
+ Map<String, Integer> deployed2 = deployer2.getDeployed();
+
+ int c1d1 = deployed1.get(context1.getName());
+ int c1d2 = deployed2.get(context1.getName());
+ int c2d1 = deployed1.get(context2.getName());
+ int c2d2 = deployed2.get(context2.getName());
+
+ assertFalse(c1d1 == -1);
+ assertFalse(c1d2 == -1);
+ assertFalse(c2d1 == -1);
+ assertFalse(c2d2 == -1);
+
+ assertTrue("Deployer1 should be before Deployer2", c1d1 < c1d2 && c1d1 < c2d2 && c2d1 < c1d2 && c2d1 < c2d2);
+ }
+
+ public void testUndeployWidthFirst() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment context1 = createSimpleDeployment("deploy1");
+ main.addDeployment(context1);
+ Deployment context2 = createSimpleDeployment("deploy2");
+ main.addDeployment(context2);
+ main.process();
+
+ main.removeDeployment(context1.getName());
+ main.removeDeployment(context2.getName());
+ main.process();
+
+ Map<String, Integer> undeployed1 = deployer1.getUndeployed();
+ Map<String, Integer> undeployed2 = deployer2.getUndeployed();
+
+ int c1d1 = undeployed1.get(context1.getName());
+ int c1d2 = undeployed2.get(context1.getName());
+ int c2d1 = undeployed1.get(context2.getName());
+ int c2d2 = undeployed2.get(context2.getName());
+
+ assertFalse(c1d1 == -1);
+ assertFalse(c1d2 == -1);
+ assertFalse(c2d1 == -1);
+ assertFalse(c2d2 == -1);
+
+ assertTrue("Deployer2 should be before Deployer1", c1d2 < c1d1 && c1d2 < c2d1 && c2d2 < c1d1 && c2d2 < c2d1);
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ deployer1 = new TestSimpleDeployer(DeploymentStages.POST_CLASSLOADER);
+ deployer2 = new TestSimpleDeployer(DeploymentStages.REAL);
+ return createMainDeployer(deployer1, deployer2);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployersImplUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployersImplUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/DeployersImplUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,179 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestSimpleDeployer;
+
+/**
+ * DeployersImplUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployersImplUnitTestCase extends AbstractDeployerTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(DeployersImplUnitTestCase.class);
+ }
+
+ public DeployersImplUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void testAddNullDeployer() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ try
+ {
+ addDeployer(main, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testAddDeployers() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ assertEmpty(getDeployers(main));
+
+ Deployer deployer = new TestSimpleDeployer();
+ HashSet<Deployer> expected = new HashSet<Deployer>();
+ expected.add(deployer);
+
+ addDeployer(main, deployer);
+ assertEquals(expected, getDeployers(main));
+
+ deployer = new TestSimpleDeployer();
+ expected.add(deployer);
+
+ addDeployer(main, deployer);
+ assertEquals(expected, getDeployers(main));
+
+ // Duplicate
+ addDeployer(main, deployer);
+ assertEquals(expected, getDeployers(main));
+ }
+
+ public void testRemoveNullDeployer() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ try
+ {
+ removeDeployer(main, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testRemoveDeployers() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ assertEmpty(getDeployers(main));
+
+ Deployer deployer1 = new TestSimpleDeployer("1");
+ Deployer deployer2 = new TestSimpleDeployer("2");
+ HashSet<Deployer> expected = new HashSet<Deployer>();
+ expected.add(deployer1);
+ expected.add(deployer2);
+ addDeployer(main, deployer1);
+ addDeployer(main, deployer2);
+ assertEquals(expected, getDeployers(main));
+
+ Deployer notPresent = new TestSimpleDeployer();
+ removeDeployer(main, notPresent);
+ assertEquals(expected, getDeployers(main));
+
+ removeDeployer(main, deployer1);
+ expected.remove(deployer1);
+ assertEquals(expected, getDeployers(main));
+
+ removeDeployer(main, deployer2);
+ expected.remove(deployer2);
+ assertEquals(expected, getDeployers(main));
+ }
+
+ public void testSetNullDeployers() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ try
+ {
+ setDeployers(main, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testSetDeployers() throws Exception
+ {
+ DeployerClient main = createMainDeployer();
+ assertEmpty(getDeployers(main));
+
+ Deployer deployer1 = new TestSimpleDeployer();
+ Deployer deployer2 = new TestSimpleDeployer();
+ Set<Deployer> expected = new HashSet<Deployer>();
+ expected.add(deployer1);
+ expected.add(deployer2);
+ setDeployers(main, expected);
+ assertEquals(expected, getDeployers(main));
+
+ expected = new HashSet<Deployer>();
+ expected.add(deployer1);
+ setDeployers(main, expected);
+ assertEquals(expected, getDeployers(main));
+
+ expected = new HashSet<Deployer>();
+ expected.add(deployer1);
+ setDeployers(main, expected);
+ assertEquals(expected, getDeployers(main));
+
+ expected = Collections.emptySet();
+ setDeployers(main, expected);
+ assertEquals(expected, getDeployers(main));
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/MultipleComponentTypeUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/MultipleComponentTypeUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/MultipleComponentTypeUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,94 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import java.util.Collections;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestDeployment1;
+import org.jboss.test.deployers.deployer.support.TestDeployment2;
+import org.jboss.test.deployers.deployer.support.TestDeploymentDeployer1;
+import org.jboss.test.deployers.deployer.support.TestDeploymentDeployer2;
+import org.jboss.test.deployers.deployer.support.TestMetaData1;
+import org.jboss.test.deployers.deployer.support.TestMetaData2;
+import org.jboss.test.deployers.deployer.support.TestRealDeployer1;
+import org.jboss.test.deployers.deployer.support.TestRealDeployer2;
+
+/**
+ * Test of deployments with multiple deployment types that map to
+ * multiple components.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 61417 $
+ */
+public class MultipleComponentTypeUnitTestCase extends AbstractDeployerTest
+{
+
+ public static Test suite()
+ {
+ return new TestSuite(MultipleComponentTypeUnitTestCase.class);
+ }
+
+ public MultipleComponentTypeUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDeploy() throws Exception
+ {
+ TestDeploymentDeployer1 componentDeployer1 = new TestDeploymentDeployer1();
+ TestDeploymentDeployer2 componentDeployer2 = new TestDeploymentDeployer2();
+ TestRealDeployer1 realDeployer1 = new TestRealDeployer1();
+ TestRealDeployer2 realDeployer2 = new TestRealDeployer2();
+ DeployerClient main = createMainDeployer(componentDeployer1, componentDeployer2, realDeployer1, realDeployer2);
+
+ Deployment deployment = createSimpleDeployment("deploy");
+ MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
+
+ TestDeployment1 deployment1 = new TestDeployment1();
+ TestMetaData1 component1 = new TestMetaData1("TestBean1");
+ deployment1.addBean(component1);
+ attachments.addAttachment(TestDeployment1.class, deployment1);
+
+ TestDeployment2 deployment2 = new TestDeployment2();
+ TestMetaData2 component2 = new TestMetaData2("TestBean2");
+ deployment2.addBean(component2);
+ attachments.addAttachment(TestDeployment2.class, deployment2);
+
+ main.addDeployment(deployment);
+ main.process();
+
+ assertEquals(Collections.singletonList(component1), realDeployer1.deployed);
+ assertEquals(Collections.singletonList(component2), realDeployer2.deployed);
+
+ main.removeDeployment(deployment);
+ main.process();
+ assertEmpty(realDeployer1.deployed);
+ assertEmpty(realDeployer2.deployed);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/DeployersManagedTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/DeployersManagedTestSuite.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/DeployersManagedTestSuite.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.managed;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.deployers.managed.test.DeployerManagedObjectUnitTestCase;
+
+/**
+ * Deployers Managed Test Suite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class DeployersManagedTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Deployers Managed Tests");
+
+ suite.addTest(DeployerManagedObjectUnitTestCase.suite());
+
+ return suite;
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.managed.support;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * TestAttachment.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestAttachment implements Cloneable, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ private Map<String, Serializable> fields = new HashMap<String, Serializable>();
+
+ public Serializable getProperty(String name)
+ {
+ return fields.get(name);
+ }
+
+ public void setProperty(String name, Serializable value)
+ {
+ fields.put(name, value);
+ }
+
+ public TestAttachment clone()
+ {
+ try
+ {
+ TestAttachment clone = (TestAttachment) super.clone();
+ clone.fields = new HashMap<String, Serializable>(clone.fields);
+ return clone;
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new Error("Unexpected", e);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestFields.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestFields.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestFields.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.managed.support;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.Fields;
+
+/**
+ * TestFields.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestFields implements Fields
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ private TestAttachment attachment;
+
+ private String property;
+
+ public TestFields(TestAttachment attachment, String property)
+ {
+ this.attachment = attachment;
+ this.property = property;
+ }
+
+ public Serializable getField(String name)
+ {
+ if (name == Fields.NAME)
+ return property;
+ if (name == Fields.VALUE)
+ return attachment.getProperty(property);
+ return null;
+ }
+
+ public void setField(String name, Serializable value)
+ {
+ if (name == Fields.VALUE)
+ {
+ attachment.setProperty(property, value);
+ return;
+ }
+ throw new UnsupportedOperationException("setField: " + name);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.managed.support;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+
+/**
+ * TestManagedObjectDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestManagedObjectDeployer extends AbstractDeployer implements ManagedObjectCreator
+{
+ public static TestAttachment lastAttachment;
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ lastAttachment = unit.getAttachment(TestAttachment.class);
+ if (lastAttachment == null)
+ {
+ lastAttachment = new TestAttachment();
+ lastAttachment.setProperty("string1", "initialString1");
+ lastAttachment.setProperty("string2", "initialString2");
+ unit.addAttachment(TestAttachment.class, lastAttachment);
+ }
+ }
+
+ public void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects) throws DeploymentException
+ {
+ TestAttachment attachment = unit.getAttachment(TestAttachment.class);
+ if (attachment != null)
+ {
+ attachment = attachment.clone();
+ ManagedObjectImpl managedObject = new ManagedObjectImpl(TestAttachment.class.getName());
+ managedObject.setAttachment(attachment);
+ Set<ManagedProperty> properties = managedObject.getProperties();
+ properties.add(new ManagedPropertyImpl(managedObject, new TestFields(attachment, "string1")));
+ properties.add(new ManagedPropertyImpl(managedObject, new TestFields(attachment, "string2")));
+ managedObjects.put(TestAttachment.class.getName(), managedObject);
+ }
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java 2007-06-27 15:57:36 UTC (rev 63682)
@@ -0,0 +1,125 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+package org.jboss.test.deployers.managed.test;
+
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.managed.support.TestAttachment;
+import org.jboss.test.deployers.managed.support.TestManagedObjectDeployer;
+import org.jboss.util.graph.Graph;
+
+/**
+ * DeployerManagedObjectUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerManagedObjectUnitTestCase extends AbstractDeployerTest
+{
+ private TestManagedObjectDeployer deployer = new TestManagedObjectDeployer();
+
+ public static Test suite()
+ {
+ return new TestSuite(DeployerManagedObjectUnitTestCase.class);
+ }
+
+ public DeployerManagedObjectUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testManagedObject() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ // Deploy a context
+ Deployment context = createSimpleDeployment("deploy");
+ main.addDeployment(context);
+ main.process();
+
+ // Check the default settings
+ assertNotNull(deployer.lastAttachment);
+ assertEquals("initialString1", deployer.lastAttachment.getProperty("string1"));
+ assertEquals("initialString2", deployer.lastAttachment.getProperty("string2"));
+
+ // Get the managed object
+ Map<String, ManagedObject> mos = main.getManagedObjects(context.getName());
+ assertNotNull(mos);
+ ManagedObject mo = mos.get(TestAttachment.class.getName());
+ assertNotNull(mo);
+ //
+ Graph<Map<String, ManagedObject>> mosg = main.getDeepManagedObjects(context.getName());
+ assertEquals("MO Graph", mosg.size(), 1);
+ mos = mosg.getRootVertex().getData();
+ assertNotNull(mos);
+ mo = mos.get(TestAttachment.class.getName());
+ assertNotNull(mo);
+
+ // TODO the attachment should NOT be the top level managed object
+ // that should be describing the structure and deployment state
+ // with the attachments as sub managed objects
+
+ // Check the managed object has the default settings
+ assertEquals("initialString1", mo.getProperty("string1").getValue());
+ assertEquals("initialString2", mo.getProperty("string2").getValue());
+
+ // Change a value
+ mo.getProperty("string1").setValue("changedString1");
+
+ // Get the changed attachment
+ TestAttachment attachment = (TestAttachment) mo.getAttachment();
+
+ // Redeploy with our changed attachment
+ MutableAttachments attachments = (MutableAttachments) context.getPredeterminedManagedObjects();
+ attachments.addAttachment(TestAttachment.class, attachment);
+ main.addDeployment(context);
+ main.process();
+
+ // Check the changed settings as seen by the deployer
+ assertNotNull(deployer.lastAttachment);
+ assertEquals("changedString1", deployer.lastAttachment.getProperty("string1"));
+ assertEquals("initialString2", deployer.lastAttachment.getProperty("string2"));
+
+ // TODO shouldn't have to reget the managed object handles across redeploys?
+ mos = main.getManagedObjects(context.getName());
+ assertNotNull(mos);
+ mo = mos.get(TestAttachment.class.getName());
+ assertNotNull(mo);
+
+ // Check the changed settings as described by the managed object
+ assertEquals("changedString1", mo.getProperty("string1").getValue());
+ assertEquals("initialString2", mo.getProperty("string2").getValue());
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ return createMainDeployer(deployer);
+ }
+}
More information about the jboss-cvs-commits
mailing list