[jboss-cvs] JBossAS SVN: r72921 - in projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations: test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 1 07:36:27 EDT 2008


Author: alesj
Date: 2008-05-01 07:36:27 -0400 (Thu, 01 May 2008)
New Revision: 72921

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoader.java
   projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoaderSystemDeployer.java
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/AnnotationsTest.java
Log:
Check if class was loaded during scanning.

Added: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoader.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoader.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoader.java	2008-05-01 11:36:27 UTC (rev 72921)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.deployers.annotations.support;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * InterceptionClassLoader.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class InterceptionClassLoader extends ClassLoader
+{
+   private ClassLoader delegate;
+   private Set<String> loaded = new HashSet<String>();
+
+   public InterceptionClassLoader(ClassLoader delegate)
+   {
+      super();
+
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate.");
+      this.delegate = delegate;
+   }
+
+   public Set<String> getLoaded()
+   {
+      return loaded;
+   }
+
+   public ClassLoader getDelegate()
+   {
+      return delegate;
+   }
+
+   public Class<?> loadClass(String name) throws ClassNotFoundException
+   {
+      loaded.add(name);
+      return delegate.loadClass(name);
+   }
+
+   public URL getResource(String name)
+   {
+      return delegate.getResource(name);
+   }
+
+   public Enumeration<URL> getResources(String name) throws IOException
+   {
+      return delegate.getResources(name);
+   }
+
+   public InputStream getResourceAsStream(String name)
+   {
+      return delegate.getResourceAsStream(name);
+   }
+
+   public synchronized void setDefaultAssertionStatus(boolean enabled)
+   {
+      delegate.setDefaultAssertionStatus(enabled);
+   }
+
+   public synchronized void setPackageAssertionStatus(String packageName, boolean enabled)
+   {
+      delegate.setPackageAssertionStatus(packageName, enabled);
+   }
+
+   public synchronized void setClassAssertionStatus(String className, boolean enabled)
+   {
+      delegate.setClassAssertionStatus(className, enabled);
+   }
+
+   public synchronized void clearAssertionStatus()
+   {
+      delegate.clearAssertionStatus();
+   }
+
+   public int hashCode()
+   {
+      return delegate.hashCode();
+   }
+
+   public boolean equals(Object obj)
+   {
+      return delegate.equals(obj);
+   }
+
+   public String toString()
+   {
+      return delegate.toString();
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoaderSystemDeployer.java (from rev 72857, projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockLevelClassLoaderSystemDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoaderSystemDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/InterceptionClassLoaderSystemDeployer.java	2008-05-01 11:36:27 UTC (rev 72921)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.deployers.annotations.support;
+
+import org.jboss.deployers.plugins.classloading.AbstractLevelClassLoaderSystemDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+
+/**
+ * InterceptionClassLoaderSystemDeployer.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class InterceptionClassLoaderSystemDeployer extends AbstractLevelClassLoaderSystemDeployer
+{
+   private InterceptionClassLoader classLoader;
+
+   public ClassLoader createClassLoader(DeploymentUnit unit) throws Exception
+   {
+      ClassLoader loader = super.createClassLoader(unit);
+      classLoader = new InterceptionClassLoader(loader);
+      return classLoader;
+   }
+
+   @Override
+   public void removeClassLoader(DeploymentUnit unit) throws Exception
+   {
+      Module module = unit.getAttachment(Module.class);
+      if (module == null)
+         return;
+
+      ClassLoader classLoader = unit.getClassLoader();
+      if (classLoader instanceof InterceptionClassLoader)
+      {
+         InterceptionClassLoader icl = (InterceptionClassLoader)classLoader;
+         classLoader = icl.getDelegate();
+      }
+
+      try
+      {
+         try
+         {
+            // Remove the classloader
+            getSystem().unregisterClassLoader(classLoader);
+         }
+         finally
+         {
+            // Try to tidy up empty domains
+            String domainName = module.getDeterminedDomainName();
+            if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(domainName) == false)
+            {
+               ClassLoaderDomain domain = getSystem().getDomain(domainName);
+               if (domain.hasClassLoaders() == false)
+                  getSystem().unregisterDomain(domain);
+            }
+         }
+      }
+      finally
+      {
+         cleanup(unit, module);
+         module.reset();
+      }
+   }
+
+   public InterceptionClassLoader getClassLoader()
+   {
+      return classLoader;
+   }
+}
\ No newline at end of file

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-05-01 10:50:50 UTC (rev 72920)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java	2008-05-01 11:36:27 UTC (rev 72921)
@@ -75,12 +75,18 @@
          ClassLoader cl = unit.getClassLoader();
          Class<TestAnnotation> taClass = (Class<TestAnnotation>)cl.loadClass("org.jboss.test.deployers.annotations.support.TestAnnotation");
 
+         assertNotLoaded("org.jboss.test.deployers.annotations.support.AnnotationsHolder");
+         // annotations are loaded, OK?
+         assertLoaded("org.jboss.test.deployers.annotations.support.TestAnnotation");
+
          AnnotationEnvironment env = getAnnotationEnvironment(unit);
          Set<Class<?>> classes = env.classIsAnnotatedWith(taClass);
          assertNotNull(classes);
          assertEquals(1, classes.size());
          assertEquals(AnnotationsHolder.class.getName(), classes.iterator().next().getName());
 
+         assertLoaded("org.jboss.test.deployers.annotations.support.AnnotationsHolder");
+
          Element<TestAnnotation, Constructor> ec = getSingleton(env.classHasConstructorAnnotatedWith(taClass));
          Annotation ta = ec.getAnnotation();
          assertNotNull(ta);
@@ -121,9 +127,4 @@
          assertUndeploy(deployer, deployment);
       }
    }
-
-   public void testClassNotLoaded() throws Exception
-   {
-      // TODO
-   }
 }

Modified: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java	2008-05-01 10:50:50 UTC (rev 72920)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java	2008-05-01 11:36:27 UTC (rev 72921)
@@ -45,8 +45,9 @@
 import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
 import org.jboss.deployers.spi.deployer.Deployer;
 import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.annotations.support.InterceptionClassLoaderSystemDeployer;
+import org.jboss.test.deployers.annotations.support.InterceptionClassLoader;
 import org.jboss.test.deployers.classloading.support.MockClassLoaderDescribeDeployer;
-import org.jboss.test.deployers.classloading.support.MockLevelClassLoaderSystemDeployer;
 
 /**
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
@@ -56,7 +57,7 @@
    private static ClassLoadingMetaDataFactory classLoadingMetaDataFactory = ClassLoadingMetaDataFactory.getInstance();
 
    protected AbstractClassLoaderDescribeDeployer deployer1;
-   protected MockLevelClassLoaderSystemDeployer deployer2;
+   protected InterceptionClassLoaderSystemDeployer deployer2;
 
    protected AnnotationsTest(String name)
    {
@@ -133,6 +134,24 @@
       return clazz.getMethod("value").invoke(annotation);
    }
 
+   protected void assertNotLoaded(String className)
+   {
+      assertCheckLoaded(className, false);
+   }
+
+   protected void assertLoaded(String className)
+   {
+      assertCheckLoaded(className, true);      
+   }
+
+   private void assertCheckLoaded(String className, boolean checkFlag)
+   {
+      InterceptionClassLoader icl = deployer2.getClassLoader();
+      Set<String> loaded = icl.getLoaded();
+      assertNotNull(loaded);
+      assertEquals(loaded.contains(className), checkFlag);
+   }
+
    protected DeployerClient getMainDeployer(Deployer... deployers)
    {
       ClassLoading classLoading = new ClassLoading();
@@ -142,7 +161,7 @@
       deployer1 = new MockClassLoaderDescribeDeployer();
       deployer1.setClassLoading(classLoading);
 
-      deployer2 = new MockLevelClassLoaderSystemDeployer();
+      deployer2 = new InterceptionClassLoaderSystemDeployer();
       deployer2.setClassLoading(classLoading);
       deployer2.setSystem(system);
 




More information about the jboss-cvs-commits mailing list