1
0

Fix bug in test; custom MyFactory class wasn't specified in commons-logging.properties!

Also, use constants instead of repeating custom class name as literal.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@369755 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Kitching
2006-01-17 11:29:42 +00:00
parent 7ff4b00fef
commit 69cc4ff86d
2 changed files with 19 additions and 11 deletions

View File

@@ -33,6 +33,12 @@ import org.apache.commons.logging.PathableTestSuite;
public class TcclDisabledTestCase extends TestCase { public class TcclDisabledTestCase extends TestCase {
public static final String MY_LOG_FACTORY_PKG =
"org.apache.commons.logging.tccl.custom";
public static final String MY_LOG_FACTORY_IMPL =
MY_LOG_FACTORY_PKG + ".MyLogFactoryImpl";
// ------------------------------------------- JUnit Infrastructure Methods // ------------------------------------------- JUnit Infrastructure Methods
@@ -70,7 +76,7 @@ public class TcclDisabledTestCase extends TestCase {
// hack to ensure that the testcase classloader can't see // hack to ensure that the testcase classloader can't see
// the cust MyLogFactoryImpl // the cust MyLogFactoryImpl
parentLoader.useExplicitLoader( parentLoader.useExplicitLoader(
"org.apache.commons.logging.tccl.custom.", emptyLoader); MY_LOG_FACTORY_PKG + ".", emptyLoader);
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/"); URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
parentLoader.addURL(propsEnableUrl); parentLoader.addURL(propsEnableUrl);
@@ -111,8 +117,7 @@ public class TcclDisabledTestCase extends TestCase {
// MyLogFactoryImpl should not be loadable via parent loader // MyLogFactoryImpl should not be loadable via parent loader
try { try {
Class clazz = thisClassLoader.loadClass( Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader"); fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
} catch(ClassNotFoundException ex) { } catch(ClassNotFoundException ex) {
// ok, expected // ok, expected
@@ -120,8 +125,7 @@ public class TcclDisabledTestCase extends TestCase {
// MyLogFactoryImpl should be loadable via tccl loader // MyLogFactoryImpl should be loadable via tccl loader
try { try {
Class clazz = tcclLoader.loadClass( Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
} catch(ClassNotFoundException ex) { } catch(ClassNotFoundException ex) {
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader"); fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
} }
@@ -134,11 +138,14 @@ public class TcclDisabledTestCase extends TestCase {
* we should see the default LogFactoryImpl rather than the custom one. * we should see the default LogFactoryImpl rather than the custom one.
*/ */
public void testTcclLoading() throws Exception { public void testTcclLoading() throws Exception {
try {
LogFactory instance = LogFactory.getFactory(); LogFactory instance = LogFactory.getFactory();
fail("Unexpectedly succeeded in loading custom factory, though TCCL disabled.");
assertEquals( } catch(org.apache.commons.logging.LogConfigurationException ex) {
"Correct LogFactory loaded", // ok, custom MyLogFactoryImpl as specified in props_disable_tccl
"org.apache.commons.logging.impl.LogFactoryImpl", // could not be found.
instance.getClass().getName()); int index = ex.getMessage().indexOf(MY_LOG_FACTORY_IMPL);
assertTrue("MylogFactoryImpl not found", index >= 0);
}
} }
} }

View File

@@ -1 +1,2 @@
use_tccl=false use_tccl=false
org.apache.commons.logging.LogFactory=org.apache.commons.logging.tccl.custom.MyLogFactoryImpl