[jboss-cvs] JBossAS SVN: r104005 - in projects/scanning/trunk: scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 15 10:19:41 EDT 2010


Author: alesj
Date: 2010-04-15 10:19:38 -0400 (Thu, 15 Apr 2010)
New Revision: 104005

Added:
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.java
   projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/indexer/
   projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/indexer/test/
   projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.xml
Modified:
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/WeakClassLoaderHolder.java
Log:
Prepare pre-indexed tests.

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java	2010-04-15 14:16:19 UTC (rev 104004)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java	2010-04-15 14:19:38 UTC (rev 104005)
@@ -53,9 +53,26 @@
    /** Should we keep the annotation */
    private boolean keepAnnotations;
 
+   /**
+    * Should only be used for de-serialization.
+    */
+   public DefaultAnnotationRepository()
+   {
+      super();
+      init();
+   }
+
    public DefaultAnnotationRepository(ClassLoader classLoader)
    {
       super(classLoader);
+      init();
+   }
+
+   /**
+    * Init.
+    */
+   protected void init()
+   {
       env = new HashMap<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>>();
       checkedClassNames = new HashSet<String>();
    }

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java	2010-04-15 14:16:19 UTC (rev 104004)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java	2010-04-15 14:19:38 UTC (rev 104005)
@@ -37,6 +37,14 @@
  */
 public abstract class MutableAnnotationRepository extends WeakClassLoaderHolder implements AnnotationIndex
 {
+   /**
+    * Should only be used for de-serialization.
+    */
+   public MutableAnnotationRepository()
+   {
+      super();
+   }
+
    protected MutableAnnotationRepository(ClassLoader classLoader)
    {
       super(classLoader);

Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/WeakClassLoaderHolder.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/WeakClassLoaderHolder.java	2010-04-15 14:16:19 UTC (rev 104004)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/WeakClassLoaderHolder.java	2010-04-15 14:19:38 UTC (rev 104005)
@@ -22,10 +22,10 @@
 
 package org.jboss.scanning.plugins.helpers;
 
+import java.lang.ref.WeakReference;
+
 import org.jboss.util.JBossObject;
 
-import java.lang.ref.WeakReference;
-
 /**
  * ClassLoader holder helper.
  *
@@ -35,6 +35,14 @@
 {
    private transient WeakReference<ClassLoader> clRef;
 
+   /**
+    * Should only be used for de-serialization.
+    */
+   public WeakClassLoaderHolder()
+   {
+      this(Thread.currentThread().getContextClassLoader());
+   }
+
    public WeakClassLoaderHolder(ClassLoader classLoader)
    {
       if (classLoader == null)

Copied: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.java (from rev 103997, projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerSmokeTestCase.java)
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.java	                        (rev 0)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.java	2010-04-15 14:19:38 UTC (rev 104005)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.indexer.test;
+
+import javax.persistence.Entity;
+
+import java.net.URL;
+import java.util.Set;
+
+import org.jboss.classloader.plugins.filter.CombiningClassFilter;
+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.ClassFilterUtils;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
+import org.jboss.scanning.annotations.spi.AnnotationRepository;
+import org.jboss.scanning.annotations.spi.Element;
+import org.jboss.scanning.spi.helpers.AbstractScanner;
+import org.jboss.test.scanning.ScanningDeployersTest;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+
+import junit.framework.Test;
+import org.hibernate.ejb.packaging.Scanner;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class IndexerRuntimeTestCase extends ScanningDeployersTest
+{
+   public IndexerRuntimeTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(IndexerRuntimeTestCase.class);
+   }
+
+   public void testBasicUsage() throws Exception
+   {
+      testUsage("defaultpar", false);
+   }
+
+   public void testPreIndexedUsage() throws Exception
+   {
+      // testUsage("pre-defaultpar", true);
+   }
+
+   protected void testUsage(String name, boolean preIndexed) throws Exception
+   {
+      ClassLoaderSystem system = (ClassLoaderSystem) getBean("ClassLoaderSystem", ControllerState.INSTALLED);
+      // we need to see hibernate/jpa
+      ClassFilter hibernateFilter = new PackageClassFilter(new String[]{Scanner.class.getPackage().getName(), Entity.class.getPackage().getName()});
+      ClassFilter before = new CombiningClassFilter(false, new ClassFilter[]{ClassFilterUtils.JAVA_ONLY, hibernateFilter});
+      ParentPolicy parentPolicy = new ParentPolicy(before, ClassFilterUtils.NOTHING);
+      system.getDefaultDomain().setParentPolicy(parentPolicy);
+
+      URL url = getResource("/hibernate/" + name + ".jar");
+      VirtualFile file = VFS.getChild(url);
+      Deployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
+      if (preIndexed)
+         ((MutableAttachments)(deployment.getPredeterminedManagedObjects())).addAttachment(AbstractScanner.IGNORE_RUNTIME_SCAN, true);
+      getDeployerClient().deploy(deployment);
+
+      DeploymentUnit unit = getMainDeployerStructure().getDeploymentUnit(deployment.getName());
+      try
+      {
+         AnnotationRepository repository = unit.getAttachment(AnnotationIndex.class);
+         assertNotNull(repository);
+         // annotations
+         Set<Element<Entity,Class<?>>> classes = repository.classIsAnnotatedWith(Entity.class);
+         assertFalse(classes.isEmpty());
+      }
+      finally
+      {
+         undeploy(unit);
+      }
+   }
+}
\ No newline at end of file

Copied: projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.xml (from rev 103689, projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/hibernate/test/HibernateUnitTestCase.xml)
===================================================================
--- projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.xml	                        (rev 0)
+++ projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/indexer/test/IndexerRuntimeTestCase.xml	2010-04-15 14:19:38 UTC (rev 104005)
@@ -0,0 +1,12 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="jpa-deployer" class="org.jboss.test.scanning.hibernate.support.MockJPADeployer"/>  
+
+  <bean name="AnnEnvDeployer" class="org.jboss.scanning.deployers.ScanningDeployer">
+    <incallback method="addFactory" />
+    <uncallback method="removeFactory" />
+  </bean>
+
+  <bean name="AnnScanningPlugin" class="org.jboss.scanning.annotations.plugins.AnnotationsScanningPluginFactory" />
+
+</deployment>




More information about the jboss-cvs-commits mailing list