[jboss-cvs] JBossAS SVN: r70907 - in projects/microcontainer/trunk/kernel/src: main/org/jboss/kernel/plugins/annotations and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 17 08:21:47 EDT 2008


Author: alesj
Date: 2008-03-17 08:21:47 -0400 (Mon, 17 Mar 2008)
New Revision: 70907

Added:
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldBeanAnnotationAdapter.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldTester.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInject.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInjectPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/AnnotationFieldTestSuite.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/SimpleFieldTestCase.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractAnnotationPlugin.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java
Log:
Simple field test.
PropertyInfo.getProperties usage fix.

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java	2008-03-17 12:13:29 UTC (rev 70906)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractPropertyMetaData.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -32,6 +32,7 @@
 import javax.xml.bind.annotation.XmlValue;
 
 import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.metadata.spi.MetaDataVisitor;
 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
 import org.jboss.beans.metadata.spi.PropertyMetaData;
@@ -302,18 +303,9 @@
       }
       // check properties
       KernelControllerContext context = visitor.getControllerContext();
-      Set<PropertyInfo> propertyInfos = context.getBeanInfo().getProperties();
-      if (propertyInfos != null && propertyInfos.isEmpty() == false)
-      {
-         for (PropertyInfo pi : propertyInfos)
-         {
-            if (getName().equals(pi.getName()))
-            {
-               return applyCollectionOrMapCheck(pi.getType());
-            }
-         }
-      }
-      throw new IllegalArgumentException("Should not be here - no matching propertyInfo: " + this);
+      BeanInfo beanInfo = context.getBeanInfo();
+      PropertyInfo pi = beanInfo.getProperty(getName());
+      return applyCollectionOrMapCheck(pi.getType());
    }
 
    public void toString(JBossStringBuilder buffer)

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractAnnotationPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractAnnotationPlugin.java	2008-03-17 12:13:29 UTC (rev 70906)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractAnnotationPlugin.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -188,7 +188,7 @@
    protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(T info, C annotation, BeanMetaData beanMetaData) throws Throwable
    {
       log.warn("Probably missing annotation apply implementation: " + this);
-      return Collections.emptyList();
+      return null;
    }
 
    public final void applyAnnotation(T info, MetaData retrieval, MetaDataVisitor visitor) throws Throwable

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldBeanAnnotationAdapter.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldBeanAnnotationAdapter.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldBeanAnnotationAdapter.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -0,0 +1,35 @@
+/*
+* 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.kernel.annotations.support;
+
+import org.jboss.kernel.plugins.annotations.AbstractBeanAnnotationAdapter;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MockFieldBeanAnnotationAdapter extends AbstractBeanAnnotationAdapter
+{
+   public MockFieldBeanAnnotationAdapter()
+   {
+      addAnnotationPlugin(MockInjectPlugin.INSTANCE);
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldTester.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldTester.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockFieldTester.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -0,0 +1,39 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.util.Date;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MockFieldTester
+{
+   @MockInject
+   private String string;
+
+   @MockInject
+   protected long time;
+
+   @MockInject
+   public Date date;
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInject.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInject.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInject.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -0,0 +1,37 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target(ElementType.FIELD)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface MockInject
+{
+   String value() default "";
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInjectPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInjectPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/MockInjectPlugin.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -0,0 +1,62 @@
+/*
+* 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.kernel.annotations.support;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.kernel.plugins.annotations.FieldAnnotationPlugin;
+import org.jboss.reflect.spi.FieldInfo;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MockInjectPlugin extends FieldAnnotationPlugin<MockInject>
+{
+   public static MockInjectPlugin INSTANCE = new MockInjectPlugin();
+
+   private Set<String> fieldNames = new HashSet<String>();
+
+   private MockInjectPlugin()
+   {
+      super(MockInject.class);
+   }
+
+   protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(FieldInfo info, MockInject annotation, BeanMetaData beanMetaData) throws Throwable
+   {
+      fieldNames.add(info.getName());
+      return null;
+   }
+
+   public Set<String> getFieldNames()
+   {
+      return fieldNames;
+   }
+
+   public void clear()
+   {
+      fieldNames.clear();
+   }
+}

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java	2008-03-17 12:13:29 UTC (rev 70906)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -26,6 +26,7 @@
 import junit.textui.TestRunner;
 import org.jboss.test.kernel.annotations.test.override.AnnotationsOverrideTestSuite;
 import org.jboss.test.kernel.annotations.test.inheritance.AnnotationsInheritanceTestSuite;
+import org.jboss.test.kernel.annotations.test.field.AnnotationFieldTestSuite;
 
 /**
  * Annotations tests.
@@ -46,6 +47,7 @@
       suite.addTest(AnnotationSupportTestSuite.suite());
       suite.addTest(AnnotationsOverrideTestSuite.suite());
       suite.addTest(AnnotationsInheritanceTestSuite.suite());
+      suite.addTest(AnnotationFieldTestSuite.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/AnnotationFieldTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/AnnotationFieldTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/AnnotationFieldTestSuite.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -0,0 +1,48 @@
+/*
+* 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.kernel.annotations.test.field;
+
+import junit.textui.TestRunner;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Field annotation tests.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AnnotationFieldTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Fields Tests");
+
+      suite.addTest(SimpleFieldTestCase.suite());
+
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/SimpleFieldTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/SimpleFieldTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/SimpleFieldTestCase.java	2008-03-17 12:21:47 UTC (rev 70907)
@@ -0,0 +1,71 @@
+/*
+* 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.kernel.annotations.test.field;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+
+import junit.framework.Test;
+import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter;
+import org.jboss.test.kernel.annotations.test.AbstractBeanAnnotationAdapterTest;
+import org.jboss.test.kernel.annotations.support.MockFieldBeanAnnotationAdapter;
+import org.jboss.test.kernel.annotations.support.MockFieldTester;
+import org.jboss.test.kernel.annotations.support.MockInjectPlugin;
+
+/**
+ * Simple field test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SimpleFieldTestCase extends AbstractBeanAnnotationAdapterTest
+{
+   public SimpleFieldTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(SimpleFieldTestCase.class);
+   }
+
+   protected BeanAnnotationAdapter getBeanAnnotationAdapterClass()
+   {
+      return new MockFieldBeanAnnotationAdapter();
+   }
+
+   public void testFieldUsage() throws Throwable
+   {
+      MockFieldTester tester = new MockFieldTester();
+      try
+      {
+         runAnnotationsOnTarget(tester);
+         Set<String> expected = new HashSet<String>(Arrays.asList("date"));//, "time", "string"));
+         assertEquals(expected, MockInjectPlugin.INSTANCE.getFieldNames());
+      }
+      finally
+      {
+         MockInjectPlugin.INSTANCE.clear();
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list