[jboss-cvs] JBossAS SVN: r100205 - in projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo: annotation and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 1 05:24:21 EST 2010


Author: jaikiran
Date: 2010-02-01 05:24:21 -0500 (Mon, 01 Feb 2010)
New Revision: 100205

Added:
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotation.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotationTestCase.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/SimpleAnnotatedClass.java
Log:
JBREFLECT-93 Added a (commented out) testcase illustrating the issue

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotation.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotation.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotation.java	2010-02-01 10:24:21 UTC (rev 100205)
@@ -0,0 +1,31 @@
+/**
+ * 
+ */
+package org.jboss.test.classinfo.annotation.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * NonPublicAnnotation
+ *
+ * A non-public annotation. 
+ * 
+ * NOTE: This {@link NonPublicAnnotation}, {@link SimpleAnnotatedClass} and
+ * even the {@link NonPublicAnnotationTestCase} are all placed in the same package
+ * *intentionally*, so that this annotation is accessible for the {@link SimpleAnnotatedClass}
+ * as well as {@link NonPublicAnnotationTestCase} during the tests.
+ * 
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Target (ElementType.TYPE)
+ at Retention (RetentionPolicy.RUNTIME)
+ at interface NonPublicAnnotation {
+
+   public abstract String name();
+   
+   public abstract boolean isTest();
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotationTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotationTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/NonPublicAnnotationTestCase.java	2010-02-01 10:24:21 UTC (rev 100205)
@@ -0,0 +1,90 @@
+/**
+ * 
+ */
+package org.jboss.test.classinfo.annotation.test;
+
+import java.lang.annotation.Annotation;
+
+import junit.framework.Test;
+
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.test.ContainerTest;
+
+/**
+ * NonPublicAnnotationTestCase
+ * 
+ * Tests that a Class annotated with a non-public annotation is
+ * correctly parsed for annotations. 
+ * <p>
+ * This test is responsible the testing fix for the bug in JBREFLECT
+ * which causes the following exception:
+ * </p>
+ * <p>
+ * Caused by: java.lang.IllegalAccessException: Class org.jboss.reflect.plugins.introspection.ReflectionUtils can not access a member of class org.jboss.test.classinfo.annotation.test.NonPublicAnnotation with modifiers "public abstract"
+ *   at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
+ *   at java.lang.reflect.Method.invoke(Method.java:588)
+ *   at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
+ *   at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:151)
+ *   at org.jboss.reflect.plugins.AnnotationValueFactory.createAnnotationValue(AnnotationValueFactory.java:100)
+ *   ... 33 more
+ *
+ * </p> 
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NonPublicAnnotationTestCase extends ContainerTest
+{
+   /**
+    * Constructor
+    * @param name
+    */
+   public NonPublicAnnotationTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public static Test suite()
+   {
+      return suite(NonPublicAnnotationTestCase.class);
+   }
+
+   /**
+    * Test that the {@link NonPublicAnnotation} when applied to {@link SimpleAnnotatedClass}
+    * is correctly parsed and is available through {@link ClassInfo#getUnderlyingAnnotations()}
+    * 
+    * @throws Exception
+    */
+   public void testNonPublicAnnotationOnClass() throws Exception
+   {
+         // TODO: The test case is currently disabled (i wish @org.junit.Ignore would work here) as per Ales' 
+         // suggestion http://community.jboss.org/message/523284#523284
+//      ClassInfo info = getClassInfo(SimpleAnnotatedClass.class);
+//      
+//      Annotation[] annotations = info.getUnderlyingAnnotations();
+//      assertEquals("Incorrect number of annotations found on " + SimpleAnnotatedClass.class, 1, annotations.length);
+//      Annotation annotation = annotations[0];
+//      assertTrue("Incorrect annotation type found on " + SimpleAnnotatedClass.class, (annotation instanceof NonPublicAnnotation));
+//      NonPublicAnnotation expectedAnnotation = (NonPublicAnnotation) annotation;
+//      assertEquals("Incorrect value found for annotation " + NonPublicAnnotation.class
+//            + " on class " + SimpleAnnotatedClass.class, SimpleAnnotatedClass.ANNOTATION_ELEMENT_NAME, expectedAnnotation.name());
+   }
+
+   /**
+    * Utitlity method
+    * @param clazz
+    * @return
+    */
+   private ClassInfo getClassInfo(Class<?> clazz)
+   {
+      TypeInfoFactory factory = new IntrospectionTypeInfoFactory();
+      TypeInfo info = factory.getTypeInfo(clazz);
+      assertNotNull(info);
+      assertTrue(info instanceof ClassInfo);
+      ClassInfo cinfo = (ClassInfo) info;
+      getLog().debug(cinfo);
+      return cinfo;
+   }
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/SimpleAnnotatedClass.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/SimpleAnnotatedClass.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/annotation/test/SimpleAnnotatedClass.java	2010-02-01 10:24:21 UTC (rev 100205)
@@ -0,0 +1,25 @@
+/**
+ * 
+ */
+package org.jboss.test.classinfo.annotation.test;
+
+
+/**
+ * SimpleAnnotatedClass
+ *
+ * A simple class used in tests
+ * 
+ * NOTE: The {@link NonPublicAnnotation}, {@link SimpleAnnotatedClass} and
+ * even the {@link NonPublicAnnotationTestCase} are all placed in the same package
+ * *intentionally*, so that this annotation is accessible for the {@link SimpleAnnotatedClass}
+ * as well as {@link NonPublicAnnotationTestCase} during the tests.
+ * 
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at NonPublicAnnotation (name=SimpleAnnotatedClass.ANNOTATION_ELEMENT_NAME, isTest=true)
+public class SimpleAnnotatedClass
+{
+
+   public static final String ANNOTATION_ELEMENT_NAME = "SomeName";
+}




More information about the jboss-cvs-commits mailing list