[jboss-cvs] JBossAS SVN: r90402 - in projects/jboss-deployers/branches/Branch_2_0: deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 18 05:22:14 EDT 2009


Author: alesj
Date: 2009-06-18 05:22:14 -0400 (Thu, 18 Jun 2009)
New Revision: 90402

Added:
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExactAttachmentDeployerWithVisitor.java
Removed:
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java
Modified:
   projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java
Log:
Port Jaikiran's patch.

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java	2009-06-18 09:03:01 UTC (rev 90401)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java	2009-06-18 09:22:14 UTC (rev 90402)
@@ -37,6 +37,7 @@
 import org.jboss.test.deployers.deployer.test.HeuristicAllOrNothingUnitTestCase;
 import org.jboss.test.deployers.deployer.test.HeuristicRussionDollUnitTestCase;
 import org.jboss.test.deployers.deployer.test.MultipleComponentTypeUnitTestCase;
+import org.jboss.test.deployers.deployer.helpers.test.ExactAttachmentDeployerWithVisitorTestCase;
 
 /**
  * Deployers Deployer Test Suite.
@@ -68,6 +69,9 @@
       suite.addTest(DeployerContextClassLoaderUnitTestCase.suite());
       suite.addTest(DeployerRequiredStageUnitTestCase.suite());
 
+      // helper deployers
+      suite.addTest(ExactAttachmentDeployerWithVisitorTestCase.suite());
+
       return suite;
    }
 }

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers (from rev 90401, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers)

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support (from rev 90401, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support)

Deleted: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java	2009-06-18 09:03:01 UTC (rev 90401)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java	2009-06-18 09:22:14 UTC (rev 90402)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.deployer.helpers.support;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.logging.Logger;
-
-/**
- * MockExtendedDeploymentVisitor
- * 
- * A mock implementation of {@link ExtendedDeploymentVisitor}, to be used in testing
- * the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor}
- * 
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class MockExtendedDeploymentVisitor<T> implements DeploymentVisitor<T>
-{
-   private String typeName;
-   
-   private Class<T> type;
-   
-   public static final String PROCESSED_ATTACHMENT_NAME = "Processed";
-   
-   private static Logger logger = Logger.getLogger(MockExtendedDeploymentVisitor.class);
-   
-   public MockExtendedDeploymentVisitor(String typeName, Class<T> type)
-   {
-      this.type = type;
-      this.typeName = typeName;
-   }
-   
-   public String getVisitorTypeName()
-   {
-      return this.typeName;
-   }
-
-   /**
-    * Just a mock implementation which adds a counter as an attachment to the unit
-    * to indicate the number of times this visitor has processed the unit
-    */
-   public void deploy(DeploymentUnit unit, T deployment) throws DeploymentException
-   {
-      logger.info("Processing unit " + unit + " for deployment " + deployment);
-      // if the unit has already been processed by this visitor then increment the count in the
-      // attachment
-      Integer count = unit.getAttachment(PROCESSED_ATTACHMENT_NAME, Integer.class);
-      if (count == null)
-      {
-         count = 0;
-      }
-      count ++;
-      unit.addAttachment(PROCESSED_ATTACHMENT_NAME, count);
-   }
-
-   /**
-    * @see DeploymentVisitor#getVisitorType()
-    */
-   public Class<T> getVisitorType()
-   {
-      return this.type;
-   }
-
-   public void undeploy(DeploymentUnit unit, T deployment)
-   {
-   }
-}

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java (from rev 90401, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java	2009-06-18 09:22:14 UTC (rev 90402)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.deployer.helpers.support;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+
+/**
+ * MockExtendedDeploymentVisitor
+ * 
+ * A mock implementation of {@link ExtendedDeploymentVisitor}, to be used in testing
+ * the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor}
+ * 
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MockExtendedDeploymentVisitor<T> implements DeploymentVisitor<T>
+{
+   private String typeName;
+   
+   private Class<T> type;
+   
+   public static final String PROCESSED_ATTACHMENT_NAME = "Processed";
+   
+   private static Logger logger = Logger.getLogger(MockExtendedDeploymentVisitor.class);
+   
+   public MockExtendedDeploymentVisitor(String typeName, Class<T> type)
+   {
+      this.type = type;
+      this.typeName = typeName;
+   }
+   
+   public String getVisitorTypeName()
+   {
+      return this.typeName;
+   }
+
+   /**
+    * Just a mock implementation which adds a counter as an attachment to the unit
+    * to indicate the number of times this visitor has processed the unit
+    */
+   public void deploy(DeploymentUnit unit, T deployment) throws DeploymentException
+   {
+      logger.info("Processing unit " + unit + " for deployment " + deployment);
+      // if the unit has already been processed by this visitor then increment the count in the
+      // attachment
+      Integer count = unit.getAttachment(PROCESSED_ATTACHMENT_NAME, Integer.class);
+      if (count == null)
+      {
+         count = 0;
+      }
+      count ++;
+      unit.addAttachment(PROCESSED_ATTACHMENT_NAME, count);
+   }
+
+   /**
+    * @see DeploymentVisitor#getVisitorType()
+    */
+   public Class<T> getVisitorType()
+   {
+      return this.type;
+   }
+
+   public void undeploy(DeploymentUnit unit, T deployment)
+   {
+   }
+}

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test (from rev 90401, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test)

Deleted: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java	2009-06-18 09:03:01 UTC (rev 90401)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java	2009-06-18 09:22:14 UTC (rev 90402)
@@ -1,147 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.deployer.helpers.test;
-
-import junit.framework.Test;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.spi.attachments.MutableAttachments;
-import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
-import org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.test.deployers.AbstractDeployerTest;
-import org.jboss.test.deployers.deployer.helpers.support.MockExtendedDeploymentVisitor;
-
-/**
- * ExactAttachmentDeployerWithVisitorTestCase
- * 
- * Test that the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor} works as expected
- * with an {@link DeploymentVisitor}
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class ExactAttachmentDeployerWithVisitorTestCase extends AbstractDeployerTest
-{
-   /**
-    * Constructor
-    * 
-    * @param name the name
-    */
-   public ExactAttachmentDeployerWithVisitorTestCase(String name)
-   {
-      super(name);
-   }
-
-   public static Test suite()
-   {
-      return suite(ExactAttachmentDeployerWithVisitorTestCase.class);
-   }
-
-   /**
-    * Tests that the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor} works correctly with an {@link ExtendedDeploymentVisitor}
-    * when the unit being processed contains the expected attachment
-    * 
-    * @throws Exception for any error
-    */
-   public void testExtendedDeploymentVisitorForUnitContainingExpectedAttachment() throws Exception
-   {
-      // the attachment name which the visitor is interested in
-      String attachmentName = "someAttachment";
-      // create an mock visitor 
-      MockExtendedDeploymentVisitor<String> visitor = new MockExtendedDeploymentVisitor<String>(attachmentName, String.class);
-      // create the real deployer which will then use the visitor to filter out 
-      // deployment units
-      ExactAttachmentDeployerWithVisitor<String> deployer = new ExactAttachmentDeployerWithVisitor<String>(visitor.getVisitorTypeName(), visitor);
-      // Create the main deployer which will be responsible for processing the deployment
-      // unit through various stages
-      DeployerClient mainDeployer = createMainDeployer(deployer);
-
-      // some name to the deployment and create a deployment out of it
-      String deploymentName = "test-deployment";
-      Deployment deployment = createSimpleDeployment(deploymentName);
-      MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
-      
-      // Jaikiran's deleted comment ;-)
-      attachments.addAttachment(String.class.getName(), "IHaveNoClueWhyTheSetInputAPIWorksTheWayItDoes");
-      
-      // add the attachment so that this unit will be picked up by the visitor
-      attachments.addAttachment(attachmentName, "Test123");
-
-      log.debug("Deploying " + deployment);
-      // deploy the deployment
-      mainDeployer.deploy(deployment);
-
-      // get the processed deployment unit
-      DeploymentUnit unit = getDeploymentUnit(mainDeployer, deploymentName);
-
-      // the processed unit is expected to contain the "processed" attachment which
-      // is added by the mock visitor. This attachment indicates that the unit was
-      // rightly picked up by the visitor
-      assertNotNull(DeploymentVisitor.class.getName() + " did not process the unit " + unit, unit.getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME));
-      // ensure that the unit was picked up only once by the visitor
-      assertEquals("The extended deployment visitor was expected to process the unit " + unit + " exactly once", unit.getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME), 1);
-   }
-
-   /**
-    * Tests that the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor} works correctly with an {@link DeploymentVisitor}
-    * when the unit being processed does *not* contain the expected attachment
-    * 
-    * @throws Exception for any error
-    */
-   public void testExtendedDeploymentVisitorForWithoutExpectedAttachment() throws Exception
-   {
-      // the attachment name which the visitor is interested in
-      String attachmentName = "someAttachment";
-      // create an mock visitor 
-      MockExtendedDeploymentVisitor<String> visitor = new MockExtendedDeploymentVisitor<String>(attachmentName, String.class);
-      // create the real deployer which will then use the visitor to filter out 
-      // deployment units
-      ExactAttachmentDeployerWithVisitor<String> deployer = new ExactAttachmentDeployerWithVisitor<String>(visitor.getVisitorTypeName(), visitor);
-      // Create the main deployer which will be responsible for processing the deployment
-      // unit through various stages
-      DeployerClient mainDeployer = createMainDeployer(deployer);
-
-      // some name to the deployment and create a deployment out of it
-      String deploymentName = "test-deployment";
-      Deployment deployment = createSimpleDeployment(deploymentName);
-      MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
-
-      // Jaikiran's deleted comment ;-)
-      attachments.addAttachment(String.class.getName(), "IHaveNoClueWhyTheSetInputAPIWorksTheWayItDoes");
-      
-      // add the attachment which the visitor is NOT interested in
-      attachments.addAttachment("ADifferentAttachment", "Test123");
-
-      log.debug("Deploying " + deployment);
-      // deploy the deployment
-      mainDeployer.deploy(deployment);
-
-      // get the processed deployment unit
-      DeploymentUnit unit = getDeploymentUnit(mainDeployer, deploymentName);
-
-      // its expected that the visitor will NOT process this unit, since the
-      // unit does not contain the expected attachment
-      assertNull(DeploymentVisitor.class.getName() + " did not process the unit " + unit, unit.getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME));
-   }
-}

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java (from rev 90401, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/ExactAttachmentDeployerWithVisitorTestCase.java	2009-06-18 09:22:14 UTC (rev 90402)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.deployer.helpers.test;
+
+import junit.framework.Test;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
+import org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.helpers.support.MockExtendedDeploymentVisitor;
+
+/**
+ * ExactAttachmentDeployerWithVisitorTestCase
+ * 
+ * Test that the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor} works as expected
+ * with an {@link DeploymentVisitor}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ExactAttachmentDeployerWithVisitorTestCase extends AbstractDeployerTest
+{
+   /**
+    * Constructor
+    * 
+    * @param name the name
+    */
+   public ExactAttachmentDeployerWithVisitorTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(ExactAttachmentDeployerWithVisitorTestCase.class);
+   }
+
+   /**
+    * Tests that the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor} works correctly with an {@link ExtendedDeploymentVisitor}
+    * when the unit being processed contains the expected attachment
+    * 
+    * @throws Exception for any error
+    */
+   public void testExtendedDeploymentVisitorForUnitContainingExpectedAttachment() throws Exception
+   {
+      // the attachment name which the visitor is interested in
+      String attachmentName = "someAttachment";
+      // create an mock visitor 
+      MockExtendedDeploymentVisitor<String> visitor = new MockExtendedDeploymentVisitor<String>(attachmentName, String.class);
+      // create the real deployer which will then use the visitor to filter out 
+      // deployment units
+      ExactAttachmentDeployerWithVisitor<String> deployer = new ExactAttachmentDeployerWithVisitor<String>(visitor.getVisitorTypeName(), visitor);
+      // Create the main deployer which will be responsible for processing the deployment
+      // unit through various stages
+      DeployerClient mainDeployer = createMainDeployer(deployer);
+
+      // some name to the deployment and create a deployment out of it
+      String deploymentName = "test-deployment";
+      Deployment deployment = createSimpleDeployment(deploymentName);
+      MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
+      
+      // Jaikiran's deleted comment ;-)
+      attachments.addAttachment(String.class.getName(), "IHaveNoClueWhyTheSetInputAPIWorksTheWayItDoes");
+      
+      // add the attachment so that this unit will be picked up by the visitor
+      attachments.addAttachment(attachmentName, "Test123");
+
+      log.debug("Deploying " + deployment);
+      // deploy the deployment
+      mainDeployer.deploy(deployment);
+
+      // get the processed deployment unit
+      DeploymentUnit unit = getDeploymentUnit(mainDeployer, deploymentName);
+
+      // the processed unit is expected to contain the "processed" attachment which
+      // is added by the mock visitor. This attachment indicates that the unit was
+      // rightly picked up by the visitor
+      assertNotNull(DeploymentVisitor.class.getName() + " did not process the unit " + unit, unit.getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME));
+      // ensure that the unit was picked up only once by the visitor
+      assertEquals("The extended deployment visitor was expected to process the unit " + unit + " exactly once", unit.getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME), 1);
+   }
+
+   /**
+    * Tests that the {@link org.jboss.deployers.spi.deployer.helpers.ExactAttachmentDeployerWithVisitor} works correctly with an {@link DeploymentVisitor}
+    * when the unit being processed does *not* contain the expected attachment
+    * 
+    * @throws Exception for any error
+    */
+   public void testExtendedDeploymentVisitorForWithoutExpectedAttachment() throws Exception
+   {
+      // the attachment name which the visitor is interested in
+      String attachmentName = "someAttachment";
+      // create an mock visitor 
+      MockExtendedDeploymentVisitor<String> visitor = new MockExtendedDeploymentVisitor<String>(attachmentName, String.class);
+      // create the real deployer which will then use the visitor to filter out 
+      // deployment units
+      ExactAttachmentDeployerWithVisitor<String> deployer = new ExactAttachmentDeployerWithVisitor<String>(visitor.getVisitorTypeName(), visitor);
+      // Create the main deployer which will be responsible for processing the deployment
+      // unit through various stages
+      DeployerClient mainDeployer = createMainDeployer(deployer);
+
+      // some name to the deployment and create a deployment out of it
+      String deploymentName = "test-deployment";
+      Deployment deployment = createSimpleDeployment(deploymentName);
+      MutableAttachments attachments = (MutableAttachments) deployment.getPredeterminedManagedObjects();
+
+      // Jaikiran's deleted comment ;-)
+      attachments.addAttachment(String.class.getName(), "IHaveNoClueWhyTheSetInputAPIWorksTheWayItDoes");
+      
+      // add the attachment which the visitor is NOT interested in
+      attachments.addAttachment("ADifferentAttachment", "Test123");
+
+      log.debug("Deploying " + deployment);
+      // deploy the deployment
+      mainDeployer.deploy(deployment);
+
+      // get the processed deployment unit
+      DeploymentUnit unit = getDeploymentUnit(mainDeployer, deploymentName);
+
+      // its expected that the visitor will NOT process this unit, since the
+      // unit does not contain the expected attachment
+      assertNull(DeploymentVisitor.class.getName() + " did not process the unit " + unit, unit.getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME));
+   }
+}

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExactAttachmentDeployerWithVisitor.java (from rev 90401, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExactAttachmentDeployerWithVisitor.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExactAttachmentDeployerWithVisitor.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExactAttachmentDeployerWithVisitor.java	2009-06-18 09:22:14 UTC (rev 90402)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.spi.deployer.helpers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * A deployer which by default is set to process
+ * deployments during the {@link DeploymentStages#REAL} phase. This deployer
+ * is similar to {@link AbstractRealDeployerWithInput} except that, this one 
+ * is more efficient when used with a {@link DeploymentVisitor}.
+ * <br>
+ * This deployer uses the {@link DeploymentVisitor} to filter out deployers
+ * for processing the units. It internally relies on {@link DeploymentVisitor#getVisitorType()}
+ * and exact attachment name to decide whether the deployer
+ * is eligible for processing the unit. See {@link #deploy(DeploymentUnit)}
+ * and {@link #undeploy(DeploymentUnit)} for more details about this deployer.
+ * 
+ * Note that the deployment stage for this deployer can be changed by invoking 
+ * {@link #setStage(org.jboss.deployers.spi.deployer.DeploymentStage)} during the construction of the 
+ * deployer
+ * 
+ * @author Jaikiran Pai
+ * @author Ales Justin
+ * @version $Revision: $
+ */
+public class ExactAttachmentDeployerWithVisitor<T> extends AbstractRealDeployer
+{
+   /** The attachment name */
+   private String attachmentName;
+
+   /**
+    * Visitor which will be used for processing the deployment unit
+    */
+   private DeploymentVisitor<T> visitor;
+
+   /**
+    * Constructor.
+    *
+    * @param attachmentName the attachment name
+    * @param visitor the visitor
+    */
+   public ExactAttachmentDeployerWithVisitor(String attachmentName, DeploymentVisitor<T> visitor)
+   {
+      if (attachmentName == null)
+         throw new IllegalArgumentException("Null attachment name");
+      if (visitor == null)
+         throw new IllegalArgumentException("Null visitor");
+
+      this.attachmentName = attachmentName;
+      this.visitor = visitor;
+      // set the input for this deployer
+      setInput(visitor.getVisitorType());
+   }
+
+   /**
+    * First checks whether the <code>visitor</code> is eligible for
+    * processing the <code>unit</code>. The attachmentName
+    * and {@link DeploymentVisitor#getVisitorType()} APIs are used to decide whether
+    * the unit is eligible to be processed by the visitor. If the unit contains an attachment with
+    * the attachmentName and of type visitorType, then the visitor is considered
+    * valid for this deployment unit. Eligible visitor are then allowed to process
+    * the unit by calling the {@link DeploymentVisitor#deploy(DeploymentUnit, Object)} API
+    *
+    *
+    * @param unit The deployment unit being processed
+    * @throws DeploymentException If any exception occurs during deployment
+    */
+   @Override
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      Class<T> attachmentType = visitor.getVisitorType();
+      T attachment = unit.getAttachment(attachmentName, attachmentType);
+
+      // no such attachment, so let's skip this visitor for this unit
+      if (attachment == null)
+      {
+         if (log.isTraceEnabled())
+         {
+            log.trace("Skipping " + visitor + " during deploy, since no attachment named " + attachmentName
+                  + " of type " + attachmentType + " found in unit " + unit);
+         }
+         return;
+      }
+
+      // attachment found, let the visitor process this unit
+      visitor.deploy(unit, attachment);
+   }
+
+   /**
+    * 
+    * First checks whether the <code>visitor</code> is eligible for
+    * processing the <code>unit</code>. The attchmentName
+    * and {@link DeploymentVisitor#getVisitorType()} APIs are used to decide whether
+    * the unit is eligible to be processed by the visitor. If the unit contains an attachment with 
+    * the attachmentName and of type visitorType, then the visitor is considered
+    * valid for this deployment unit. Eligible visitor are then allowed to process
+    * the unit by calling the {@link DeploymentVisitor#deploy(DeploymentUnit, Object)} API
+
+    * @param unit The deployment unit to be processed
+    */
+   protected void internalUndeploy(DeploymentUnit unit)
+   {
+      Class<T> attachmentType = visitor.getVisitorType();
+      T attachment = unit.getAttachment(attachmentName, attachmentType);
+
+      // no such attachment, so let's skip this visitor for this unit
+      if (attachment == null)
+      {
+         if (log.isTraceEnabled())
+         {
+            log.trace("Skipping " + visitor + " during undeploy, since no attachment named " + attachmentName
+                  + " of type " + attachmentType + " found in unit " + unit);
+         }
+         return;
+      }
+
+      // attachment found, let the visitor process this unit
+      visitor.undeploy(unit, attachment);
+   }
+}




More information about the jboss-cvs-commits mailing list