[jboss-cvs] JBossAS SVN: r66238 - in projects/microcontainer/trunk: deployers-vfs/src/tests/org/jboss/test/deployers and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 18 10:59:52 EDT 2007


Author: alesj
Date: 2007-10-18 10:59:52 -0400 (Thu, 18 Oct 2007)
New Revision: 66238

Added:
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/VFSManagedTestSuite.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/MCBeanWithRuntimeName.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/PlainMCBean.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/test/
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/test/BeanMetaDataICFTestCase.java
Modified:
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/managed/BeanInstanceClassFactory.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/InstanceClassFactory.java
Log:
BeanMetaData ICF tests.

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/managed/BeanInstanceClassFactory.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/managed/BeanInstanceClassFactory.java	2007-10-18 13:48:54 UTC (rev 66237)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/managed/BeanInstanceClassFactory.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -23,11 +23,13 @@
 
 import java.io.Serializable;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Set;
 
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
 import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.beans.metadata.spi.PropertyMetaData;
 import org.jboss.beans.metadata.spi.ValueMetaData;
@@ -42,7 +44,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class BeanInstanceClassFactory implements InstanceClassFactory<BeanMetaData>
+public class BeanInstanceClassFactory implements InstanceClassFactory<AbstractBeanMetaData>
 {
    /** The meta value factory */
    private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
@@ -67,10 +69,9 @@
    }
 
    @SuppressWarnings("unchecked")
-   public Class<? extends Serializable> getManagedObjectClass(BeanMetaData attachment) throws ClassNotFoundException
+   public Class<? extends Serializable> getManagedObjectClass(AbstractBeanMetaData attachment) throws ClassNotFoundException
    {
-      Class clazz = getClassLoader(attachment).loadClass(attachment.getBean());
-      return clazz;
+      return (Class)getClassLoader(attachment).loadClass(attachment.getBean());
    }
 
    /**
@@ -80,15 +81,19 @@
     * @param name property name
     * @return property meta data or null if no match
     */
-   protected PropertyMetaData getPropertyMetaData(BeanMetaData attachment, String name)
+   protected PropertyMetaData getPropertyMetaData(AbstractBeanMetaData attachment, String name)
    {
       PropertyMetaData propertyMetaData = null;
-      for(PropertyMetaData pmd : attachment.getProperties())
+      Set<PropertyMetaData> properties = attachment.getProperties();
+      if (properties != null && properties.isEmpty() == false)
       {
-         if (name.equals(pmd.getName()))
+         for(PropertyMetaData pmd : properties)
          {
-            propertyMetaData = pmd;
-            break;
+            if (name.equals(pmd.getName()))
+            {
+               propertyMetaData = pmd;
+               break;
+            }
          }
       }
       return propertyMetaData;
@@ -102,7 +107,7 @@
     * @return property meta data or exception if no match
     * @throws IllegalArgumentException for no matching property meta data
     */
-   protected PropertyMetaData getExactPropertyMetaData(BeanMetaData attachment, String name)
+   protected PropertyMetaData getExactPropertyMetaData(AbstractBeanMetaData attachment, String name)
    {
       PropertyMetaData propertyMetaData = getPropertyMetaData(attachment, name);
       if (propertyMetaData == null)
@@ -110,7 +115,7 @@
       return propertyMetaData;
    }
 
-   public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property, BeanMetaData attachment)
+   public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property, AbstractBeanMetaData attachment)
    {
       String name = property.getName();
       PropertyMetaData pmd = getExactPropertyMetaData(attachment, name);
@@ -127,7 +132,7 @@
       }
    }
 
-   public void setValue(BeanInfo beanInfo, ManagedProperty property, BeanMetaData attachment, MetaValue value)
+   public void setValue(BeanInfo beanInfo, ManagedProperty property, AbstractBeanMetaData attachment, MetaValue value)
    {
       String name = property.getName();
       PropertyMetaData pmd = getExactPropertyMetaData(attachment, name);
@@ -139,7 +144,7 @@
       }
    }
 
-   public Object getComponentName(BeanInfo beanInfo, ManagedProperty property, BeanMetaData attachment, MetaValue value)
+   public Object getComponentName(BeanInfo beanInfo, ManagedProperty property, AbstractBeanMetaData attachment, MetaValue value)
    {
       return (beanInfo == null || property == null || value == null) ? attachment.getName() : null;
    }

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java	2007-10-18 13:48:54 UTC (rev 66237)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -31,6 +31,7 @@
 import org.jboss.test.deployers.vfs.metadata.VFSMetaDataTestSuite;
 import org.jboss.test.deployers.vfs.structure.VFSStructureTestSuite;
 import org.jboss.test.deployers.vfs.structurebuilder.VFSStructureBuilderTestSuite;
+import org.jboss.test.deployers.vfs.managed.VFSManagedTestSuite;
 
 /**
  * Deployers VFS Test Suite.
@@ -55,6 +56,7 @@
       suite.addTest(VFSMetaDataTestSuite.suite());
       suite.addTest(VFSDeployerTestSuite.suite());
       suite.addTest(BeanDeployerTestSuite.suite());
+      suite.addTest(VFSManagedTestSuite.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/VFSManagedTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/VFSManagedTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/VFSManagedTestSuite.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -0,0 +1,49 @@
+/*
+* 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.vfs.managed;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jboss.test.deployers.vfs.managed.test.BeanMetaDataICFTestCase;
+
+/**
+ * VFS managed testsuite.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSManagedTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("VFS Managed Tests");
+
+      suite.addTest(BeanMetaDataICFTestCase.suite());
+
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/MCBeanWithRuntimeName.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/MCBeanWithRuntimeName.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/MCBeanWithRuntimeName.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -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.test.deployers.vfs.managed.support;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at ManagementObject
+public class MCBeanWithRuntimeName
+{
+   private String id;
+   private String componentName;
+
+   @ManagementObjectID(type = "MCBean")
+   public String getId()
+   {
+      return id;
+   }
+
+   public void setId(String id)
+   {
+      this.id = id;
+   }
+
+   @ManagementRuntimeRef
+   public String getComponentName()
+   {
+      return componentName;
+   }
+
+   public void setComponentName(String componentName)
+   {
+      this.componentName = componentName;
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/PlainMCBean.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/PlainMCBean.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/support/PlainMCBean.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -0,0 +1,45 @@
+/*
+* 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.vfs.managed.support;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at ManagementObject
+public class PlainMCBean
+{
+   private String id;
+
+   @ManagementObjectID(type = "MCBean")
+   public String getId()
+   {
+      return id;
+   }
+
+   public void setId(String id)
+   {
+      this.id = id;
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/test/BeanMetaDataICFTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/test/BeanMetaDataICFTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/managed/test/BeanMetaDataICFTestCase.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -0,0 +1,76 @@
+/*
+* 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.vfs.managed.test;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.deployers.vfs.deployer.kernel.managed.BeanInstanceClassFactory;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.test.BaseTestCase;
+import org.jboss.test.deployers.vfs.managed.support.PlainMCBean;
+import org.jboss.test.deployers.vfs.managed.support.MCBeanWithRuntimeName;
+
+/**
+ * Test bean meta data ICF.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeanMetaDataICFTestCase extends BaseTestCase
+{
+   public BeanMetaDataICFTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(BeanMetaDataICFTestCase.class);
+   }
+
+   public void testICF() throws Exception
+   {
+      ManagedObjectFactory factory = ManagedObjectFactory.getInstance();
+      BeanInstanceClassFactory instanceClassFactory = new BeanInstanceClassFactory();
+      factory.setInstanceClassFactory(AbstractBeanMetaData.class, instanceClassFactory);
+      try
+      {
+         AbstractBeanMetaData plainMCBean = new AbstractBeanMetaData("plain", PlainMCBean.class.getName());
+         plainMCBean.addProperty(new AbstractPropertyMetaData("id", "PlainMCBean"));
+         ManagedObject mo = factory.initManagedObject(plainMCBean, "PlainMCBean", "MC");
+         assertNotNull(mo);
+         assertEquals("plain", mo.getComponentName());
+
+         AbstractBeanMetaData runtimeMCBean = new AbstractBeanMetaData("runtime", MCBeanWithRuntimeName.class.getName());
+         runtimeMCBean.addProperty(new AbstractPropertyMetaData("id", "RuntimeMCBean"));
+         runtimeMCBean.addProperty(new AbstractPropertyMetaData("componentName", "FromObjectRuntime"));
+         ManagedObject mo2 = factory.initManagedObject(runtimeMCBean, "RuntimeMCBean", "MC");
+         assertNotNull(mo2);
+         assertEquals("FromObjectRuntime", mo2.getComponentName());
+      }
+      finally
+      {
+         factory.setInstanceClassFactory(AbstractBeanMetaData.class, null);
+      }
+   }
+}

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java	2007-10-18 13:48:54 UTC (rev 66237)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -55,7 +55,7 @@
     * @param object the object
     * @param name - the name of the managed object. If null, the name will
     *    be derived from the object annotations or attachment name.
-    * @param type - the name of the managed object. If null, the name will
+    * @param nameType - the name of the managed object. If null, the name will
     *    be derived from the object annotations or default to "".
     * 
     * @see ManagementObjectID

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/InstanceClassFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/InstanceClassFactory.java	2007-10-18 13:48:54 UTC (rev 66237)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/InstanceClassFactory.java	2007-10-18 14:59:52 UTC (rev 66238)
@@ -36,7 +36,7 @@
  * @author Ales.Justin at jboss.org
  * @version $Revision$
  */
-public interface InstanceClassFactory<T>
+public interface InstanceClassFactory<T extends Serializable>
 {
    /**
     * Return the Class that represents the root ManagedObject to scan




More information about the jboss-cvs-commits mailing list