Author: rmannibucau
Date: Mon Aug 13 17:06:27 2012
New Revision: 1372513

URL: http://svn.apache.org/viewvc?rev=1372513&view=rev
Log:
TempClassLoaderTest fix

Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/TempClassLoaderTest.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java?rev=1372513&r1=1372512&r2=1372513&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
 Mon Aug 13 17:06:27 2012
@@ -20,6 +20,7 @@ import org.apache.openejb.loader.SystemI
 
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 
@@ -32,15 +33,25 @@ public class URLClassLoaderFirst extends
     private static final boolean SKIP_COMMONS_NET = 
skipLib("org.apache.commons.net.pop3.POP3Client");
 
     // - will not match anything, that's the desired default behavior
-    private static final Collection<String> FORCED_SKIP = 
list("openejb.classloader.forced-skip");
-    private static final Collection<String> FORCED_LOAD = 
list("openejb.classloader.forced-load");
+    private static final Collection<String> FORCED_SKIP = new 
ArrayList<String>();
+    private static final Collection<String> FORCED_LOAD = new 
ArrayList<String>();
+
+    static {
+        reloadConfig();
+    }
+
+    public static void reloadConfig() {
+        list(FORCED_SKIP, "openejb.classloader.forced-skip");
+        list(FORCED_LOAD, "openejb.classloader.forced-load");
+    }
+
+    private static void list(final Collection<String> list, final String key) {
+        list.clear();
 
-    private static Collection<String> list(final String key) {
         final String s = SystemInstance.get().getOptions().get(key, (String) 
null);
-        if (s == null || s.trim().isEmpty()) {
-            return null; // no need to iterate over something empty
+        if (s != null && !s.trim().isEmpty()) {
+            list.addAll(Arrays.asList(s.trim().split(",")));
         }
-        return Arrays.asList(s.trim().split(","));
     }
 
     private static boolean skipLib(final String includedClass) {
@@ -101,10 +112,13 @@ public class URLClassLoaderFirst extends
         if (!ok) {
             clazz = loadInternal(name, resolve);
             if (clazz != null) {
+                if (ok) {
+                    System.out.println(">>> " + name);
+                }
                 return clazz;
             }
         }
-
+        System.out.println("CNF>>> " + name);
         throw new ClassNotFoundException(name);
     }
 

Modified: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/TempClassLoaderTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/TempClassLoaderTest.java?rev=1372513&r1=1372512&r2=1372513&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/TempClassLoaderTest.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/TempClassLoaderTest.java
 Mon Aug 13 17:06:27 2012
@@ -17,10 +17,29 @@
  */
 package org.apache.openejb.core;
 
-import junit.framework.TestCase;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.classloader.URLClassLoaderFirst;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+
+public class TempClassLoaderTest {
+    @BeforeClass
+    public static void init() {
+        SystemInstance.get().setProperty("openejb.classloader.forced-load", 
"org.apache.openejb.core");
+        URLClassLoaderFirst.reloadConfig();
+    }
+
+    @AfterClass
+    public static void reset() {
+        
SystemInstance.get().getProperties().remove("openejb.classloader.forced-load");
+        URLClassLoaderFirst.reloadConfig();
+    }
 
-public class TempClassLoaderTest extends TestCase {
+    @Test
     public void test() throws Exception {
         ClassLoader tempCL = new TempClassLoader(getClass().getClassLoader());
         Class<?> clazz;
@@ -42,7 +61,8 @@ public class TempClassLoaderTest extends
         assertSame(tempCL, clazz.getClassLoader());
     }
 
-    public void _testHackEnabled() throws Exception {
+    @Test
+    public void testHackEnabled() throws Exception {
         TempClassLoader tempCL = new 
TempClassLoader(getClass().getClassLoader());
         tempCL.skip(TempClassLoader.Skip.ANNOTATIONS);
         


Reply via email to