1 16 17 package org.apache.commons.logging.config; 18 19 20 import java.net.URL ; 21 22 import junit.framework.Test; 23 import junit.framework.TestCase; 24 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.commons.logging.PathableClassLoader; 27 import org.apache.commons.logging.PathableTestSuite; 28 29 30 41 public class FirstPriorityConfigTestCase extends TestCase { 42 43 45 46 49 public static Test suite() throws Exception { 50 Class thisClass = FirstPriorityConfigTestCase.class; 51 52 PathableClassLoader dummy = new PathableClassLoader(null); 57 dummy.useSystemLoader("junit."); 58 dummy.addLogicalLib("testclasses"); 59 dummy.addLogicalLib("commons-logging"); 60 61 String thisClassPath = thisClass.getName().replace('.', '/') + ".class"; 62 URL baseUrl = dummy.findResource(thisClassPath); 63 64 PathableClassLoader containerLoader = new PathableClassLoader(null); 72 containerLoader.useSystemLoader("junit."); 73 containerLoader.addLogicalLib("commons-logging"); 74 75 PathableClassLoader webappLoader = new PathableClassLoader(containerLoader); 76 webappLoader.addLogicalLib("testclasses"); 77 78 URL pri20URL = new URL (baseUrl, "priority20/"); 79 webappLoader.addURL(pri20URL); 80 81 URL pri10URL = new URL (baseUrl, "priority10/"); 82 webappLoader.addURL(pri10URL); 83 84 Class testClass = webappLoader.loadClass(thisClass.getName()); 87 return new PathableTestSuite(testClass, webappLoader); 88 } 89 90 93 public void setUp() throws Exception { 94 LogFactory.releaseAll(); 95 } 96 97 100 public void tearDown() { 101 LogFactory.releaseAll(); 102 } 103 104 106 110 public void testPriority() throws Exception { 111 LogFactory instance = LogFactory.getFactory(); 112 String id = (String ) instance.getAttribute("configId"); 113 assertEquals("Correct config file loaded", "priority20", id ); 114 } 115 } 116 | Popular Tags |