[jboss-cvs] JBossAS SVN: r102719 - in projects/jboss-reflect/trunk/src: test/java/org/jboss/test/beaninfo/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 22 08:41:54 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-03-22 08:41:53 -0400 (Mon, 22 Mar 2010)
New Revision: 102719
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoUnitTestCase.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/support/SimpleBean.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/test/JoinpointTest.java
Log:
[JBREFLECT-108] Fix primitive javassist field joinpoints
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java 2010-03-22 12:40:40 UTC (rev 102718)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java 2010-03-22 12:41:53 UTC (rev 102719)
@@ -515,7 +515,7 @@
// Primitives can't be null
if (type.isPrimitive())
{
- buffer.append("if (type == null) ");
+ buffer.append("if (value == null) ");
buffer.append("throw new IllegalArgumentException(\"Value ");
buffer.append(" cannot be null for ").append(type.getName());
buffer.append(" for ").append(ctField.getName()).append("\");");
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoUnitTestCase.java 2010-03-22 12:40:40 UTC (rev 102718)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoUnitTestCase.java 2010-03-22 12:41:53 UTC (rev 102719)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.beaninfo.test;
+import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;
@@ -28,12 +29,14 @@
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.reflect.spi.AnnotationValue;
import org.jboss.test.beaninfo.support.BeanInfoAnnotatedGetterAndSetter;
import org.jboss.test.beaninfo.support.BeanInfoAnnotatedGetterAndSetterSimpleMerge;
import org.jboss.test.beaninfo.support.BeanInfoAnnotatedGetterAndSetterWithInterface;
import org.jboss.test.beaninfo.support.BeanInfoAnnotatedGetterOnly;
import org.jboss.test.beaninfo.support.BeanInfoAnnotatedSetterOnly;
import org.jboss.test.beaninfo.support.BeanInfoAnnotation;
+import org.jboss.test.beaninfo.support.BeanInfoAnnotation1;
import org.jboss.test.beaninfo.support.BeanInfoBooleanProperties;
import org.jboss.test.beaninfo.support.BeanInfoConstructors;
import org.jboss.test.beaninfo.support.BeanInfoDefaultConstructor;
@@ -239,7 +242,7 @@
{
testBean(BeanInfoInterface.class, new String[] { "something" });
}
-
+
public void testBeanAnnotation() throws Throwable
{
testBean(BeanInfoAnnotation.class, new String[] { "something" });
@@ -324,6 +327,36 @@
assertEquals("java.lang.Double", property.getType().getName());
}
+ public void testBeanAnnotatedGetterOnlyAnnotations() throws Throwable
+ {
+ testBeanAnnotations(BeanInfoAnnotatedGetterOnly.class, new String[] { "something" }, new Class<?>[] {BeanInfoAnnotation1.class});
+ }
+
+// public void testBeanAnnotatedSetterOnlyAnnotations() throws Throwable
+// {
+// testBeanAnnotations(BeanInfoAnnotatedSetterOnly.class, new String[] { "something" });
+// }
+//
+// public void testBeanAnnotatedGetterAndSetterAnnotations() throws Throwable
+// {
+// testBeanAnnotations(BeanInfoAnnotatedGetterAndSetter.class, new String[] { "something" });
+// }
+//
+// public void testBeanAnnotatedGetterAndSetterWithInterfaceAnnotations() throws Throwable
+// {
+// testBeanAnnotations(BeanInfoAnnotatedGetterAndSetterWithInterface.class, new String[] { "something" });
+// }
+//
+// public void testBeanAnnotatedGetterAndSetterSimpleMergeAnnotations() throws Throwable
+// {
+// testBeanAnnotations(BeanInfoAnnotatedGetterAndSetterSimpleMerge.class, new String[] { "something" });
+// }
+//
+// public void testBeanAnnotations() throws Throwable
+// {
+// testBeanAnnotations(BeanInfoAnnotation.class, new String[] { "something" });
+// }
+
protected void testBean(Class<?> clazz, String[] beanNames) throws Throwable
{
for (BeanAccessMode mode : BeanAccessMode.values())
@@ -331,6 +364,7 @@
testBean(clazz, mode, beanNames);
}
}
+
protected void testBean(Class<?> clazz, BeanAccessMode mode, String[] beanNames) throws Throwable
{
BeanInfo beanInfo = getBeanInfo(clazz, mode);
@@ -349,4 +383,56 @@
assertEquals(expected, props);
}
}
+
+ protected void testBeanAnnotations(Class<?> clazz, String[] beanNames, Class<?>[] annotations) throws Throwable
+ {
+ for (BeanAccessMode mode : BeanAccessMode.values())
+ {
+ testBeanAnnotations(clazz, mode, beanNames, annotations);
+ }
+ }
+
+ protected void testBeanAnnotations(Class<?> clazz, BeanAccessMode mode, String[] beanNames, Class<?>[] annotations) throws Throwable
+ {
+ BeanInfo beanInfo = getBeanInfo(clazz, mode);
+ assertBeanInfo(beanInfo, clazz, mode);
+
+ for (String prop : beanNames)
+ {
+ PropertyInfo property = beanInfo.getProperty(prop);
+ AnnotationValue[] annValues = property.getAnnotations();
+ Annotation[] underlying = property.getUnderlyingAnnotations();
+ assertEquals(annotations.length, annValues.length);
+ for (Class<?> ann : annotations)
+ {
+ AnnotationValue val = property.getAnnotation(ann.getName());
+ assertNotNull(val);
+
+ boolean found = false;
+ for (AnnotationValue annVal : annValues)
+ {
+ if (annVal.getType().getName().equals(ann.getName()))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ fail("Cound not find " + ann);
+
+ assertNotNull(property.getUnderlyingAnnotation((Class<? extends Annotation>)ann));
+ found = false;
+ for (Annotation under : underlying)
+ {
+ if (under.annotationType() == ann)
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ fail("Cound not find " + ann);
+ }
+ }
+ }
}
\ No newline at end of file
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/support/SimpleBean.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/support/SimpleBean.java 2010-03-22 12:40:40 UTC (rev 102718)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/support/SimpleBean.java 2010-03-22 12:41:53 UTC (rev 102719)
@@ -37,6 +37,10 @@
private String constructorUsed;
+ public int intField;
+
+ public static int staticField;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -56,6 +60,11 @@
constructorUsed = string;
}
+ public SimpleBean(int i)
+ {
+ intField = i;
+ }
+
// Public --------------------------------------------------------
public String getConstructorUsed()
@@ -68,6 +77,18 @@
return value;
}
+ public int setIntField(int i)
+ {
+ intField = i;
+ return i;
+ }
+
+ public static int staticMethod(int i)
+ {
+ staticField = i;
+ return i;
+ }
+
// SimpleInterface Implementation --------------------------------
// Package protected ---------------------------------------------
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/test/JoinpointTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/test/JoinpointTest.java 2010-03-22 12:40:40 UTC (rev 102718)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/joinpoint/test/JoinpointTest.java 2010-03-22 12:41:53 UTC (rev 102719)
@@ -113,13 +113,102 @@
assertEquals(bean.toString(), joinpoint.dispatch());
}
+ public void testConstructorPrimitive() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ Joinpoint joinpoint = Config.getConstructorJoinpoint(jpf, new String[] {"int"}, new Object[] {10});
+ Object o = joinpoint.dispatch();
+ SimpleBean bean = assertInstanceOf(o, SimpleBean.class);
+ assertEquals(10, bean.intField);
+ }
+
+ public void testSetPrimitiveField() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ SimpleBean bean = new SimpleBean();
+ Joinpoint joinpoint = Config.getFieldSetJoinpoint(bean, jpf, "intField", 11);
+ joinpoint.dispatch();
+ assertEquals(11, bean.intField);
+ }
+
+ public void testUnsetPrimitiveField() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ SimpleBean bean = new SimpleBean();
+ Joinpoint joinpoint = Config.getFieldSetJoinpoint(bean, jpf, "intField", null);
+ try
+ {
+ joinpoint.dispatch();
+ fail("Should not have allowed a null primitive");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testGetPrimitiveField() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ SimpleBean bean = new SimpleBean();
+ bean.intField = 12;
+ Joinpoint joinpoint = Config.getFieldGetJoinpoint(bean, jpf, "intField");
+ assertEquals(12, joinpoint.dispatch());
+ }
+
+ public void testPrimitiveMethod() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ SimpleBean bean = new SimpleBean();
+ Joinpoint joinpoint = Config.getMethodJoinpoint(bean, jpf, "setIntField", new String[] {"int"}, new Object[] {13});
+ assertEquals(13, joinpoint.dispatch());
+ assertEquals(13, bean.intField);
+ }
+
+ public void testSetStaticPrimitiveField() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ Joinpoint joinpoint = Config.getFieldSetJoinpoint(null, jpf, "staticField", 11);
+ joinpoint.dispatch();
+ assertEquals(11, SimpleBean.staticField);
+ }
+
+ public void testUnsetStaticPrimitiveField() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ Joinpoint joinpoint = Config.getFieldSetJoinpoint(null, jpf, "staticField", null);
+ try
+ {
+ joinpoint.dispatch();
+ fail("Should not have allowed a null primitive");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testGetStaticPrimitiveField() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ SimpleBean.staticField = 12;
+ Joinpoint joinpoint = Config.getFieldGetJoinpoint(null, jpf, "staticField");
+ assertEquals(12, joinpoint.dispatch());
+ }
+
+ public void testStaticPrimitiveMethod() throws Throwable
+ {
+ JoinpointFactory jpf = getJointpointFactory(SimpleBean.class);
+ Joinpoint joinpoint = Config.getStaticMethodJoinpoint(jpf, "staticMethod", new String[] {"int"}, new Object[] {13});
+ assertEquals(13, joinpoint.dispatch());
+ assertEquals(13, SimpleBean.staticField);
+ }
+
protected JoinpointFactory getJointpointFactory(Class<?> clazz)
{
TypeInfoFactory typeFactory = getTypeInfoFactory();
ClassInfo info = (ClassInfo) typeFactory.getTypeInfo(clazz);
return new BasicJoinpointFactory(info);
}
-
+
protected abstract TypeInfoFactory getTypeInfoFactory();
protected void configureLogging()
More information about the jboss-cvs-commits
mailing list