[Jboss-cvs] JBossAS SVN: r56467 - in branches/MC_VDF_WORK/system-jmx: . src/resources src/resources/tests-support src/resources/tests-support/jar1 src/resources/tests-support/jar2 src/tests/org/jboss/test/classloading

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 31 00:56:51 EDT 2006


Author: scott.stark at jboss.org
Date: 2006-08-31 00:56:47 -0400 (Thu, 31 Aug 2006)
New Revision: 56467

Added:
   branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/
   branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar1/
   branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar1/resource1.xml
   branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar2/
   branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar2/resource1.xml
Modified:
   branches/MC_VDF_WORK/system-jmx/build-support-jars.xml
   branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading/UCLDomainClassLoaderTest.java
Log:
Add resource lookup tests

Modified: branches/MC_VDF_WORK/system-jmx/build-support-jars.xml
===================================================================
--- branches/MC_VDF_WORK/system-jmx/build-support-jars.xml	2006-08-31 04:49:05 UTC (rev 56466)
+++ branches/MC_VDF_WORK/system-jmx/build-support-jars.xml	2006-08-31 04:56:47 UTC (rev 56467)
@@ -12,6 +12,7 @@
         <attribute name="classpath" default="" description="Class-Path manifest value" />
         <sequential>
             <mkdir dir="${build.test.lib}" />
+        	   <mkdir dir="${build.test.resources}/@{name}" />
             <jar destfile="${build.test.lib}/@{name}.jar">
                 <manifest>
                   <attribute name="Class-Path" value="@{classpath}" />
@@ -21,9 +22,9 @@
                    <include name="org/jboss/test/support/@{package}/**"/>
                </fileset>
             	<!-- Include all resources under output/resources/tests-resources/@{name} -->
-               <fileset dir="${build.test.resources}">
-                   <include name="@{name}/**"/>
-               </fileset>
+               <zipfileset dir="${build.test.resources}/@{name}">
+                   <include name="**" />
+               </zipfileset>
             </jar>
         </sequential>
     </macrodef>

Added: branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar1/resource1.xml
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar1/resource1.xml	2006-08-31 04:49:05 UTC (rev 56466)
+++ branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar1/resource1.xml	2006-08-31 04:56:47 UTC (rev 56467)
@@ -0,0 +1 @@
+<root version="1.0.0" />

Added: branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar2/resource1.xml
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar2/resource1.xml	2006-08-31 04:49:05 UTC (rev 56466)
+++ branches/MC_VDF_WORK/system-jmx/src/resources/tests-support/jar2/resource1.xml	2006-08-31 04:56:47 UTC (rev 56467)
@@ -0,0 +1 @@
+<root version="2.0.0" />

Modified: branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading/UCLDomainClassLoaderTest.java
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading/UCLDomainClassLoaderTest.java	2006-08-31 04:49:05 UTC (rev 56466)
+++ branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading/UCLDomainClassLoaderTest.java	2006-08-31 04:56:47 UTC (rev 56467)
@@ -22,9 +22,11 @@
 package org.jboss.test.classloading;
 
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.security.ProtectionDomain;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Enumeration;
 
 import org.jboss.test.AbstractSystemTest;
 import org.jboss.mx.loading.DomainClassLoaderUCLImpl;
@@ -44,6 +46,10 @@
       "org.jboss.test.support.jar1.simple1.ISimpleBean",
       "org.jboss.test.support.jar2.simple1.Jar1Consumer"
    };
+   // Resources that should not be found in the unit test classpath
+   static String[] SUPPORT_RESOURCES = {
+      "resource1.xml"
+   };
 
    public UCLDomainClassLoaderTest(String name)
    {
@@ -72,6 +78,14 @@
             getLog().debug(name+" is not on unit test classpath");
          }
       }
+      for(String name : SUPPORT_RESOURCES)
+      {
+         URL resURL = tcl.getResource(name);
+         if( resURL != null )
+            fail("Was able to find "+name+", "+resURL);
+         else
+            getLog().debug(name+" is not on unit test classpath");
+      }
    }
 
 
@@ -99,8 +113,8 @@
    }
 
    /**
-    * Basic test of loading classes in /simple2.jar which has a Class-Path
-    * manifest entry pointing to /simple1.jar
+    * Basic test of loading classes in /jar2.jar which has a Class-Path
+    * manifest entry pointing to /jar1.jar
     *  
     * @throws Exception
     */
@@ -195,6 +209,126 @@
       assertSame(loader1, beanClass2.getClassLoader());
    }
 
+   /**
+    * Test finding resources in a single jar
+    * @throws Exception
+    */
+   public void testSimple1Resource()
+      throws Exception
+   {
+      UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
+      URL[] cp = buildClasspath("/jar1.jar");
+      getLog().info("Using classpath: "+Arrays.asList(cp));
+      DomainClassLoaderUCLImpl loader = new DomainClassLoaderUCLImpl(cp, repository);
+      URL resURL = repository.getResource("resource1.xml", loader);
+      assertNotNull(resURL);
+      getLog().info(resURL);
+      String path = resURL.getPath();
+      assertTrue("res path contains jar1.jar", path.indexOf("jar1.jar") > 0);
+
+      Enumeration<URL> resURLs = repository.findResources("resource1.xml");
+      int count = 0;
+      while( resURLs.hasMoreElements() )
+      {
+         getLog().info(resURLs.nextElement());
+         count ++;
+      }
+      assertEquals("1 resource1.xml", 1, count);
+   }
+
+   /**
+    * Basic test of finding resources in /jar2.jar which has a Class-Path
+    * manifest entry pointing to /jar1.jar
+    *  
+    * @throws Exception
+    */
+   public void testSimple2ResourcesWithManifestCP()
+      throws Exception
+   {
+      UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
+      URL[] cp = buildClasspath("/jar2CPjar1.jar");
+      getLog().info("Using classpath: "+Arrays.asList(cp));
+      DomainClassLoaderUCLImpl loader = new DomainClassLoaderUCLImpl(cp, repository);
+      URL resURL = repository.getResource("resource1.xml", loader);
+      assertNotNull(resURL);
+      getLog().info(resURL);
+      String path = resURL.getPath();
+      assertTrue("res path contains jar1.jar", path.indexOf("jar1.jar") > 0);
+
+      Enumeration<URL> resURLs = repository.findResources("resource1.xml");
+      int count = 0;
+      while( resURLs.hasMoreElements() )
+      {
+         getLog().info(resURLs.nextElement());
+         count ++;
+      }
+      assertEquals("1 resource1.xml", 1, count);
+   }
+
+   /**
+    * Test that multiple independent jars can be combined to form a resource path 
+    * @throws Exception
+    */
+   public void testMulitipleJarsResource()
+      throws Exception
+   {
+      UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
+      URL[] cp = buildClasspath("/jar1.jar", "/jar2.jar");
+      getLog().info("Using classpath: "+Arrays.asList(cp));
+      DomainClassLoaderUCLImpl loader = new DomainClassLoaderUCLImpl(cp, repository);
+      URL resURL = repository.getResource("resource1.xml", loader);
+      assertNotNull(resURL);
+      getLog().info(resURL);
+      String path = resURL.getPath();
+      assertTrue("res path contains jar1.jar", path.indexOf("jar1.jar") > 0);
+
+      Enumeration<URL> resURLs = repository.findResources("resource1.xml");
+      int count = 0;
+      while( resURLs.hasMoreElements() )
+      {
+         getLog().info(resURLs.nextElement());
+         count ++;
+      }
+      assertEquals("2 resource1.xml", 2, count);
+   }
+
+   /**
+    * Test that multiple class loaders combine to form a uniform repository
+    * for resources
+    * @throws Exception
+    */
+   public void testMutipleClassLoadersResource()
+      throws Exception
+   {
+      UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
+      URL[] cp1 = buildClasspath("/jar1.jar");
+      URL[] cp2 = buildClasspath("/jar2.jar");
+      getLog().info("Using classpath: "+Arrays.asList(cp1));
+      DomainClassLoaderUCLImpl loader1 = new DomainClassLoaderUCLImpl(cp1, repository);
+      loader1.getURLs();
+      getLog().info("Using classpath: "+Arrays.asList(cp2));
+      DomainClassLoaderUCLImpl loader2 = new DomainClassLoaderUCLImpl(cp2, repository);
+      URL resURL = repository.getResource("resource1.xml", loader1);
+      assertNotNull(resURL);
+      getLog().info(resURL);
+      String path = resURL.getPath();
+      assertTrue("res path contains jar1.jar", path.indexOf("jar1.jar") > 0);
+      resURL = repository.getResource("resource1.xml", loader2);
+      assertNotNull(resURL);
+      getLog().info(resURL);
+      path = resURL.getPath();
+      assertTrue("res path contains jar2.jar", path.indexOf("jar2.jar") > 0);
+
+      Enumeration<URL> resURLs = repository.findResources("resource1.xml");
+      int count = 0;
+      while( resURLs.hasMoreElements() )
+      {
+         getLog().info(resURLs.nextElement());
+         count ++;
+      }
+      assertEquals("2 resource1.xml", 2, count);
+   }
+
    private URL[] buildClasspath(String... jars)
    {
       ArrayList<URL> cp = new ArrayList<URL>();




More information about the jboss-cvs-commits mailing list