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 47 48 public class PriorityConfigTestCase extends TestCase { 49 50 52 53 56 public static Test suite() throws Exception { 57 Class thisClass = PriorityConfigTestCase.class; 58 59 PathableClassLoader dummy = new PathableClassLoader(null); 64 dummy.useSystemLoader("junit."); 65 dummy.addLogicalLib("testclasses"); 66 dummy.addLogicalLib("commons-logging"); 67 68 String thisClassPath = thisClass.getName().replace('.', '/') + ".class"; 69 URL baseUrl = dummy.findResource(thisClassPath); 70 71 PathableClassLoader containerLoader = new PathableClassLoader(null); 79 containerLoader.useSystemLoader("junit."); 80 containerLoader.addLogicalLib("commons-logging"); 81 82 URL pri10URL = new URL (baseUrl, "priority10/"); 83 containerLoader.addURL(pri10URL); 84 85 PathableClassLoader webappLoader = new PathableClassLoader(containerLoader); 86 webappLoader.setParentFirst(true); 87 webappLoader.addLogicalLib("testclasses"); 88 89 URL noPriorityURL = new URL (baseUrl, "nopriority/"); 90 webappLoader.addURL(noPriorityURL); 91 92 URL pri20URL = new URL (baseUrl, "priority20/"); 93 webappLoader.addURL(pri20URL); 94 95 URL pri20aURL = new URL (baseUrl, "priority20a/"); 96 webappLoader.addURL(pri20aURL); 97 98 Class testClass = webappLoader.loadClass(thisClass.getName()); 101 return new PathableTestSuite(testClass, webappLoader); 102 } 103 104 107 public void setUp() throws Exception { 108 LogFactory.releaseAll(); 109 } 110 111 114 public void tearDown() { 115 LogFactory.releaseAll(); 116 } 117 118 120 124 public void testPriority() throws Exception { 125 LogFactory instance = LogFactory.getFactory(); 126 String id = (String ) instance.getAttribute("configId"); 127 assertEquals("Correct config file loaded", "priority20", id ); 128 } 129 } 130 | Popular Tags |