Author: oheger
Date: Fri Apr 8 17:57:17 2011
New Revision: 1090368
URL: http://svn.apache.org/viewvc?rev=1090368&view=rev
Log:
[CONFIGURATION-439] Added a unit test to verify that the problem is solved.
Updated changes.xml.
Modified:
commons/proper/configuration/trunk/src/changes/changes.xml
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1090368&r1=1090367&r2=1090368&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Fri Apr 8
17:57:17 2011
@@ -23,6 +23,13 @@
<body>
<release version="1.7" date="in SVN" description="">
+ <action dev="oheger" type="update" issue="CONFIGURATION-439">
+ Child configuration builders created for a <configuration>
element
+ in a configuration definition file now inherit the configuration and
+ error listeners from the original DefaultConfigurationBuilder. This
+ makes it possible to suppress log output created for optional
+ configurations.
+ </action>
<action dev="oheger" type="update" issue="CONFIGURATION-438"
due-to="Mike Noordermeer">
JNDIConfiguration.getKeys() no more logs an exception if the prefix
does
not exist.
Modified:
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java?rev=1090368&r1=1090367&r2=1090368&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
(original)
+++
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
Fri Apr 8 17:57:17 2011
@@ -19,6 +19,9 @@ package org.apache.commons.configuration
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -593,6 +596,41 @@ public class TestDefaultConfigurationBui
}
/**
+ * Tests whether the error log message caused by an optional configuration
+ * can be suppressed if a child builder is involved.
+ */
+ public void testLoadOptionalChildBuilderSuppressErrorLog()
+ throws ConfigurationException
+ {
+ factory.addProperty("override.configuration[@fileName]",
+ OPTIONAL_FILE.getAbsolutePath());
+ // a special invocation handler which checks that the warn() method of
+ // a logger is not called
+ InvocationHandler handler = new InvocationHandler()
+ {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable
+ {
+ String methodName = method.getName();
+ if (methodName.startsWith("is"))
+ {
+ return Boolean.TRUE;
+ }
+ if ("warn".equals(methodName))
+ {
+ fail("Unexpected log output!");
+ }
+ return null;
+ }
+ };
+ factory.setLogger((Log) Proxy.newProxyInstance(getClass()
+ .getClassLoader(), new Class[] {
+ Log.class
+ }, handler));
+ factory.getConfiguration(false);
+ }
+
+ /**
* Tests loading a definition file with multiple different sources.
*/
public void testLoadDifferentSources() throws ConfigurationException