[jboss-cvs] JBossAS SVN: r90330 - in projects/jboss-deployers/trunk: 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
Wed Jun 17 10:08:46 EDT 2009


Author: jaikiran
Date: 2009-06-17 10:08:46 -0400 (Wed, 17 Jun 2009)
New Revision: 90330

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/
   projects/jboss-deployers/trunk/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/test/
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/RealDeployerWithInputTestCase.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExtendedDeploymentVisitor.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/RealDeployerWithInput.java
Log:
JBDEPLOY-193 A new ExtendedDeploymentVisitor which can be used to filter deployers based on the name of the attachment and the type of the attachment they are interested in

Added: projects/jboss-deployers/trunk/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	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/support/MockExtendedDeploymentVisitor.java	2009-06-17 14:08:46 UTC (rev 90330)
@@ -0,0 +1,99 @@
+/*
+ * 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.ExtendedDeploymentVisitor;
+import org.jboss.deployers.spi.deployer.helpers.RealDeployerWithInput;
+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 RealDeployerWithInput}
+ * 
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MockExtendedDeploymentVisitor<T> implements ExtendedDeploymentVisitor<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;
+   }
+   
+   /**
+    * @see ExtendedDeploymentVisitor#getVisitorTypeName()
+    */
+   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 ExtendedDeploymentVisitor#getVisitorType()
+    */
+   public Class<T> getVisitorType()
+   {
+      return this.type;
+   }
+
+   public void undeploy(DeploymentUnit unit, T deployment)
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+}

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/RealDeployerWithInputTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/RealDeployerWithInputTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/helpers/test/RealDeployerWithInputTestCase.java	2009-06-17 14:08:46 UTC (rev 90330)
@@ -0,0 +1,162 @@
+/*
+ * 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 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.ExtendedDeploymentVisitor;
+import org.jboss.deployers.spi.deployer.helpers.RealDeployerWithInput;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.helpers.support.MockExtendedDeploymentVisitor;
+
+/**
+ * RealDeployerWithInputTestCase
+ * 
+ * Test that the {@link RealDeployerWithInput} works as expected
+ * with an {@link ExtendedDeploymentVisitor}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class RealDeployerWithInputTestCase extends AbstractDeployerTest
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(RealDeployerWithInputTestCase.class);
+
+   /**
+    * Constructor
+    * 
+    * @param name
+    */
+   public RealDeployerWithInputTestCase(String name)
+   {
+      super(name);
+
+   }
+
+   /**
+    * Tests that the {@link RealDeployerWithInput} works correctly with an {@link ExtendedDeploymentVisitor}
+    * when the unit being processed contains the expected attachment
+    * 
+    * @throws Exception
+    */
+   public void testExtendedDeploymentVisitorForUnitContainingExpectedAttachment() throws Exception
+   {
+      // the attachment name which the visitor is interested in
+      String attachmentName = "someAttachment";
+      // create an mock visitor 
+      ExtendedDeploymentVisitor<String> visitor = new MockExtendedDeploymentVisitor<String>(attachmentName,
+            String.class);
+      // create the real deployer which will then use the visitor to filter out 
+      // deployment units
+      RealDeployerWithInput<String> deployer = new RealDeployerWithInput<String>(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();
+      
+      // I seriously have no idea about how the setInput()/setInputs()/addInput() API expect/work
+      // The more i look into it, the more confused i am.
+      // For some weird reason, this is expected to be done.
+      attachments.addAttachment(String.class.getName(), "IHaveNoClueWhyTheSetInputAPIWorksTheWayItDoes");
+      
+      // add the attachment so that this unit will be picked up by the visitor
+      attachments.addAttachment(attachmentName, new String("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(ExtendedDeploymentVisitor.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 RealDeployerWithInput} works correctly with an {@link ExtendedDeploymentVisitor}
+    * when the unit being processed does *not* contain the expected attachment
+    * 
+    * @throws Exception
+    */
+   public void testExtendedDeploymentVisitorForWithoutExpectedAttachment() throws Exception
+   {
+      // the attachment name which the visitor is interested in
+      String attachmentName = "someAttachment";
+      // create an mock visitor 
+      ExtendedDeploymentVisitor<String> visitor = new MockExtendedDeploymentVisitor<String>(attachmentName,
+            String.class);
+      // create the real deployer which will then use the visitor to filter out 
+      // deployment units
+      RealDeployerWithInput<String> deployer = new RealDeployerWithInput<String>(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();
+
+      // I seriously have no idea about how the setInput()/setInputs()/addInput() API expect/work
+      // The more i look into it, the more confused i am.
+      // For some weird reason, this is expected to be done.
+      attachments.addAttachment(String.class.getName(), "IHaveNoClueWhyTheSetInputAPIWorksTheWayItDoes");
+
+      
+      // add the attachment which the visitor is NOT interested in
+      attachments.addAttachment("ADifferentAttachment", new String("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(ExtendedDeploymentVisitor.class.getName() + " did not process the unit " + unit, unit
+            .getAttachment(MockExtendedDeploymentVisitor.PROCESSED_ATTACHMENT_NAME));
+
+   }
+
+}

Added: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExtendedDeploymentVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExtendedDeploymentVisitor.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ExtendedDeploymentVisitor.java	2009-06-17 14:08:46 UTC (rev 90330)
@@ -0,0 +1,55 @@
+/*
+ * 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.deployers.spi.deployer.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * ExtendedDeploymentVisitor
+ *
+ * Extended version of the {@link DeploymentVisitor} which allows to filter
+ * out eligible unit based on the name of the attachments. The {@link #getVisitorTypeName()}
+ * and {@link #getVisitorType()} decide which units are eligible for being 
+ * processed by this visitor.
+ * 
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ * @param <T>
+ */
+public interface ExtendedDeploymentVisitor<T> extends DeploymentVisitor<T>
+{
+
+   /**
+    * Returns the name of attachment in the deployment unit, which this
+    * visitor is interested in processing.<br>
+    *  
+    * This along with the {@link #getVisitorType()} will be used to check
+    * whether an {@link DeploymentUnit} is eligible to be processed by this {@link DeploymentVisitor}.
+    * If the unit contains a attachment with {@link #getVisitorTypeName()} of type {@link #getVisitorType()}
+    * then that unit is considered eligible to be passed to this {@link DeploymentVisitor}. 
+    * 
+    * @return 
+    */
+   String getVisitorTypeName();
+
+}

Added: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/RealDeployerWithInput.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/RealDeployerWithInput.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/RealDeployerWithInput.java	2009-06-17 14:08:46 UTC (rev 90330)
@@ -0,0 +1,175 @@
+/*
+ * 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;
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * RealDeployerWithInput - 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 ExtendedDeploymentVisitor}.
+ * <br>
+ * This deployer uses the {@link ExtendedDeploymentVisitor} to filter out deployers
+ * for processing the units. It internally relies on {@link ExtendedDeploymentVisitor#getVisitorType()}
+ * and {@link ExtendedDeploymentVisitor#getVisitorTypeName()} to decide whether the deployer
+ * is eligible for processing the unit. See {@link #deploy(DeploymentUnit, ExtendedDeploymentVisitor)}
+ * and {@link #undeploy(DeploymentUnit, ExtendedDeploymentVisitor)} 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
+ * @version $Revision: $
+ */
+public class RealDeployerWithInput<T> extends AbstractRealDeployer
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(RealDeployerWithInput.class);
+
+   /**
+    * Visitor which will be used for processing the deployment unit
+    */
+   private ExtendedDeploymentVisitor<T> visitor;
+
+   /**
+    * Constructor
+    * @param visitor
+    */
+   public RealDeployerWithInput(ExtendedDeploymentVisitor<T> visitor)
+   {
+      this.visitor = visitor;
+      // set the input for this deployer
+      setInput(visitor.getVisitorType());
+   }
+   
+   /**
+    * Returns the {@link ExtendedDeploymentVisitor} associated with this deployer
+    * @return
+    */
+   public ExtendedDeploymentVisitor<T> getDeploymentVisitor()
+   {
+      return this.visitor;
+   }
+
+   @Override
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      deploy(unit, this.visitor);
+
+   }
+
+   /**
+    * First checks whether the <code>visitor</code> is eligible for
+    * processing the <code>unit</code>. The {@link ExtendedDeploymentVisitor#getVisitorTypeName()}
+    * and {@link ExtendedDeploymentVisitor#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 visitorTypeName 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 ExtendedDeploymentVisitor#deploy(DeploymentUnit, Object)} API
+    * 
+    * 
+    * @param unit The deployment unit being processed
+    * @param visitor The visitor which will be checked for eligibility for processing the unit
+    *                  based on the {@link ExtendedDeploymentVisitor#getVisitorTypeName()} and
+    *                  {@link ExtendedDeploymentVisitor#getVisitorType()} values
+    *                  
+    * @throws DeploymentException If any exception occurs during deployment
+    * @throws NullPointerException If either of <code>unit</code> or <code>visitor</code> is null
+    */
+   protected void deploy(DeploymentUnit unit, ExtendedDeploymentVisitor<T> visitor) throws DeploymentException
+   {
+      // get hold of the attachment based on the visitorTypeName and visitorType
+      String attachmentName = visitor.getVisitorTypeName();
+      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 (logger.isTraceEnabled())
+         {
+            logger.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 {@link ExtendedDeploymentVisitor#getVisitorTypeName()}
+    * and {@link ExtendedDeploymentVisitor#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 visitorTypeName 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 ExtendedDeploymentVisitor#deploy(DeploymentUnit, Object)} API
+
+    * @param unit The deployment unit to be processed
+    * @param visitor The visitor which will be checked for eligibility for processing the unit
+    *                  based on the {@link ExtendedDeploymentVisitor#getVisitorTypeName()} and
+    *                  {@link ExtendedDeploymentVisitor#getVisitorType()} values
+    *                  
+    * @throws DeploymentException If any exception occurs during deployment
+    * @throws NullPointerException If either of <code>unit</code> or <code>visitor</code> is null
+    */
+   protected void undeploy(DeploymentUnit unit, ExtendedDeploymentVisitor<T> visitor) throws DeploymentException
+   {
+      // get hold of the attachment based on the visitorTypeName and visitorType
+      String attachmentName = visitor.getVisitorTypeName();
+      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 (logger.isTraceEnabled())
+         {
+            logger.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