[jboss-cvs] JBossAS SVN: r59322 - in projects/microcontainer/branches/2_0/deployers/src: main/org/jboss/deployers/spi main/org/jboss/deployers/spi/managed tests/org/jboss/test/deployers tests/org/jboss/test/deployers/managed tests/org/jboss/test/deployers/managed/support tests/org/jboss/test/deployers/managed/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 3 21:44:16 EST 2007


Author: scott.stark at jboss.org
Date: 2007-01-03 21:44:11 -0500 (Wed, 03 Jan 2007)
New Revision: 59322

Added:
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/managed/
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/managed/ManagedObjectBuilder.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/ManagedTestSuite.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestFields.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/test/
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
Log:
Merge deployer/managed object changes from trunk

Added: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/managed/ManagedObjectBuilder.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/managed/ManagedObjectBuilder.java	2007-01-04 02:42:21 UTC (rev 59321)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/managed/ManagedObjectBuilder.java	2007-01-04 02:44:11 UTC (rev 59322)
@@ -0,0 +1,58 @@
+/*
+* 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.spi.managed;
+
+import java.util.Map;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.managed.api.ManagedObject;
+
+/**
+ * ManagedObjectBuilder.
+ * 
+ * TODO Critique
+ *      Rather having the contexts create the managed objects directly
+ *      they should provide the underlying metadata, e.g. the Fields + other information
+ *      from which we can create the managed object.
+ *      This is important because it is likely that multiple builders/deployers will
+ *      play populate an object, e.g. (possibly?)
+ *      - the parsing deployer will describe the properties/metadata
+ *      - there maybe transformation, augmentation by some other deployers
+ *      - the component deployers will want to link their component metadata back into
+ *            the parent by reference, e.g. an mbean as part of sar/-service.xml  
+ *      - the real deployer will describe any runtime support, e.g. managed operations and statistics
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ManagedObjectBuilder
+{
+   /**
+    * Build managed objects for this deployment context
+    * 
+    * @param unit the deployment unit
+    * @param managedObjects the managed objects
+    * @throws DeploymentException
+    */
+   void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects) throws DeploymentException;
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/spi/managed/ManagedObjectBuilder.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/ManagedTestSuite.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/ManagedTestSuite.java	2007-01-04 02:42:21 UTC (rev 59321)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/ManagedTestSuite.java	2007-01-04 02:44:11 UTC (rev 59322)
@@ -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;
+
+/**
+ * Managed Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class ManagedTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Managed Tests");
+
+      suite.addTest(DeployerManagedObjectUnitTestCase.suite());
+
+      return suite;
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/ManagedTestSuite.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java	2007-01-04 02:42:21 UTC (rev 59321)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java	2007-01-04 02:44:11 UTC (rev 59322)
@@ -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);
+      }
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestAttachment.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestFields.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestFields.java	2007-01-04 02:42:21 UTC (rev 59321)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestFields.java	2007-01-04 02:44:11 UTC (rev 59322)
@@ -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);
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestFields.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java	2007-01-04 02:42:21 UTC (rev 59321)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java	2007-01-04 02:44:11 UTC (rev 59322)
@@ -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.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.deployers.spi.managed.ManagedObjectBuilder;
+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 AbstractSimpleDeployer implements ManagedObjectBuilder
+{
+   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);
+      }
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/support/TestManagedObjectDeployer.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java	2007-01-04 02:42:21 UTC (rev 59321)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java	2007-01-04 02:44:11 UTC (rev 59322)
@@ -0,0 +1,133 @@
+/*
+* 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.plugins.deployment.MainDeployerImpl;
+import org.jboss.deployers.spi.deployment.MainDeployer;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.test.deployers.BaseDeployersTest;
+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 BaseDeployersTest
+{
+   private MainDeployer mainDeployer;
+   
+   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
+   {
+      MainDeployer main = getMainDeployer();
+      
+      // Deploy a context
+      DeploymentContext context = createSimpleDeployment("deploy");
+      main.addDeploymentContext(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);
+      assertNotNull(mos);
+      ManagedObject mo = mos.get(TestAttachment.class.getName());
+      assertNotNull(mo);
+      //
+      Graph<Map<String, ManagedObject>> mosg = main.getManagedObjects(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
+      context.getPredeterminedManagedObjects().addAttachment(TestAttachment.class, attachment);
+      main.addDeploymentContext(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);
+      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 MainDeployer getMainDeployer()
+   {
+      if (mainDeployer != null)
+         return mainDeployer;
+      
+      MainDeployerImpl result = new MainDeployerImpl();
+      result.addDeployer(deployer);
+      
+      mainDeployer = result;
+      return result;
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list