[jboss-cvs] JBossAS SVN: r74133 - in projects/jboss-deployers/trunk: deployers-impl/src/tests/org/jboss/test/deployers/annotations/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 5 06:38:16 EDT 2008


Author: alesj
Date: 2008-06-05 06:38:16 -0400 (Thu, 05 Jun 2008)
New Revision: 74133

Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java
   projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanScanningUnitTestCase.java
   projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/facelets/test/FaceletsUnitTestCase.java
Log:
Fix classloading issues in annotations tests - new system, filtering domain, ...
Introduce String annotation as parameter to AnnotationEnvironment.
Fix BeanScanning test, to not use entire testsuite classpath.

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java	2008-06-05 10:38:10 UTC (rev 74132)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java	2008-06-05 10:38:16 UTC (rev 74133)
@@ -181,4 +181,49 @@
    {
       return transformToElements(ElementType.PARAMETER, annotation, AccessibleObject.class);
    }
+
+   /**
+    * Load the annotation class.
+    *
+    * @param annotationName the annoation class name
+    * @return annotation class
+    */
+   @SuppressWarnings("unchecked")
+   protected Class<Annotation> getAnnotationClass(String annotationName)
+   {
+      Class<?> clazz = loadClass(annotationName);
+      if (Annotation.class.isAssignableFrom(clazz) == false)
+         throw new IllegalArgumentException("Annotation name " + annotationName + " doesn't extend Annotation class.");
+      return (Class<Annotation>)clazz;
+   }
+
+   public boolean hasClassAnnotatedWith(String annotationName)
+   {
+      return hasClassAnnotatedWith(getAnnotationClass(annotationName));
+   }
+
+   public Set<Class<?>> classIsAnnotatedWith(String annotationName)
+   {
+      return classIsAnnotatedWith(getAnnotationClass(annotationName));
+   }
+
+   public Set<Element<Annotation, Constructor>> classHasConstructorAnnotatedWith(String annotationName)
+   {
+      return classHasConstructorAnnotatedWith(getAnnotationClass(annotationName));
+   }
+
+   public Set<Element<Annotation, Field>> classHasFieldAnnotatedWith(String annotationName)
+   {
+      return classHasFieldAnnotatedWith(getAnnotationClass(annotationName));
+   }
+
+   public Set<Element<Annotation, Method>> classHasMethodAnnotatedWith(String annotationName)
+   {
+      return classHasMethodAnnotatedWith(getAnnotationClass(annotationName));
+   }
+
+   public Set<Element<Annotation, AccessibleObject>> classHasParameterAnnotatedWith(String annotationName)
+   {
+      return classHasParameterAnnotatedWith(getAnnotationClass(annotationName));
+   }
 }

Modified: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java	2008-06-05 10:38:10 UTC (rev 74132)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java	2008-06-05 10:38:16 UTC (rev 74133)
@@ -56,7 +56,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   public void testSimpleUsage() throws Exception
+   public void testDirectClassUsage() throws Exception
    {
       DeployerClient deployer = getMainDeployer();
 
@@ -127,4 +127,76 @@
          assertUndeploy(deployer, deployment);
       }
    }
+
+   @SuppressWarnings("unchecked")
+   public void testSimpleClassUsage() throws Exception
+   {
+      DeployerClient deployer = getMainDeployer();
+
+      Deployment deployment = createSimpleDeployment("a");
+      addClassLoadingMetaData(
+            deployment,
+            deployment.getName(),
+            null,
+            ClassLoaderUtils.classNameToPath("org.jboss.test.deployers.annotations.support.AnnotationsHolder"),
+            ClassLoaderUtils.classNameToPath("org.jboss.test.deployers.annotations.support.TestAnnotation")
+      );
+
+      DeploymentUnit unit = assertDeploy(deployer, deployment);
+      try
+      {
+         String annotationName = "org.jboss.test.deployers.annotations.support.TestAnnotation";
+
+         assertNotLoaded(unit, "org.jboss.test.deployers.annotations.support.AnnotationsHolder");
+         // annotations are loaded, OK?
+         assertLoaded(unit, "org.jboss.test.deployers.annotations.support.TestAnnotation");
+
+         AnnotationEnvironment env = getAnnotationEnvironment(unit);
+         Set<Class<?>> classes = env.classIsAnnotatedWith(annotationName);
+         assertNotNull(classes);
+         assertEquals(1, classes.size());
+         assertEquals(AnnotationsHolder.class.getName(), classes.iterator().next().getName());
+
+         assertLoaded(unit, "org.jboss.test.deployers.annotations.support.AnnotationsHolder");
+
+         Element<Annotation, Constructor> ec = getSingleton(env.classHasConstructorAnnotatedWith(annotationName));
+         Annotation ta = ec.getAnnotation();
+         assertNotNull(ta);
+         assertEquals("constructor", getValue(ta));
+         assertInstanceOf(ec.getAccessibleObject(), Constructor.class, false);
+
+         Element<Annotation, Field> ef = getSingleton(env.classHasFieldAnnotatedWith(annotationName));
+         ta = ef.getAnnotation();
+         assertNotNull(ta);
+         assertEquals("field", getValue(ta));
+         assertInstanceOf(ef.getAccessibleObject(), Field.class, false);
+
+         Element<Annotation, Method> em = getSingleton(env.classHasMethodAnnotatedWith(annotationName));
+         ta = em.getAnnotation();
+         assertNotNull(ta);
+         assertEquals("method", getValue(ta));
+         assertInstanceOf(em.getAccessibleObject(), Method.class, false);
+
+         Set<Element<Annotation, AccessibleObject>> eps = env.classHasParameterAnnotatedWith(annotationName);
+         assertNotNull(eps);
+         assertEquals(2, eps.size());
+         for (Element<Annotation, AccessibleObject> ep : eps)
+         {
+            ta = ep.getAnnotation();
+            assertNotNull(ta);
+            Object value = getValue(ta);
+            AccessibleObject ao = ep.getAccessibleObject();
+            if ("cparameter".equals(value))
+               assertInstanceOf(ao, Constructor.class, false);
+            else if ("mparameter".equals(value))
+               assertInstanceOf(ao, Method.class, false);
+            else
+               fail("Illegal annotation value: " + value);
+         }
+      }
+      finally
+      {
+         assertUndeploy(deployer, deployment);
+      }
+   }
 }

Modified: projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java	2008-06-05 10:38:10 UTC (rev 74132)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java	2008-06-05 10:38:16 UTC (rev 74133)
@@ -34,6 +34,9 @@
  * Implementations should delay the actual class loading
  * until it's absolutely necessary.
  *
+ * All methods that have annotation name as parameter
+ * will use unit's classloader to load the actual annotation class.
+ *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
 public interface AnnotationEnvironment
@@ -55,6 +58,22 @@
    boolean hasClassAnnotatedWith(Class<? extends Annotation> annotation);
 
    /**
+    * Does this annotation environment contain a class
+    * which is annotated with annotation parameter.
+    * This only applies to annotations for ElementType.TYPE level.
+    *
+    * This method should be used if we have no intention
+    * to do real lookup of annotated classes, but we're
+    * only interested in existance of the annotation.
+    * e.g. deployment unit contains @Stateful EJBs
+    *
+    * @param annotationName the annotation name we're querying for
+    * @return true if there exists a class with annotation param
+    * @see #hasClassAnnotatedWith(Class annotation)
+    */
+   boolean hasClassAnnotatedWith(String annotationName);
+
+   /**
     * Get all classes annotated with annotation param.
     *
     * @param annotation the annotation we're querying for
@@ -63,6 +82,14 @@
    Set<Class<?>> classIsAnnotatedWith(Class<? extends Annotation> annotation);
 
    /**
+    * Get all classes annotated with annotation param.
+    *
+    * @param annotationName the annotation name we're querying for
+    * @return set of matching classes
+    */
+   Set<Class<?>> classIsAnnotatedWith(String annotationName);
+
+   /**
     * Get all classes who have some constructor annotated with annotation param.
     *
     * @param annotation the annotation we're querying for
@@ -71,6 +98,14 @@
    <A extends Annotation> Set<Element<A, Constructor>> classHasConstructorAnnotatedWith(Class<A> annotation);
 
    /**
+    * Get all classes who have some constructor annotated with annotation param.
+    *
+    * @param annotationName the annotation name we're querying for
+    * @return set of matching classes
+    */
+   Set<Element<Annotation, Constructor>> classHasConstructorAnnotatedWith(String annotationName);
+
+   /**
     * Get all classes who have some field annotated with annotation param.
     *
     * @param annotation the annotation we're querying for
@@ -79,6 +114,14 @@
    <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation);
 
    /**
+    * Get all classes who have some field annotated with annotation param.
+    *
+    * @param annotationName the annotation name we're querying for
+    * @return set of matching classes
+    */
+   Set<Element<Annotation, Field>> classHasFieldAnnotatedWith(String annotationName);
+
+   /**
     * Get all classes who have some method annotated with annotation param.
     *
     * @param annotation the annotation we're querying for
@@ -87,10 +130,26 @@
    <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation);
 
    /**
+    * Get all classes who have some method annotated with annotation param.
+    *
+    * @param annotationName the annotation name we're querying for
+    * @return set of matching classes
+    */
+   Set<Element<Annotation, Method>> classHasMethodAnnotatedWith(String annotationName);
+
+   /**
     * Get all classes who have some method's/constructor's parameter annotated with annotation param.
     *
     * @param annotation the annotation we're querying for
     * @return set of matching classes
     */
    <A extends Annotation> Set<Element<A, AccessibleObject>> classHasParameterAnnotatedWith(Class<A> annotation);
+
+   /**
+    * Get all classes who have some method's/constructor's parameter annotated with annotation param.
+    *
+    * @param annotationName the annotation name we're querying for
+    * @return set of matching classes
+    */
+   Set<Element<Annotation, AccessibleObject>> classHasParameterAnnotatedWith(String annotationName);
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanScanningUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanScanningUnitTestCase.java	2008-06-05 10:38:10 UTC (rev 74132)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanScanningUnitTestCase.java	2008-06-05 10:38:16 UTC (rev 74133)
@@ -23,9 +23,15 @@
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import org.jboss.beans.metadata.api.annotations.Bean;
 import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
 import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.classloader.plugins.filter.CombiningClassFilter;
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
 import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
 import org.jboss.classloading.spi.dependency.ClassLoading;
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
 import org.jboss.dependency.spi.ControllerContext;
@@ -41,8 +47,6 @@
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.test.deployers.vfs.deployer.AbstractDeployerUnitTest;
-import org.jboss.test.deployers.vfs.deployer.bean.support.BeanAnnotationHolder;
-import org.jboss.test.deployers.vfs.deployer.bean.support.BeanFactoryAnnotationHolder;
 
 /**
  * BeanScanningUnitTestCase.
@@ -85,9 +89,16 @@
       }
       vfsdd.setClassLoading(classLoading);
 
+      ClassLoaderSystem system = new DefaultClassLoaderSystem();
+      // allow MC annotations, so that both, deployer and tester see the same
+      ClassFilter mcAnnFilter = new PackageClassFilter(new String[]{"org.jboss.beans.metadata.api.annotations"});
+      ClassFilter filter = new CombiningClassFilter(false, new ClassFilter[]{ClassFilter.JAVA_ONLY, mcAnnFilter});
+      ParentPolicy policy = new ParentPolicy(filter, ClassFilter.NOTHING);
+      system.getDefaultDomain().setParentPolicy(policy);
+
       AbstractLevelClassLoaderSystemDeployer clsd = new AbstractLevelClassLoaderSystemDeployer();
       clsd.setClassLoading(classLoading);
-      clsd.setSystem(ClassLoaderSystem.getInstance());
+      clsd.setSystem(system);
 
       GenericAnnotationDeployer gad = new GenericAnnotationDeployer();
       KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
@@ -111,14 +122,20 @@
 
       ControllerContext testCC = controller.getInstalledContext("Test");
       assertNotNull(testCC);
-      assertInstanceOf(testCC.getTarget(), BeanAnnotationHolder.class, false);
+      Object testTarget = testCC.getTarget();
+      assertNotNull(testTarget);
+      Class<?> testClass = testTarget.getClass();
+      assertTrue(testClass.isAnnotationPresent(Bean.class));
 
       ControllerContext testCCBF = controller.getInstalledContext("TestBF");
       assertNotNull(testCCBF);
       Object target = testCCBF.getTarget();
       assertInstanceOf(target, BeanFactory.class, false);
       BeanFactory bf = (BeanFactory)target;
-      assertInstanceOf(bf.createBean(), BeanFactoryAnnotationHolder.class, false);
+      Object bfTarget = bf.createBean();
+      assertNotNull(bfTarget);
+      Class<?> bfTClass = bfTarget.getClass();
+      assertTrue(bfTClass.isAnnotationPresent(org.jboss.beans.metadata.api.annotations.BeanFactory.class));
 
       assertUndeploy(context);
       assertNull(controller.getContext("TestBF", null));

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/facelets/test/FaceletsUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/facelets/test/FaceletsUnitTestCase.java	2008-06-05 10:38:10 UTC (rev 74132)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/facelets/test/FaceletsUnitTestCase.java	2008-06-05 10:38:16 UTC (rev 74133)
@@ -26,7 +26,9 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
 import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
 import org.jboss.classloading.spi.dependency.ClassLoading;
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
 import org.jboss.deployers.plugins.classloading.AbstractLevelClassLoaderSystemDeployer;
@@ -88,9 +90,12 @@
       }
       vfsdd.setClassLoading(classLoading);
 
+      ClassLoaderSystem system = new DefaultClassLoaderSystem();
+      system.getDefaultDomain().setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
+
       AbstractLevelClassLoaderSystemDeployer clsd = new AbstractLevelClassLoaderSystemDeployer();
       clsd.setClassLoading(classLoading);
-      clsd.setSystem(ClassLoaderSystem.getInstance());
+      clsd.setSystem(system);
 
       addDeployer(main, cldd);
       addDeployer(main, vfsdd);




More information about the jboss-cvs-commits mailing list