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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 6 13:00:06 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-07-06 13:00:05 -0400 (Tue, 06 Jul 2010)
New Revision: 106453

Added:
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotation.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotationWithValue.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass1.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass2.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass1.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass2.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeMixedClassInfoImplementationTestCase.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/IntrospectionMixedClassInfoImplementationTestCase.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistMixedClassInfoImplementationTestCase.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/MixedClassInfoImplementationTest.java
Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
Log:
[JBREFLECT-131] Write some tests for obtaining annotations and mixing reflect and other sub/super classes

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java	2010-07-06 15:58:22 UTC (rev 106452)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -796,10 +796,7 @@
    @Override
    public ClassInfo getSuperHolder()
    {
-      TypeInfo info = getSuperclass();
-      if (info instanceof BytecodeInheritableAnnotationHolder)
-         return (ClassInfo)info;
-      return null;
+      return getSuperclass();
    }
 
    public TypeInfo[] getActualTypeArguments()

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotation.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotation.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotation.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.support;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Inherited
+public @interface InheritedAnnotation {
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotationWithValue.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotationWithValue.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/InheritedAnnotationWithValue.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.support;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Inherited
+public @interface InheritedAnnotationWithValue {
+   String value();
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass1.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass1.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass1.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at InheritedAnnotationWithValue("sub1")
+ at AnotherAnnotation
+public class MixedImplementationAnnotationsSubClass1 extends MixedImplementationAnnotationsSuperClass1
+{
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass2.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass2.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSubClass2.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at InheritedAnnotationWithValue("sub2")
+ at AnotherAnnotation
+public class MixedImplementationAnnotationsSubClass2 extends MixedImplementationAnnotationsSuperClass2
+{
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass1.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass1.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass1.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at InheritedAnnotation
+ at InheritedAnnotationWithValue("super1")
+public class MixedImplementationAnnotationsSuperClass1
+{
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass2.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass2.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/MixedImplementationAnnotationsSuperClass2.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at InheritedAnnotation
+ at InheritedAnnotationWithValue("super2")
+public class MixedImplementationAnnotationsSuperClass2
+{
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeMixedClassInfoImplementationTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeMixedClassInfoImplementationTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeMixedClassInfoImplementationTestCase.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.test;
+
+import junit.framework.TestSuite;
+
+import org.jboss.reflect.plugins.bytecode.BytecodeTypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BytecodeMixedClassInfoImplementationTestCase extends MixedClassInfoImplementationTest
+{
+   public BytecodeMixedClassInfoImplementationTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public static TestSuite suite()
+   {
+      return new TestSuite(BytecodeMixedClassInfoImplementationTestCase.class);
+   }
+
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new BytecodeTypeInfoFactory();
+   }
+
+   @Override
+   protected void setSuperClassInAnySubClass(ClassInfo subClassInfo, ClassInfo superClassInfo) throws Exception
+   {
+      setSuperClass(subClassInfo, superClassInfo, "BytecodeTypeInfo", "superClass");
+   }
+
+}

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2010-07-06 15:58:22 UTC (rev 106452)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -104,6 +104,10 @@
       suite.addTest(IntrospectionClassInfoWithArrayMembersTestCase.suite());
       suite.addTest(JavassistClassInfoWithArrayMembersTestCase.suite());
       suite.addTest(BytecodeClassInfoWithArrayMembersTestCase.suite());
+      
+      suite.addTest(IntrospectionMixedClassInfoImplementationTestCase.suite());
+      suite.addTest(JavassistMixedClassInfoImplementationTestCase.suite());
+      suite.addTest(BytecodeMixedClassInfoImplementationTestCase.suite());
 
       return suite;
    }

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/IntrospectionMixedClassInfoImplementationTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/IntrospectionMixedClassInfoImplementationTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/IntrospectionMixedClassInfoImplementationTestCase.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.test;
+
+import junit.framework.TestSuite;
+
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IntrospectionMixedClassInfoImplementationTestCase extends MixedClassInfoImplementationTest
+{
+   public IntrospectionMixedClassInfoImplementationTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public static TestSuite suite()
+   {
+      return new TestSuite(IntrospectionMixedClassInfoImplementationTestCase.class);
+   }
+
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new IntrospectionTypeInfoFactory();
+   }
+
+   @Override
+   protected void setSuperClassInAnySubClass(ClassInfo subClassInfo, ClassInfo superClassInfo) throws Exception
+   {
+      setSuperClassInReflectSubClass(subClassInfo, superClassInfo);
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistMixedClassInfoImplementationTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistMixedClassInfoImplementationTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistMixedClassInfoImplementationTestCase.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.test;
+
+import junit.framework.TestSuite;
+
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistMixedClassInfoImplementationTestCase extends MixedClassInfoImplementationTest
+{
+   public JavassistMixedClassInfoImplementationTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public static TestSuite suite()
+   {
+      return new TestSuite(JavassistMixedClassInfoImplementationTestCase.class);
+   }
+
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new JavassistTypeInfoFactory();
+   }
+
+   @Override
+   protected void setSuperClassInAnySubClass(ClassInfo subClassInfo, ClassInfo superClassInfo) throws Exception
+   {
+      setSuperClass(subClassInfo, superClassInfo, "JavassistTypeInfo", "superClass");
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/MixedClassInfoImplementationTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/MixedClassInfoImplementationTest.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/MixedClassInfoImplementationTest.java	2010-07-06 17:00:05 UTC (rev 106453)
@@ -0,0 +1,138 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.classinfo.test;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.reflect.plugins.ClassInfoImpl;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.plugins.introspection.ReflectClassInfoImpl;
+import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.ContainerTest;
+import org.jboss.test.classinfo.support.AnotherAnnotation;
+import org.jboss.test.classinfo.support.InheritedAnnotation;
+import org.jboss.test.classinfo.support.InheritedAnnotationWithValue;
+import org.jboss.test.classinfo.support.MixedImplementationAnnotationsSubClass1;
+import org.jboss.test.classinfo.support.MixedImplementationAnnotationsSubClass2;
+import org.jboss.test.classinfo.support.MixedImplementationAnnotationsSuperClass1;
+import org.jboss.test.classinfo.support.MixedImplementationAnnotationsSuperClass2;
+
+/**
+ * This test hacks the superclass of various class info impls to get a mixture
+ * similar to what happened for JBREFLECT-131 to happen in AS
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class MixedClassInfoImplementationTest extends ContainerTest
+{
+   public MixedClassInfoImplementationTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Run this test with security turned off
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
+      return delegate;
+   }
+
+
+   public void testAnnotationsReflectSuperClass() throws Exception
+   {
+      ClassInfo reflectSuper = getReflectClassInfo(MixedImplementationAnnotationsSuperClass1.class);
+      ClassInfo otherSub = assertInstanceOf(getTypeInfoFactory().getTypeInfo(MixedImplementationAnnotationsSubClass1.class), ClassInfo.class);
+      setSuperClassInAnySubClass(otherSub, reflectSuper);
+      assertSame(reflectSuper, otherSub.getSuperclass());
+      
+      checkAnnotations(otherSub, "sub1");
+   }
+   
+   public void testAnnotationsReflectSubClass() throws Exception
+   {
+      ClassInfo otherSuper = assertInstanceOf(getTypeInfoFactory().getTypeInfo(MixedImplementationAnnotationsSuperClass2.class), ClassInfo.class);
+      ClassInfo reflectSub = getReflectClassInfo(MixedImplementationAnnotationsSubClass2.class);
+      setSuperClassInReflectSubClass(reflectSub, otherSuper);
+      assertSame(otherSuper, reflectSub.getSuperclass());
+      
+      checkAnnotations(reflectSub, "sub2");
+   }
+   
+   private void checkAnnotations(ClassInfo sub, String overriddenValue)
+   {
+      AnnotationValue[] anns = sub.getAnnotations();
+      assertEquals(3, anns.length);
+      for (int i = 0 ; i < 3 ; i++)
+      {
+         Annotation ann = anns[i].getUnderlyingAnnotation();
+         if (ann.annotationType() == InheritedAnnotation.class)
+         {
+            
+         }
+         else if (ann.annotationType() == AnotherAnnotation.class)
+         {
+            
+         }
+         else if (ann.annotationType() == InheritedAnnotationWithValue.class)
+         {
+            assertEquals(overriddenValue, ((InheritedAnnotationWithValue)ann).value());
+         }
+         else
+            fail("Unknown annotation" + ann);
+      }
+      
+   }
+   
+   private ClassInfo getReflectClassInfo(Class<?> clazz) 
+   {
+      return assertInstanceOf(new IntrospectionTypeInfoFactory().getTypeInfo(clazz), ClassInfo.class);
+   }
+   
+   protected abstract TypeInfoFactory getTypeInfoFactory();
+   
+   protected abstract void setSuperClassInAnySubClass(ClassInfo subClassInfo, ClassInfo superClassInfo) throws Exception;
+   
+   protected void setSuperClassInReflectSubClass(ClassInfo subClassInfo, ClassInfo superClassInfo) throws Exception
+   {
+      setSuperClass(subClassInfo, superClassInfo, ClassInfoImpl.class.getSimpleName(), "superclass");
+   }
+   
+   protected void setSuperClass(ClassInfo subClassInfo, ClassInfo superClassInfo, String containingClass, String fieldName) throws Exception
+   {
+      Class<?> clazz = subClassInfo.getClass();
+      while (!clazz.getName().contains("." + containingClass))
+         clazz = clazz.getSuperclass();
+      Field field = clazz.getDeclaredField(fieldName);
+      field.setAccessible(true);
+      field.set(subClassInfo, superClassInfo);
+   }
+}



More information about the jboss-cvs-commits mailing list