[jboss-cvs] JBossAS SVN: r71618 - in projects/jboss-deployers/trunk/deployers-impl/src: tests/org/jboss/test/deployers/main and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 2 11:03:23 EDT 2008


Author: alesj
Date: 2008-04-02 11:03:23 -0400 (Wed, 02 Apr 2008)
New Revision: 71618

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedControllerContext.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedDependencyInfo.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedTestAttachmentDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestDemandDependencyItem.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/CycleCheckCompleteTestCase.java
Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/DeployersMainTestSuite.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/AbstractTestAttachmentDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java
Log:
[JBDEPLOY-30] initial work on better cycle info.

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2008-04-02 14:34:27 UTC (rev 71617)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -59,6 +59,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.util.id.GUID;
 
 /**
  * DeployersImpl.
@@ -680,7 +681,8 @@
          contextsInError.put(context.getName().toString(), getRootCause(context.getError()));
       else
       {
-         String name = context.getName().toString();
+         Object contextName = context.getName();
+         String name = contextName.toString();
          Set<MissingDependency> dependencies = new HashSet<MissingDependency>();
          DependencyInfo dependsInfo = context.getDependencyInfo();
          for (DependencyItem item : dependsInfo.getIDependOn(null))
@@ -690,33 +692,54 @@
                String dependency;
                ControllerState actualState = null;
                String actualStateString;
+
                Object iDependOn = item.getIDependOn();
-               if (iDependOn == null)
+               if (contextName.equals(iDependOn) == false)
                {
-                  dependency = "<UNKNOWN>";
-                  actualStateString = "** UNRESOLVED " + item.toHumanReadableString() + " **";
-               }
-               else
-               {
-                  dependency = iDependOn.toString();
-                  ControllerContext other = controller.getContext(iDependOn, null);
-                  if (other == null)
-                     actualStateString = "** NOT FOUND " + item.toHumanReadableString() + " **";
+                  boolean includeDependency = true;
+
+                  if (iDependOn == null)
+                  {
+                     dependency = "<UNKNOWN " + GUID.asString() + ">";
+                     actualStateString = "** UNRESOLVED " + item.toHumanReadableString() + " **";
+                  }
                   else
                   {
-                     actualState = other.getState();
-                     actualStateString = actualState.getStateString();
+                     dependency = iDependOn.toString();
+                     ControllerContext other = controller.getContext(iDependOn, null);
+                     if (other == null)
+                        actualStateString = "** NOT FOUND " + item.toHumanReadableString() + " **";
+                     else
+                     {
+                        actualState = other.getState();
+                        actualStateString = actualState.getStateString();
+                        if (actualState != null && actualState.equals(ControllerState.ERROR) == false)
+                        {
+                           ControllerState dependentState = item.getDependentState();
+                           if (dependentState == null)
+                              dependentState = ControllerState.INSTALLED;
+
+                           int dependentIndex = states.indexOf(dependentState);
+                           int actualIndex = states.indexOf(actualState);
+                           if (actualIndex >= dependentIndex)
+                              includeDependency = false;
+                        }
+                     }
                   }
+
+                  if (includeDependency)
+                  {
+                     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);
+                     }
+                  }
                }
-               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);

Modified: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/DeployersMainTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/DeployersMainTestSuite.java	2008-04-02 14:34:27 UTC (rev 71617)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/DeployersMainTestSuite.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -27,6 +27,7 @@
 import org.jboss.test.deployers.main.test.DeployerCheckCompleteTestCase;
 import org.jboss.test.deployers.main.test.DeployerSingleDeploymentTestCase;
 import org.jboss.test.deployers.main.test.DeployerIncompleteDeploymentsTestCase;
+import org.jboss.test.deployers.main.test.CycleCheckCompleteTestCase;
 
 /**
  * Deployers Main Test Suite.
@@ -47,6 +48,7 @@
       suite.addTest(DeployerSingleDeploymentTestCase.suite());
       suite.addTest(DeployerCheckCompleteTestCase.suite());
       suite.addTest(DeployerIncompleteDeploymentsTestCase.suite());
+      suite.addTest(CycleCheckCompleteTestCase.suite());
 
       return suite;
    }

Modified: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/AbstractTestAttachmentDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/AbstractTestAttachmentDeployer.java	2008-04-02 14:34:27 UTC (rev 71617)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/AbstractTestAttachmentDeployer.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -28,6 +28,7 @@
 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.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -55,17 +56,21 @@
       if (attachment != null)
       {
          Object name = attachment.getName();
-         AbstractControllerContext context = new AbstractControllerContext(name, actions);
+         ControllerContext context = controller.getContext(name, null);
+         if (context == null)
+            context = createControllerContext(name, actions);
+         
          DependencyInfo dependencyInfo = context.getDependencyInfo();
          Object dependency = attachment.getDependency();
          if (dependency != null)
          {
-            AbstractDependencyItem item = new AbstractDependencyItem(name, dependency, ControllerState.INSTALLED, null);
+            DependencyItem item = createDependencyItem(name, dependency);
             dependencyInfo.addIDependOn(item);
          }
          try
          {
-            controller.install(context);
+            if (attachment.isInstall())
+               controller.install(context);
          }
          catch (Throwable t)
          {
@@ -79,10 +84,21 @@
       TestAttachment attachment = unit.getAttachment(TestAttachment.class);
       if (attachment != null)
       {
-         controller.uninstall(attachment.getName());
+         if (attachment.isInstall())
+            controller.uninstall(attachment.getName());
       }
    }
 
+   protected ControllerContext createControllerContext(Object name, ControllerContextActions actions)
+   {
+      return new AbstractControllerContext(name, actions);
+   }
+
+   protected DependencyItem createDependencyItem(Object name, Object dependency)
+   {
+      return new AbstractDependencyItem(name, dependency, ControllerState.INSTALLED, null);
+   }
+
    private class TestControllerContextActions implements ControllerContextActions
    {
       public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable

Added: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedControllerContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedControllerContext.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedControllerContext.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -0,0 +1,66 @@
+/*
+* 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.main.support;
+
+import java.util.Set;
+
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.DependencyInfo;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OrderedControllerContext extends AbstractControllerContext
+{
+   private DependencyInfo orderedDependencyInfo = new OrderedDependencyInfo();
+
+   public OrderedControllerContext(Object name, ControllerContextActions actions)
+   {
+      super(name, actions);
+   }
+
+   public OrderedControllerContext(Object name, ControllerContextActions actions, DependencyInfo dependencies)
+   {
+      super(name, actions, dependencies);
+   }
+
+   public OrderedControllerContext(Object name, ControllerContextActions actions, DependencyInfo dependencies, Object target)
+   {
+      super(name, actions, dependencies, target);
+   }
+
+   public OrderedControllerContext(Object name, Set<Object> aliases, ControllerContextActions actions, DependencyInfo dependencies, Object target)
+   {
+      super(name, aliases, actions, dependencies, target);
+   }
+
+   public OrderedControllerContext(Object name, Object target)
+   {
+      super(name, target);
+   }
+
+   public DependencyInfo getDependencyInfo()
+   {
+      return orderedDependencyInfo;
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedDependencyInfo.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedDependencyInfo.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedDependencyInfo.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -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.main.support;
+
+import java.util.Set;
+import java.util.LinkedHashSet;
+
+import org.jboss.dependency.plugins.AbstractDependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OrderedDependencyInfo extends AbstractDependencyInfo
+{
+   private Set<DependencyItem> items = new LinkedHashSet<DependencyItem>();
+
+   public void addIDependOn(DependencyItem dependency)
+   {
+      super.addIDependOn(dependency);
+      items.add(dependency);
+   }
+
+   public void removeIDependOn(DependencyItem dependency)
+   {
+      super.removeIDependOn(dependency);
+      items.remove(dependency);
+   }
+
+   public Set<DependencyItem> getUnresolvedDependencies()
+   {
+      return items;
+   }
+
+   public boolean resolveDependencies(Controller controller, ControllerState state)
+   {
+      boolean resolved = true;
+      if (items.isEmpty() == false)
+      {
+         for (DependencyItem item : items)
+         {
+            if (state.equals(item.getWhenRequired()) && item.resolve(controller) == false)
+            {
+               resolved = false;
+               break;
+            }
+         }
+      }
+      return resolved;
+   }
+}

Copied: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedTestAttachmentDeployer.java (from rev 71587, projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachmentDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedTestAttachmentDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/OrderedTestAttachmentDeployer.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -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.main.support;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.DependencyItem;
+
+/**
+ * Test attachments deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OrderedTestAttachmentDeployer extends TestAttachmentDeployer
+{
+   public OrderedTestAttachmentDeployer(Controller controller)
+   {
+      super(controller);
+   }
+
+   protected ControllerContext createControllerContext(Object name, ControllerContextActions actions)
+   {
+      return new OrderedControllerContext(name, actions);
+   }
+
+   protected DependencyItem createDependencyItem(Object name, Object dependency)
+   {
+      TestDemandDependencyItem item = new TestDemandDependencyItem(name);
+//      TestDemandDependencyItem item = new TestDemandDependencyItem(name, dependency);
+      item.setDemand(dependency);
+      return item;
+   }
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java	2008-04-02 14:34:27 UTC (rev 71617)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -32,11 +32,18 @@
 
    private Object name;
    private Object dependency;
+   private boolean install;
 
    public TestAttachment(Object name, Object dependency)
    {
+      this(name, dependency, true);
+   }
+
+   public TestAttachment(Object name, Object dependency, boolean install)
+   {
       this.name = name;
       this.dependency = dependency;
+      this.install = install;
    }
 
    public Object getName()
@@ -48,4 +55,9 @@
    {
       return dependency;
    }
+
+   public boolean isInstall()
+   {
+      return install;
+   }
 }

Added: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestDemandDependencyItem.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestDemandDependencyItem.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestDemandDependencyItem.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -0,0 +1,99 @@
+/*
+* 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.main.support;
+
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestDemandDependencyItem extends AbstractDependencyItem
+{
+   private Object demand;
+
+   public TestDemandDependencyItem(Object name)
+   {
+      this(name, null);
+   }
+
+   public TestDemandDependencyItem(Object name, Object demand)
+   {
+      super(name, demand, ControllerState.INSTALLED, null);
+   }
+
+   public Object getDemand()
+   {
+      return demand;
+   }
+
+   public void setDemand(Object demand)
+   {
+      this.demand = demand;
+   }
+
+   public boolean resolve(Controller controller)
+   {
+      Object name = getDemand();
+      ControllerContext context = controller.getInstalledContext(name);
+      if (context != null)
+      {
+         setIDependOn(context.getName());
+         addDependsOnMe(controller, context);
+         setResolved(true);
+      }
+      else
+      {
+         setResolved(false);
+      }
+      return isResolved();
+   }
+
+   @Override
+   public void unresolved()
+   {
+      setIDependOn(null);
+      setResolved(false);
+   }
+
+   public void toString(JBossStringBuilder buffer)
+   {
+      super.toString(buffer);
+      buffer.append(" demand=").append(getDemand());
+   }
+
+   public void toShortString(JBossStringBuilder buffer)
+   {
+      buffer.append(getName()).append(" demands ").append(getDemand());
+   }
+
+   @Override
+   public String toHumanReadableString()
+   {
+      StringBuilder builder = new StringBuilder();
+      builder.append("Demands '").append(getDemand()).append("'");
+      return builder.toString();
+   }
+}

Copied: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/CycleCheckCompleteTestCase.java (from rev 71479, projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/CycleCheckCompleteTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/CycleCheckCompleteTestCase.java	2008-04-02 15:03:23 UTC (rev 71618)
@@ -0,0 +1,131 @@
+/*
+* 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.main.test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Test;
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+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.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.plugins.main.MainDeployerImpl;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.test.deployers.main.support.OrderedTestAttachmentDeployer;
+import org.jboss.test.deployers.main.support.TestAttachment;
+import org.jboss.test.deployers.main.support.TestAttachments;
+import org.jboss.test.deployers.main.support.TestAttachmentsDeployer;
+
+/**
+ * Check for cycles.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CycleCheckCompleteTestCase extends AbstractMainDeployerTest
+{
+   public CycleCheckCompleteTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(CycleCheckCompleteTestCase.class);
+   }
+
+   public void testOtherAsCause() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment dA = createSimpleDeployment("A");
+      addAttachment(dA, "xB", true);
+      addAttachment(dA, "xC", false);
+
+      Deployment dB = createSimpleDeployment("B");
+      addAttachment(dB, "xA", true);
+      addAttachment(dB, "xC", false);
+      addAttachment(dB, "xD", false);
+
+      Deployment dC = createSimpleDeployment("C");
+      addAttachment(dC, null, true);
+
+      Deployment dD = createSimpleDeployment("D");
+      addAttachment(dD, null, true);
+
+      try
+      {
+         main.deploy(dA, dB, dC, dD);
+         fail("Should not be here.");
+      }
+      catch (DeploymentException e)
+      {
+         IncompleteDeploymentException ide = assertInstanceOf(e, IncompleteDeploymentException.class);
+         ide.printStackTrace();
+         IncompleteDeployments id = ide.getIncompleteDeployments();
+         assertNotNull(id);
+         assertEmpty(id.getDeploymentsInError());
+         assertEmpty(id.getDeploymentsMissingDeployer());
+         assertEmpty(id.getContextsInError());
+         Map<String,Set<MissingDependency>> map = id.getContextsMissingDependencies();
+         assertNotNull(map);
+         assertEquals(new HashSet<String>(Arrays.asList("xA", "xB")), map.keySet());
+      }
+   }
+
+   protected void assertEmpty(Map<?, ?> map)
+   {
+      assertNotNull(map);
+      assertEmpty(map.keySet());
+   }
+
+   protected DeployerClient getMainDeployer()
+   {
+      MainDeployerImpl main = new MainDeployerImpl();
+      main.setStructuralDeployers(createStructuralDeployers());
+      AbstractController controller = new AbstractController();
+      DeployersImpl deployers = new DeployersImpl(controller);
+      deployers.addDeployer(new TestAttachmentsDeployer());
+      deployers.addDeployer(new OrderedTestAttachmentDeployer(controller));
+      main.setDeployers(deployers);
+      return main;
+   }
+
+   protected void addAttachment(Deployment deployment, Object dependency, boolean install)
+   {
+      MutableAttachments mutableAttachments = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+      TestAttachments testAttachments = mutableAttachments.getAttachment(TestAttachments.class);
+      if (testAttachments == null)
+      {
+         testAttachments = new TestAttachments();
+         mutableAttachments.addAttachment(TestAttachments.class, testAttachments);
+      }
+      TestAttachment testAttachment = new TestAttachment("x" + deployment.getName(), dependency, install);
+      testAttachments.addAttachment(testAttachment);
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list