[Jboss-cvs] JBossAS SVN: r56429 - branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 30 03:52:17 EDT 2006
Author: scott.stark at jboss.org
Date: 2006-08-30 03:52:15 -0400 (Wed, 30 Aug 2006)
New Revision: 56429
Modified:
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading/UCLDomainClassLoaderTest.java
Log:
Correct the loadClassFromClassLoader and drop the getURLs() override as this should be handled by the JBossRMIClassLoader
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-30 06:23:58 UTC (rev 56428)
+++ branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/classloading/UCLDomainClassLoaderTest.java 2006-08-30 07:52:15 UTC (rev 56429)
@@ -22,6 +22,7 @@
package org.jboss.test.classloading;
import java.net.URL;
+import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
@@ -37,13 +38,44 @@
*/
public class UCLDomainClassLoaderTest extends AbstractSystemTest
{
+ // Classes that should not be found in the unit test classpath
+ static String[] SUPPORT_CLASSES = {
+ "org.jboss.test.support.jar1.simple1.Bean1",
+ "org.jboss.test.support.jar1.simple1.ISimpleBean",
+ "org.jboss.test.support.jar2.simple1.Jar1Consumer"
+ };
public UCLDomainClassLoaderTest(String name)
{
super(name);
}
+
/**
+ * Validate that SUPPORT_CLASSES are not on the unit test classpath
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ // Assert that Bean1 is not visible to this test class loader
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ for(String name : SUPPORT_CLASSES)
+ {
+ try
+ {
+ Class beanClass = tcl.loadClass(name);
+ fail("Was able to find "+name+", "+beanClass.getProtectionDomain());
+ }
+ catch(ClassNotFoundException e)
+ {
+ getLog().debug(name+" is not on unit test classpath");
+ }
+ }
+ }
+
+
+ /**
* Basic test of loading classes from /simple1.jar
* @throws Exception
*/
@@ -51,16 +83,6 @@
throws Exception
{
String beanClassName = "org.jboss.test.support.jar1.simple1.Bean1";
- // Assert that Bean1 is not visible to this test class loader
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- try
- {
- Class beanClass = tcl.loadClass(beanClassName);
- fail("Was able to find "+beanClassName+", "+beanClass.getProtectionDomain());
- }
- catch(ClassNotFoundException e)
- {
- }
UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
URL[] cp = buildClasspath("/jar1.jar");
@@ -68,7 +90,12 @@
DomainClassLoaderUCLImpl loader = new DomainClassLoaderUCLImpl(cp, repository);
Class beanClass = repository.loadClass(beanClassName);
assertNotNull(beanClass);
- getLog().info(beanClass+", PD: "+beanClass.getProtectionDomain());
+ ProtectionDomain pd = beanClass.getProtectionDomain();
+ getLog().info(beanClass+", PD: "+pd);
+ String path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("Bean1.PD ends with jar1.jar", path.endsWith("jar1.jar"));
+ Object bean = beanClass.newInstance();
+ assertSame(loader, bean.getClass().getClassLoader());
}
/**
@@ -80,27 +107,94 @@
public void testSimple2JarWithManifestCP()
throws Exception
{
- String beanClassName = "org.jboss.test.support.jar1.simple1.Bean1";
- // Assert that Bean1 is not visible to this test class loader
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- try
- {
- Class beanClass = tcl.loadClass(beanClassName);
- fail("Was able to find "+beanClassName+", "+beanClass.getProtectionDomain());
- }
- catch(ClassNotFoundException e)
- {
- }
+ String beanClassName = "org.jboss.test.support.jar2.Jar1Consumer";
UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
- URL[] cp = buildClasspath("/jar1.jar");
+ URL[] cp = buildClasspath("/jar2CPjar1.jar");
getLog().info("Using classpath: "+Arrays.asList(cp));
DomainClassLoaderUCLImpl loader = new DomainClassLoaderUCLImpl(cp, repository);
Class beanClass = repository.loadClass(beanClassName);
assertNotNull(beanClass);
- getLog().info(beanClass+", PD: "+beanClass.getProtectionDomain());
+ ProtectionDomain pd = beanClass.getProtectionDomain();
+ getLog().info(beanClass+", PD: "+pd);
+ String path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("Jar1Consumer.PD ends with jar2CPjar1.jar", path.endsWith("jar2CPjar1.jar"));
+ Object bean = beanClass.newInstance();
+ assertSame(loader, bean.getClass().getClassLoader());
+
+ Class beanClass2 = repository.loadClass("org.jboss.test.support.jar1.simple1.ISimpleBean");
+ assertNotNull(beanClass);
+ pd = beanClass2.getProtectionDomain();
+ getLog().info(beanClass2+", PD: "+pd);
+ path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("ISimpleBean.PD ends with jar1.jar", path.endsWith("jar1.jar"));
+ assertSame(loader, beanClass2.getClassLoader());
}
+ /**
+ * Test that multiple independent jars can be combined to form a classpath
+ * @throws Exception
+ */
+ public void testMulitipleJars()
+ throws Exception
+ {
+ String beanClassName = "org.jboss.test.support.jar2.Jar1Consumer";
+ UnifiedLoaderRepositoryDCL repository = new UnifiedLoaderRepositoryDCL();
+ URL[] cp = buildClasspath("/jar1.jar", "/jar2.jar");
+ getLog().info("Using classpath: "+Arrays.asList(cp));
+ DomainClassLoaderUCLImpl loader = new DomainClassLoaderUCLImpl(cp, repository);
+ Class beanClass = repository.loadClass(beanClassName);
+ assertNotNull(beanClass);
+ ProtectionDomain pd = beanClass.getProtectionDomain();
+ getLog().info(beanClass+", PD: "+pd);
+ String path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("Jar1Consumer.PD ends with jar2.jar", path.endsWith("jar2.jar"));
+ Object bean = beanClass.newInstance();
+ assertSame(loader, bean.getClass().getClassLoader());
+
+ Class beanClass2 = repository.loadClass("org.jboss.test.support.jar1.simple1.ISimpleBean");
+ assertNotNull(beanClass);
+ pd = beanClass2.getProtectionDomain();
+ getLog().info(beanClass2+", PD: "+pd);
+ path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("ISimpleBean.PD ends with jar1.jar", path.endsWith("jar1.jar"));
+ assertSame(loader, beanClass2.getClassLoader());
+ }
+
+ /**
+ * Test that multiple class loaders combine to form a uniform repository
+ * @throws Exception
+ */
+ public void testMutipleClassLoaders()
+ throws Exception
+ {
+ String beanClassName = "org.jboss.test.support.jar2.Jar1Consumer";
+ 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);
+ Class beanClass = loader1.loadClass(beanClassName);
+ assertNotNull(beanClass);
+ ProtectionDomain pd = beanClass.getProtectionDomain();
+ getLog().info(beanClass+", PD: "+pd);
+ String path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("Jar1Consumer.PD ends with jar2.jar", path.endsWith("jar2.jar"));
+ Object bean = beanClass.newInstance();
+ assertSame(loader2, bean.getClass().getClassLoader());
+
+ Class beanClass2 = repository.loadClass("org.jboss.test.support.jar1.simple1.ISimpleBean");
+ assertNotNull(beanClass);
+ pd = beanClass2.getProtectionDomain();
+ getLog().info(beanClass2+", PD: "+pd);
+ path = pd.getCodeSource().getLocation().getPath();
+ assertTrue("ISimpleBean.PD ends with jar1.jar", path.endsWith("jar1.jar"));
+ assertSame(loader1, beanClass2.getClassLoader());
+ }
+
private URL[] buildClasspath(String... jars)
{
ArrayList<URL> cp = new ArrayList<URL>();
More information about the jboss-cvs-commits
mailing list