[jboss-cvs] JBossAS SVN: r64255 - in projects/microcontainer/trunk/classloader: src/main/org/jboss/classloader/test/support and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 24 12:59:37 EDT 2007


Author: adrian at jboss.org
Date: 2007-07-24 12:59:37 -0400 (Tue, 24 Jul 2007)
New Revision: 64255

Added:
   projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/IsolatedClassLoaderTest.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/JUnitTestSuite.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/notsupport/
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/notsupport/NotSupport.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/support/
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/support/Support.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/test/
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/test/IsolatedClassLoaderUnitTestCase.java
Modified:
   projects/microcontainer/trunk/classloader/pom.xml
   projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/MockClassLoaderPolicy.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/ClassLoaderAllTestSuite.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/domain/test/ParentPolicyUnitTestCase.java
Log:
Add an abstract isolated classloader test support class
that can be used to control classloading inside a unit test.

Modified: projects/microcontainer/trunk/classloader/pom.xml
===================================================================
--- projects/microcontainer/trunk/classloader/pom.xml	2007-07-24 16:58:00 UTC (rev 64254)
+++ projects/microcontainer/trunk/classloader/pom.xml	2007-07-24 16:59:37 UTC (rev 64255)
@@ -19,6 +19,22 @@
     </testResources>
   </build>
   <!-- Do not add version information here, use ../build/pom.xml instead -->
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>jboss</groupId>
+        <artifactId>jboss-test</artifactId>
+        <version>${version.jboss.test}</version>
+        <scope>compile</scope>
+      </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>${version.junit}</version>
+        <scope>compile</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
   <dependencies>
     <!-- Global dependencies -->
     <dependency>

Added: projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/IsolatedClassLoaderTest.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/IsolatedClassLoaderTest.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/IsolatedClassLoaderTest.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -0,0 +1,276 @@
+/*
+ * 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.classloader.test.support;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+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.logging.Logger;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.logging.LoggingPlugin;
+import org.jboss.test.security.PolicyPlugin;
+
+/**
+ * IsolatedClassLoaderTest.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class IsolatedClassLoaderTest extends AbstractTestCaseWithSetup
+{
+   // The last classloader system
+   private static ClassLoaderSystem system;
+
+   /**
+    * Get the delegate
+    * 
+    * @param clazz the test class
+    * @return the delegate
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz)
+   {
+      return new AbstractTestDelegate(clazz);
+   }
+
+   /**
+    * Create a test with just test's package visible
+    * and the default parent packages
+    *
+    * It imports nothing
+    * 
+    * @param clazz the test class
+    * @return the test
+    */
+   public static Test suite(Class<?> clazz)
+   {
+      return suite(clazz, false);
+   }
+
+   /**
+    * Create a test with just test's package visible
+    * and the default parent packages
+    * 
+    * It exports everything
+    * 
+    * @param clazz the test class
+    * @param importAll whether to import all
+    * @return the test
+    */
+   public static Test suite(Class<?> clazz, boolean importAll)
+   {
+      return suite(clazz, importAll, new Class[0]);
+   }
+   
+   /**
+    * Create a test with test's package visible and the packages
+    * of the classes listed with the default parent packages
+    * 
+    * It exports everything
+    * It imports nothing
+    * 
+    * @see #getParentPackages()
+    * @param clazz the test class
+    * @param packages the classes in packages that should also be included
+    * @return the test
+    */
+   public static Test suite(Class<?> clazz, Class<?>... packages)
+   {
+      return suite(clazz, false, getParentPackages(), packages);
+   }
+   
+   /**
+    * Create a test with test's package visible and the packages
+    * of the classes listed with the default parent packages
+    *
+    * It exports everything
+    * 
+    * @see #getParentPackages()
+    * @param importAll whether to import all
+    * @param clazz the test class
+    * @param packages the classes in packages that should also be included
+    * @return the test
+    */
+   public static Test suite(Class<?> clazz, boolean importAll, Class<?>... packages)
+   {
+      return suite(clazz, importAll, getParentPackages(), packages);
+   }
+   
+   /**
+    * Create a test with test's package visible and the packages
+    * of the classes listed
+    * 
+    * It exports everything
+    * 
+    * @see #getParentPackages()
+    * @param clazz the test class
+    * @param importAll whether to import all
+    * @param parentPackages the packages that are not isolated
+    * @param packages the classes in packages that should also be included
+    * @return the test
+    */
+   public static Test suite(Class<?> clazz, boolean importAll, Set<String> parentPackages, Class<?>... packages)
+   {
+      // A new classloader system for each test
+      system = new DefaultClassLoaderSystem();
+
+      // The parent filter
+      PackageClassFilter filter = new PackageClassFilter(parentPackages.toArray(new String[parentPackages.size()]));
+      filter.setIncludeJava(true);
+      ParentPolicy parentPolicy = new ParentPolicy(filter, ClassFilter.NOTHING);
+      ClassLoaderDomain domain = system.createAndRegisterDomain("TEST", parentPolicy);
+      
+      // Configure the policy for the test
+      MockClassLoaderPolicy policy = new MockClassLoaderPolicy();
+      Set<Class> classes = new HashSet<Class>();
+      classes.add(clazz);
+      for (Class<?> c : packages)
+         classes.add(c);
+      policy.setImportAll(importAll);
+      policy.setPathsAndPackageNames(classes.toArray(new Class[classes.size()]));
+      
+      // Create the classloader
+      ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
+
+      // Load the class from the isolated classloader
+      try
+      {
+         clazz = classLoader.loadClass(clazz.getName());
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException("Unable to load test class in isolated classloader " + clazz, e);
+      }
+      
+      // Create the test based on the isolated class
+      return AbstractTestCaseWithSetup.suite(clazz);
+   }
+
+   /**
+    * Get the packages that should not be isolated
+    * (and by transience their dependent classes, e.g. log4j in the classpath)<p>
+    * 
+    * NOTE: The transient packages cannot be used directly by the test
+    * unless explicity mentioned in this list.
+    * 
+    * @return the test support packages
+    */
+   public static Set<String> getParentPackages()
+   {
+      Set<String> result = new HashSet<String>();
+      result.add(Test.class.getPackage().getName());
+      result.add(TestSetup.class.getPackage().getName());
+      result.add(AbstractTestCaseWithSetup.class.getPackage().getName());
+      result.add(Logger.class.getPackage().getName());
+      result.add(LoggingPlugin.class.getPackage().getName());
+      result.add(PolicyPlugin.class.getPackage().getName());
+      result.add(ClassLoaderSystem.class.getPackage().getName());
+      result.add(IsolatedClassLoaderTest.class.getPackage().getName());
+      return result;
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      configureLogging();
+   }
+
+   /**
+    * Create a new IsolatedClassLoaderTest.
+    * 
+    * @param name the test name
+    */
+   public IsolatedClassLoaderTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Get the classloader system, this will be configured with
+    * a domain called TEST that includes the test case's classloader
+    * 
+    * @return the classloader
+    */
+   public ClassLoaderSystem getClassLoaderSystem()
+   {
+      return system;
+   }
+   
+   /**
+    * Create a classloader
+    *
+    * It exports everything
+    * It imports everything
+    * 
+    * @param name the name
+    * @param packages the packages
+    * @return the classloader
+    * @throws Exception for any error
+    */
+   protected ClassLoader createClassLoader(String name, String packages) throws Exception
+   {
+      return createClassLoader(name, true, packages);
+   }
+   
+   /**
+    * Create a classloader
+    * 
+    * It exports everything
+    *
+    * @param name the name
+    * @param importAll whether to import all
+    * @param packages the packages
+    * @return the classloader
+    * @throws Exception for any error
+    */
+   protected ClassLoader createClassLoader(String name, boolean importAll, String packages) throws Exception
+   {
+      ClassLoaderSystem system = getClassLoaderSystem();
+      ClassLoaderDomain domain = system.getDomain("TEST");
+      MockClassLoaderPolicy policy = MockClassLoaderHelper.createMockClassLoaderPolicy(name);
+      policy.setImportAll(importAll);
+      policy.setPathsAndPackageNames(packages);
+      return MockClassLoaderHelper.registerMockClassLoader(system, domain, policy);
+   }
+
+   /**
+    * Unregister a classloader
+    * 
+    * @param classLoader the classloader
+    * @throws Exception for any error
+    */
+   protected void unregisterClassLoader(ClassLoader classLoader) throws Exception
+   {
+      ClassLoaderSystem system = getClassLoaderSystem();
+      system.unregisterClassLoader(classLoader);
+   }
+}

Modified: projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/MockClassLoaderPolicy.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/MockClassLoaderPolicy.java	2007-07-24 16:58:00 UTC (rev 64254)
+++ projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/test/support/MockClassLoaderPolicy.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -272,6 +272,26 @@
       setPaths(classes);
       setPackageNames(classes);
    }
+
+   /**
+    * Set the paths and the exported package names
+    * 
+    * @param packages the packages
+    */
+   public void setPathsAndPackageNames(String... packages)
+   {
+      if (packages == null)
+      {
+         paths = null;
+         packageNames = null;
+         return;
+      }
+      paths = new String[packages.length];
+      for (int i = 0; i < packages.length; ++i)
+         paths[i] = packages[i].replace('.', '/');
+      
+      setPackageNames(packages);
+   }
    
    @Override
    public boolean isImportAll()

Modified: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java	2007-07-24 16:58:00 UTC (rev 64254)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -21,7 +21,10 @@
  */
 package org.jboss.test.classloader;
 
+import junit.framework.TestCase;
+
 import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
 import org.jboss.classloader.spi.ClassLoaderDomain;
 import org.jboss.classloader.spi.ClassLoaderPolicy;
 import org.jboss.classloader.spi.ClassLoaderSystem;
@@ -40,6 +43,12 @@
  */
 public abstract class AbstractClassLoaderTest extends AbstractTestCaseWithSetup
 {
+   static
+   {
+      // Make sure the mock classloader doesn't think we are part of the JDK
+      AbstractJDKChecker.getExcluded().add(TestCase.class);
+   }
+   
    public static AbstractTestDelegate getDelegate(Class<?> clazz)
    {
       return new AbstractTestDelegate(clazz);
@@ -185,6 +194,7 @@
       try
       {
          start.loadClass(name);
+         fail("Should not be here!");
       }
       catch (Exception expected)
       {

Modified: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/ClassLoaderAllTestSuite.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/ClassLoaderAllTestSuite.java	2007-07-24 16:58:00 UTC (rev 64254)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/ClassLoaderAllTestSuite.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -30,6 +30,7 @@
 import org.jboss.test.classloader.domain.ClassLoaderDomainTestSuite;
 import org.jboss.test.classloader.filter.FilterTestSuite;
 import org.jboss.test.classloader.jmx.JMXTestSuite;
+import org.jboss.test.classloader.junit.JUnitTestSuite;
 import org.jboss.test.classloader.old.OldTestSuite;
 import org.jboss.test.classloader.policy.test.ClassLoaderPolicyUnitTestCase;
 import org.jboss.test.classloader.resources.ResourceTestSuite;
@@ -71,6 +72,7 @@
       suite.addTest(DelegateTestSuite.suite());
       suite.addTest(ResourceTestSuite.suite());
       suite.addTest(JMXTestSuite.suite());
+      suite.addTest(JUnitTestSuite.suite());
       
       return suite;
    }

Modified: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/domain/test/ParentPolicyUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/domain/test/ParentPolicyUnitTestCase.java	2007-07-24 16:58:00 UTC (rev 64254)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/domain/test/ParentPolicyUnitTestCase.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -27,6 +27,7 @@
 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.classloader.test.support.MockClassLoaderPolicy;
 import org.jboss.test.classloader.AbstractClassLoaderTestWithSecurity;
 import org.jboss.test.classloader.domain.support.MatchClassFilter;
@@ -227,4 +228,38 @@
       assertLoadClass(ClassLoaderDomain.class, classLoader, null, true);
       assertTrue("Should have been filtered", filter.filtered);
    }
+   
+   public void testNoMatchBeforeAndAfter() throws Exception
+   {
+      ClassLoaderSystem system = createClassLoaderSystem();
+      ParentPolicy parentPolicy = new ParentPolicy(ClassFilter.NOTHING, ClassFilter.NOTHING);
+      ClassLoaderDomain domain = system.createAndRegisterDomain("test", parentPolicy, null);
+      MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
+      ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
+      enableTrace("org.jboss.classloader");
+      assertLoadClassFail(Object.class, classLoader);
+   }
+   
+   public void testPackageFilterNoJava() throws Exception
+   {
+      ClassLoaderSystem system = createClassLoaderSystem();
+      PackageClassFilter filter = PackageClassFilter.createPackageClassFilter("dummy");
+      ParentPolicy parentPolicy = new ParentPolicy(filter, ClassFilter.NOTHING);
+      ClassLoaderDomain domain = system.createAndRegisterDomain("test", parentPolicy, null);
+      MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
+      ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
+      assertLoadClassFail(Object.class, classLoader);
+   }
+   
+   public void testPackageFilterIncludeJava() throws Exception
+   {
+      ClassLoaderSystem system = createClassLoaderSystem();
+      PackageClassFilter filter = PackageClassFilter.createPackageClassFilter("dummy");
+      filter.setIncludeJava(true);
+      ParentPolicy parentPolicy = new ParentPolicy(filter, ClassFilter.NOTHING);
+      ClassLoaderDomain domain = system.createAndRegisterDomain("test", parentPolicy, null);
+      MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
+      ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
+      assertLoadClass(Object.class, classLoader, null, true);
+   }
 }

Added: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/JUnitTestSuite.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/JUnitTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/JUnitTestSuite.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -0,0 +1,61 @@
+/*
+ * 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.classloader.junit;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.classloader.junit.test.IsolatedClassLoaderUnitTestCase;
+
+/**
+ * JunitTestSuite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class JUnitTestSuite extends TestSuite
+{
+   /**
+    * For running the testsuite from the command line
+    * 
+    * @param args the command line args
+    */
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   /**
+    * Create the testsuite
+    * 
+    * @return the testsuite
+    */
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Junit Tests");
+
+      suite.addTest(IsolatedClassLoaderUnitTestCase.suite());
+      
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/notsupport/NotSupport.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/notsupport/NotSupport.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/notsupport/NotSupport.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloader.junit.notsupport;
+
+/**
+ * NotSupport.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NotSupport
+{
+
+}

Added: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/support/Support.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/support/Support.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/support/Support.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloader.junit.support;
+
+/**
+ * Support.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Support
+{
+}

Added: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/test/IsolatedClassLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/test/IsolatedClassLoaderUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/junit/test/IsolatedClassLoaderUnitTestCase.java	2007-07-24 16:59:37 UTC (rev 64255)
@@ -0,0 +1,137 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloader.junit.test;
+
+import java.util.Set;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.test.support.IsolatedClassLoaderTest;
+import org.jboss.test.classloader.junit.notsupport.NotSupport;
+import org.jboss.test.classloader.junit.support.Support;
+
+/**
+ * IsolatedClassLoaderUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class IsolatedClassLoaderUnitTestCase extends IsolatedClassLoaderTest
+{
+   private static final String NOT_SUPPORT_PACKAGE = "org.jboss.test.classloader.junit.notsupport";
+   private static final String NOT_SUPPORT_CLASS = NOT_SUPPORT_PACKAGE + ".NotSupport";
+   
+   public static Test suite()
+   {
+      return suite(IsolatedClassLoaderUnitTestCase.class, true, Support.class);
+   }
+
+   public IsolatedClassLoaderUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testClassLoader()
+   {
+      ClassLoader classLoader = getClass().getClassLoader();
+      assertFalse(classLoader.equals(IsolatedClassLoaderTest.class.getClassLoader()));
+   }
+   
+   public void testClassLoaderSystem()
+   {
+      ClassLoaderSystem system = getClassLoaderSystem();
+      assertTrue(system.isRegistered("TEST"));
+   }
+   
+   public void testSupport()
+   {
+      assertEquals(Support.class.getClassLoader(), getClass().getClassLoader());
+   }
+   
+   public void testNotSupport()
+   {
+      // This should fail since it is not suite() above
+      try
+      {
+         getLog().debug(NotSupport.class);
+         fail("Should not be here!");
+      }
+      catch (Throwable expected)
+      {
+         checkThrowable(NoClassDefFoundError.class, expected);
+      }
+   }
+   
+   public void testCreateClassLoader() throws Exception
+   {
+      ClassLoader classLoader = createClassLoader("NewClassLoader", NOT_SUPPORT_PACKAGE);
+      try
+      {
+         Class<?> clazz = classLoader.loadClass(NOT_SUPPORT_CLASS);
+         assertEquals(classLoader, clazz.getClassLoader());
+
+         Class<?> clazz2 = getClass().getClassLoader().loadClass(NOT_SUPPORT_CLASS);
+         assertEquals(classLoader, clazz2.getClassLoader());
+      }
+      finally
+      {
+         unregisterClassLoader(classLoader);
+      }
+   }
+   
+   public void testUnregisterClassLoader() throws Exception
+   {
+      ClassLoader classLoader = createClassLoader("NewClassLoader", NOT_SUPPORT_PACKAGE);
+      unregisterClassLoader(classLoader);
+      
+      try
+      {
+         classLoader.loadClass(NOT_SUPPORT_CLASS);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+      
+      try
+      {
+         getClass().getClassLoader().loadClass(NOT_SUPPORT_CLASS);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(ClassNotFoundException.class, t);
+      }
+   }
+   
+   public void testJavaClass() throws Exception
+   {
+      Class clazz = getClass().getClassLoader().loadClass("java.util.Set");
+      assertEquals(Set.class, clazz);
+      clazz = getClass().getClassLoader().loadClass("javax.naming.InitialContext");
+      assertEquals(InitialContext.class, clazz);
+   }
+}




More information about the jboss-cvs-commits mailing list