Author: oheger
Date: Fri Mar 30 02:14:03 2007
New Revision: 524000
URL: http://svn.apache.org/viewvc?view=rev&rev=524000
Log:
Added a test case for CompositeConfiguration that checks interpolation together
with reloading
Modified:
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
Modified:
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java?view=diff&rev=524000&r1=523999&r2=524000
==============================================================================
---
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
(original)
+++
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
Fri Mar 30 02:14:03 2007
@@ -18,6 +18,9 @@
package org.apache.commons.configuration;
import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -26,6 +29,7 @@
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.reloading.FileAlwaysReloadingStrategy;
import junit.framework.TestCase;
@@ -457,6 +461,63 @@
assertEquals("Wrong list size", 2, lst.size());
assertEquals("Wrong first element", "test1", lst.get(0));
assertEquals("Wrong second element", "test2", lst.get(1));
+ }
+
+ /**
+ * Tests interpolation in combination with reloading.
+ */
+ public void testInterpolationWithReload() throws IOException,
+ ConfigurationException
+ {
+ File testFile = new File("target/testConfig.properties");
+ final String propFirst = "first.name";
+ final String propFull = "full.name";
+
+ try
+ {
+ writeTestConfig(testFile, propFirst, "John");
+ PropertiesConfiguration c1 = new PropertiesConfiguration(testFile);
+ c1.setReloadingStrategy(new FileAlwaysReloadingStrategy());
+ PropertiesConfiguration c2 = new PropertiesConfiguration();
+ c2.addProperty(propFull, "${" + propFirst + "} Doe");
+ CompositeConfiguration cc = new CompositeConfiguration();
+ cc.addConfiguration(c1);
+ cc.addConfiguration(c2);
+ assertEquals("Wrong name", "John Doe", cc.getString(propFull));
+
+ writeTestConfig(testFile, propFirst, "Jane");
+ assertEquals("First name not changed", "Jane", c1
+ .getString(propFirst));
+ assertEquals("First name not changed in composite", "Jane", cc
+ .getString(propFirst));
+ assertEquals("Full name not changed", "Jane Doe", cc
+ .getString(propFull));
+ }
+ finally
+ {
+ if (testFile.exists())
+ {
+ testFile.delete();
+ }
+ }
+ }
+
+ /**
+ * Writes a test properties file containing a single property definition.
+ *
+ * @param f the file to write
+ * @param prop the property name
+ * @param value the property value
+ * @throws IOException if an error occurs
+ */
+ private void writeTestConfig(File f, String prop, String value)
+ throws IOException
+ {
+ PrintWriter out = new PrintWriter(new FileWriter(f));
+ out.print(prop);
+ out.print("=");
+ out.println(value);
+ out.close();
}
public void testInstanciateWithCollection()
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]