[Jboss-cvs] JBossAS SVN: r56507 - in projects/test/trunk/test: . src src/main/org/jboss/test src/main/org/jboss/test/classloader src/resources src/resources/tests src/resources/tests/org src/resources/tests/org/jboss src/resources/tests/org/jboss/test src/resources/tests/org/jboss/test/classloader src/resources/tests/org/jboss/test/classloader/support src/resources/tests/org/jboss/test/classloader/support/filtered src/resources/tests/org/jboss/test/classloader/support/filtered2 src/resources/tests/org/jboss/test/classloader/support/unfiltered src/tests src/tests/org src/tests/org/jboss src/tests/org/jboss/test src/tests/org/jboss/test/classloader src/tests/org/jboss/test/classloader/support src/tests/org/jboss/test/classloader/support/filtered src/tests/org/jboss/test/classloader/support/filtered2 src/tests/org/jboss/test/classloader/support/unfiltered src/tests/org/jboss/test/classloader/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 1 11:16:17 EDT 2006


Author: adrian at jboss.org
Date: 2006-09-01 11:16:08 -0400 (Fri, 01 Sep 2006)
New Revision: 56507

Added:
   projects/test/trunk/test/build-test.xml
   projects/test/trunk/test/src/main/org/jboss/test/classloader/
   projects/test/trunk/test/src/main/org/jboss/test/classloader/FilteringClassLoader.java
   projects/test/trunk/test/src/resources/
   projects/test/trunk/test/src/resources/tests/
   projects/test/trunk/test/src/resources/tests/org/
   projects/test/trunk/test/src/resources/tests/org/jboss/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered/filtered
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered2/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered2/filtered2
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/unfiltered/
   projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/unfiltered/unfiltered
   projects/test/trunk/test/src/tests/
   projects/test/trunk/test/src/tests/org/
   projects/test/trunk/test/src/tests/org/jboss/
   projects/test/trunk/test/src/tests/org/jboss/test/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered/Filtered.java
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered2/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered2/Filtered2.java
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/unfiltered/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/unfiltered/Unfiltered.java
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/test/
   projects/test/trunk/test/src/tests/org/jboss/test/classloader/test/FilteringClassLoaderUnitTestCase.java
Modified:
   projects/test/trunk/test/.classpath
   projects/test/trunk/test/build.xml
Log:
Add a filtering classloader to jboss-test.
Also started a testsuite for jboss-test. :-)

Modified: projects/test/trunk/test/.classpath
===================================================================
--- projects/test/trunk/test/.classpath	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/.classpath	2006-09-01 15:16:08 UTC (rev 56507)
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src/main"/>
+	<classpathentry kind="src" path="src/tests"/>
+	<classpathentry kind="lib" path="src/resources/tests"/>
 	<classpathentry kind="src" path="examples/src/main"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>

Added: projects/test/trunk/test/build-test.xml
===================================================================
--- projects/test/trunk/test/build-test.xml	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/build-test.xml	2006-09-01 15:16:08 UTC (rev 56507)
@@ -0,0 +1,229 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+   <!ENTITY buildmagic SYSTEM "../tools/etc/buildmagic/buildmagic.ent">
+   <!ENTITY libraries  SYSTEM "../thirdparty/libraries.ent">
+   <!ENTITY targets SYSTEM "../tools/etc/buildmagic/targets.ent">
+]>
+
+<!-- ====================================================================== -->
+<!--                                                                        -->
+<!--  JBoss, the OpenSource J2EE webOS                                      -->
+<!--                                                                        -->
+<!--  Distributable under LGPL license.                                     -->
+<!--  See terms of license at http://www.gnu.org.                           -->
+<!--                                                                        -->
+<!-- ====================================================================== -->
+
+<!-- $Id: build-test.xml 56480 2006-08-31 15:15:32 +0000 (Thu, 31 Aug 2006) adrian at jboss.org $ -->
+
+<project default="main" name="JBoss/Test Tests">
+
+  <!-- ================================================================== -->
+  <!-- Setup                                                              -->
+  <!-- ================================================================== -->
+
+  <!--
+     | Include the common Buildmagic elements.
+     |
+     | This defines several different targets, properties and paths.
+     | It also sets up the basic extention tasks amoung other things.
+   -->
+
+  &buildmagic;
+
+  <!--
+     | Include the normal targets.
+   -->
+  &targets;
+
+  <!-- ================================================================== -->
+  <!-- Configuration                                                      -->
+  <!-- ================================================================== -->
+
+  <!--
+     | Configure the build system.
+     |
+     | This target is invoked by the Buildmagic initialization logic and
+     | should contain module specific configuration elements.
+   -->
+
+  <target name="configure" unless="configure.disable">
+
+    <!-- =================== -->
+    <!-- Basic Configuration -->
+    <!-- =================== -->
+
+    <!-- Module name(s) & version -->
+    <property name="module.name" value="test"/>
+    <property name="module.Name" value="JBoss Test"/>
+    <property name="module.version" value="DEV"/>
+    <property name="jar.prefix" value="jboss-test-test"/>
+
+    <!-- ========= -->
+    <!-- Libraries -->
+    <!-- ========= -->
+
+    &libraries;
+
+    <!-- The combined library classpath -->
+    <path id="library.classpath">
+       <path refid="apache.log4j.classpath"/>
+       <path refid="junit.junit.classpath"/>
+       <path refid="apache.ant.classpath"/>
+       <path refid="apache.ant.optional.classpath"/>
+    </path>
+      
+    <path id="apache.ant.optional.classpath">
+       <pathelement path="${project.tools}/lib/ant-junit.jar"/>
+    </path>
+
+<!-- this -->
+<property name="jboss.this.root" value="${module.root}/output"/>
+<property name="jboss.this.lib" value="${jboss.this.root}/lib"/>
+<path id="jboss.this.classpath">
+   <fileset dir="${jboss.this.lib}">
+      <include name="*.jar"/>
+      <exclude name="${jar.prefix}.jar"/>
+   </fileset>
+</path>
+
+    <!-- The combined dependant module classpath -->
+    <path id="dependentmodule.classpath">
+       <path refid="jboss.this.classpath"/>
+       <path refid="jboss.common.classpath"/>
+       <path refid="jboss.profiler.jvmti.classpath"/>
+    </path>
+
+    <!-- ===== -->
+    <!-- Tasks -->
+    <!-- ===== -->
+
+   <property name="source.java" value="${module.source}/tests"/>
+   <property name="javac.target" value="1.5"/>
+   <property name="javac.source" value="1.5"/>
+   <property name="build.classes" value="${module.output}/classes-tests"/>
+   <property name="build.testlog" value="${module.output}/log"/>
+   <property name="build-bypass.disabled" value="true"/>
+
+   <call target="_default:task-init"/>
+  	
+    <path id="thirdparty.classpath">
+       <path refid="library.classpath"/>
+       <path refid="dependentmodule.classpath"/>
+    </path>
+    
+    <path id="no.javassist.classpath">
+       <path refid="dependentmodule.classpath"/>
+      <path refid="junit.junit.classpath"/>
+      <path refid="apache.log4j.classpath"/>
+      <path refid="oswego.concurrent.classpath"/>
+      <path refid="jboss.profiler.jvmti.classpath"/>
+      <path refid="jboss.test.classpath"/>
+      <path refid="jboss.common.classpath"/>
+    </path>
+
+  </target>
+
+  <!-- ================================================================== -->
+  <!-- Compile                                                            -->
+  <!-- ================================================================== -->
+
+  <!--
+     | Compile everything.
+     |
+     | This target should depend on other compile-* targets for each
+     | different type of compile that needs to be performed, short of
+     | documentation compiles.
+   -->
+
+  <target name="compile"
+	  description="Compile all source files."
+	  depends="_default:compile-classes"
+  />
+   
+  <!-- ================================================================== -->
+  <!-- Archives                                                           -->
+  <!-- ================================================================== -->
+
+  <!-- 
+     |  Build all jar files.
+    -->
+  <target name="module-jars" depends="init">
+    
+    <jar jarfile="${build.lib}/${jar.prefix}.jar" manifest="${build.etc}/default.mf">
+      <fileset dir="${build.classes}"/>
+    </jar>
+  </target>
+
+  <!-- ================================================================== -->
+  <!-- Tests                                                              -->
+  <!-- ================================================================== -->
+
+   <target name="tests" depends="most"
+      description="Execute all tests in the given test directory.">
+      <mkdir dir="${build.reports}"/>
+      <mkdir dir="${build.testlog}"/>
+      <!-- Remove the test.log so each run has a fresh log -->
+      <delete file="${build.testlog}/test.log"/>
+      <junit dir="${module.output}"
+         printsummary="yes"
+         haltonerror="false"
+         haltonfailure="false"
+         fork="true">
+
+         <sysproperty key="build.testlog" value="${build.testlog}"/>
+
+         <classpath>
+            <pathelement location="${build.classes}"/>
+            <pathelement location="${build.resources}/tests"/>
+            <path refid="javac.classpath"/>
+            <path refid="apache.xerces.classpath"/>
+         </classpath>
+
+         <formatter type="plain" usefile="true"/>
+         <formatter type="xml" usefile="true"/>
+
+         <batchtest todir="${build.reports}"
+            haltonerror="false"
+            haltonfailure="false"
+            fork="true">
+
+            <fileset dir="${build.classes}">
+               <include name="org/jboss/test/**/*TestCase.class"/>
+            </fileset>
+         </batchtest>
+      </junit>
+   </target>
+
+   <target name="one-test" depends="init"
+      description="Execute all tests in the given test directory.">
+      <mkdir dir="${build.reports}"/>
+      <mkdir dir="${build.testlog}"/>
+      <!-- Remove the test.log so each run has a fresh log -->
+      <delete file="${build.testlog}/test.log"/>
+      <junit dir="${module.output}"
+         printsummary="yes"
+         haltonerror="false"
+         haltonfailure="false"
+         fork="true">
+
+         <sysproperty key="build.testlog" value="${build.testlog}"/>
+
+         <classpath>
+            <pathelement location="${build.classes}"/>
+            <pathelement location="${build.resources}/tests"/>
+            <path refid="javac.classpath"/>
+            <path refid="apache.xerces.classpath"/>
+         </classpath>
+
+         <formatter type="plain" usefile="true"/>
+         <formatter type="xml" usefile="true"/>
+
+         <test todir="${build.reports}" name="${test}"
+               haltonerror="${junit.batchtest.haltonerror}"
+               haltonfailure="${junit.batchtest.haltonfailure}"
+               fork="${junit.batchtest.fork}"/>
+      </junit>
+   </target>
+
+</project>

Modified: projects/test/trunk/test/build.xml
===================================================================
--- projects/test/trunk/test/build.xml	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/build.xml	2006-09-01 15:16:08 UTC (rev 56507)
@@ -69,7 +69,7 @@
          <path refid="apache.log4j.classpath"/>
          <path refid="junit.junit.classpath"/>
          <path refid="apache.ant.classpath"/>
-      	 <path refid="apache.ant.optional.classpath"/>
+         <path refid="apache.ant.optional.classpath"/>
       </path>
       
       <path id="apache.ant.optional.classpath">
@@ -124,8 +124,9 @@
    <target name="compile"
            description="Compile all source files."
            depends="_default:compile-classes, 
-                   _default:compile-etc,
-                   retro"
+                    _default:compile-resources,
+                    _default:compile-etc,
+                    retro"
    />
    
   <target name="retro">

Added: projects/test/trunk/test/src/main/org/jboss/test/classloader/FilteringClassLoader.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/classloader/FilteringClassLoader.java	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/main/org/jboss/test/classloader/FilteringClassLoader.java	2006-09-01 15:16:08 UTC (rev 56507)
@@ -0,0 +1,130 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.jboss.util.collection.Iterators;
+
+/**
+ * FilteringClassLoader.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FilteringClassLoader extends ClassLoader
+{
+   /** The packages to filter out, e.g. org.jboss.test.something */
+   private String[] packages;
+   
+   /** The paths to filter out, e.g. org/jboss/test/something */
+   private String[] paths;
+   
+   /** The urls to filter out, e.g. file:/home/whatever/project/output/classes/org/jboss/test/something */
+   private String[] urls;
+   
+   /**
+    * Create a new FilteringClassLoader.
+    * 
+    * @param parent the parent classloader
+    * @param packages the packages to filter out
+    */
+   public FilteringClassLoader(ClassLoader parent, String[] packages)
+   {
+      super(parent);
+      if (packages == null)
+         throw new IllegalArgumentException("Null packages");
+      this.packages = packages;
+      
+      // Determine the filtered paths
+      paths = new String[packages.length];
+      for (int i = 0; i < packages.length; ++i)
+         paths[i] = packages[i].replace('.', '/');
+      
+      // Determine the filtered roots
+      try
+      {
+         Enumeration<URL> enumeration = super.getResources("");
+         List<URL> rootURLs = new ArrayList<URL>();
+         while (enumeration.hasMoreElements())
+            rootURLs.add(enumeration.nextElement());
+         urls = new String[paths.length * rootURLs.size()];
+         int i = 0; 
+         for (String path : paths)
+         {
+            for (URL rootURL : rootURLs)
+               urls[i++] = new URL(rootURL, path).toString();
+         }
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error determining classloader urls", e);
+      }
+   }
+
+   @Override
+   protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
+   {
+      for (String pkg : packages)
+      {
+         if (name.startsWith(pkg))
+            throw new ClassNotFoundException("Class not found (filtered): " + name);
+      }
+      return super.loadClass(name, resolve);
+   }
+
+   @Override
+   public URL getResource(String name)
+   {
+      for (String path : paths)
+      {
+         if (name.startsWith(path))
+            return null;
+      }
+      return super.getResource(name);
+   }
+
+   @SuppressWarnings("unchecked")
+   @Override
+   public Enumeration<URL> getResources(String name) throws IOException
+   {
+      Enumeration<URL> unfiltered = super.getResources(name);
+      List<URL> filtered = new ArrayList<URL>();
+      while (unfiltered.hasMoreElements())
+      {
+         URL next = unfiltered.nextElement();
+         boolean ignore =false;
+         for (String url : urls)
+         {
+            if (next.toString().startsWith(url))
+               ignore = true;
+         }
+         if (ignore == false)
+            filtered.add(next);
+      }
+      return Iterators.toEnumeration(filtered.iterator());
+   }
+}

Added: projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered/filtered
===================================================================
--- projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered/filtered	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered/filtered	2006-09-01 15:16:08 UTC (rev 56507)
@@ -0,0 +1 @@
+empty
\ No newline at end of file

Added: projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered2/filtered2
===================================================================
--- projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered2/filtered2	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/filtered2/filtered2	2006-09-01 15:16:08 UTC (rev 56507)
@@ -0,0 +1 @@
+empty
\ No newline at end of file

Added: projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/unfiltered/unfiltered
===================================================================
--- projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/unfiltered/unfiltered	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/resources/tests/org/jboss/test/classloader/support/unfiltered/unfiltered	2006-09-01 15:16:08 UTC (rev 56507)
@@ -0,0 +1 @@
+empty
\ No newline at end of file

Added: projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered/Filtered.java
===================================================================
--- projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered/Filtered.java	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered/Filtered.java	2006-09-01 15:16:08 UTC (rev 56507)
@@ -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.support.filtered;
+
+/**
+ * Filtered.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Filtered
+{
+}

Added: projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered2/Filtered2.java
===================================================================
--- projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered2/Filtered2.java	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/filtered2/Filtered2.java	2006-09-01 15:16:08 UTC (rev 56507)
@@ -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.support.filtered2;
+
+/**
+ * Filtered.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Filtered2
+{
+}

Added: projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/unfiltered/Unfiltered.java
===================================================================
--- projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/unfiltered/Unfiltered.java	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/tests/org/jboss/test/classloader/support/unfiltered/Unfiltered.java	2006-09-01 15:16:08 UTC (rev 56507)
@@ -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.support.unfiltered;
+
+/**
+ * Unfiltered.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Unfiltered
+{
+}

Added: projects/test/trunk/test/src/tests/org/jboss/test/classloader/test/FilteringClassLoaderUnitTestCase.java
===================================================================
--- projects/test/trunk/test/src/tests/org/jboss/test/classloader/test/FilteringClassLoaderUnitTestCase.java	2006-09-01 13:35:31 UTC (rev 56506)
+++ projects/test/trunk/test/src/tests/org/jboss/test/classloader/test/FilteringClassLoaderUnitTestCase.java	2006-09-01 15:16:08 UTC (rev 56507)
@@ -0,0 +1,169 @@
+/*
+* 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.test;
+
+import org.jboss.test.BaseTestCase;
+import org.jboss.test.classloader.FilteringClassLoader;
+import org.jboss.test.classloader.support.filtered.Filtered;
+import org.jboss.test.classloader.support.filtered2.Filtered2;
+import org.jboss.test.classloader.support.unfiltered.Unfiltered;
+
+/**
+ * FilteringClassLoaderUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FilteringClassLoaderUnitTestCase extends BaseTestCase
+{
+   Class filtered = Filtered.class;
+   String filteredClassName = filtered.getName();
+   String filteredPackage = filtered.getPackage().getName();
+   String filteredPath = filteredPackage.replace('.', '/');
+   Class filtered2 = Filtered2.class;
+   String filtered2ClassName = filtered2.getName();
+   String filtered2Package = filtered2.getPackage().getName();
+   String filtered2Path = filtered2Package.replace('.', '/');
+
+   Class unfiltered = Unfiltered.class;
+   String unfilteredClassName = unfiltered.getName();
+   String unfilteredPackage = unfiltered.getPackage().getName();
+   String unfilteredPath = unfilteredPackage.replace('.', '/');
+   
+   public FilteringClassLoaderUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testFilteredClass() throws Exception
+   {
+      ClassLoader cl = getClass().getClassLoader();
+      assertNotNull(cl.loadClass(filteredClassName));
+      assertNotNull(cl.loadClass(unfilteredClassName));
+      
+      String[] packages = { filteredPackage };
+      cl = createFilteringClassLoader(cl, packages);
+      try
+      {
+         cl.loadClass(filteredClassName);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(ClassNotFoundException.class, t);
+      }
+      
+      assertNotNull(cl.loadClass(unfilteredClassName));
+   }
+   
+   public void testFilteredResource() throws Exception
+   {
+      ClassLoader cl = getClass().getClassLoader();
+      assertNotNull(cl.getResource(filteredPath + "/filtered"));
+      assertNotNull(cl.getResource(unfilteredPath + "/unfiltered"));
+      
+      String[] packages = { filteredPackage };
+      cl = createFilteringClassLoader(cl, packages);
+      assertNull(cl.getResource(filteredPath + "/" + "filtered"));
+      
+      assertNotNull(cl.getResource(unfilteredPath + "/unfiltered"));
+   }
+   
+   public void testFilteredResources() throws Exception
+   {
+      ClassLoader cl = getClass().getClassLoader();
+      assertTrue(cl.getResources(filteredPath + "/filtered").hasMoreElements());
+      assertTrue(cl.getResources(unfilteredPath + "/unfiltered").hasMoreElements());
+      
+      String[] packages = { filteredPackage };
+      cl = createFilteringClassLoader(cl, packages);
+      assertFalse(cl.getResources(filteredPath + "/" + "filtered").hasMoreElements());
+      
+      assertTrue(cl.getResources(unfilteredPath + "/unfiltered").hasMoreElements());
+   }
+   
+   public void testFilteredClass2() throws Exception
+   {
+      ClassLoader cl = getClass().getClassLoader();
+      assertNotNull(cl.loadClass(filteredClassName));
+      assertNotNull(cl.loadClass(filtered2ClassName));
+      assertNotNull(cl.loadClass(unfilteredClassName));
+      
+      String[] packages = { filteredPackage, filtered2Package };
+      cl = createFilteringClassLoader(cl, packages);
+      try
+      {
+         cl.loadClass(filteredClassName);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(ClassNotFoundException.class, t);
+      }
+      try
+      {
+         cl.loadClass(filtered2ClassName);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(ClassNotFoundException.class, t);
+      }
+      
+      assertNotNull(cl.loadClass(unfilteredClassName));
+   }
+   
+   public void testFilteredResource2() throws Exception
+   {
+      ClassLoader cl = getClass().getClassLoader();
+      assertNotNull(cl.getResource(filteredPath + "/filtered"));
+      assertNotNull(cl.getResource(filtered2Path + "/filtered2"));
+      assertNotNull(cl.getResource(unfilteredPath + "/unfiltered"));
+      
+      String[] packages = { filteredPackage, filtered2Package };
+      cl = createFilteringClassLoader(cl, packages);
+      assertNull(cl.getResource(filteredPath + "/" + "filtered"));
+      assertNull(cl.getResource(filtered2Path + "/" + "filtered2"));
+      
+      assertNotNull(cl.getResource(unfilteredPath + "/unfiltered"));
+   }
+   
+   public void testFilteredResources2() throws Exception
+   {
+      ClassLoader cl = getClass().getClassLoader();
+      assertTrue(cl.getResources(filteredPath + "/filtered").hasMoreElements());
+      assertTrue(cl.getResources(filtered2Path + "/filtered2").hasMoreElements());
+      assertTrue(cl.getResources(unfilteredPath + "/unfiltered").hasMoreElements());
+      
+      String[] packages = { filteredPackage, filtered2Package };
+      cl = createFilteringClassLoader(cl, packages);
+      assertFalse(cl.getResources(filteredPath + "/" + "filtered").hasMoreElements());
+      assertFalse(cl.getResources(filtered2Path + "/" + "filtered2").hasMoreElements());
+      
+      assertTrue(cl.getResources(unfilteredPath + "/unfiltered").hasMoreElements());
+   }
+   
+   protected ClassLoader createFilteringClassLoader(ClassLoader cl, String[] packages)
+   {
+      return new FilteringClassLoader(cl, packages);
+   }
+}




More information about the jboss-cvs-commits mailing list