You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by EP...@upstate.com on 2003/07/07 21:03:27 UTC
RE: cvs commit: jakarta-turbine-2/src/test/org/apache/turbine Con
figurationTest.java
Henning,
I missed your post about the move of the testcases to commons-configuration.
I agree the testcases are more appropriate there. I would like to leave the
testcases in turbine for a day or to to make sure that everything does run
properly, and then delete them. I should've seen your CVS commit message,
but I am using a crummy web interface, and missed it.
Eric
-----Original Message-----
From: epugh@apache.org
To: jakarta-turbine-2-cvs@apache.org
Sent: 7/7/03 2:59 PM
Subject: cvs commit: jakarta-turbine-2/src/test/org/apache/turbine
ConfigurationTest.java
epugh 2003/07/07 11:59:30
Modified: src/test/org/apache/turbine ConfigurationTest.java
Log:
Added some more logging to try and track down the bug that others seem
to report.
If you can't compile, please send epugh@upstate.com the stack trace.
If it isn't solvable,
I'll remove the test later this week.
Revision Changes Path
1.7 +185 -75
jakarta-turbine-2/src/test/org/apache/turbine/ConfigurationTest.java
Index: ConfigurationTest.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/test/org/apache/turbine/ConfigurationTes
t.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConfigurationTest.java 6 Jul 2003 11:33:35 -0000 1.6
+++ ConfigurationTest.java 7 Jul 2003 18:59:29 -0000 1.7
@@ -66,7 +66,8 @@
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.configuration.BaseConfiguration;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Tests that the ConfigurationFactory and regular old properties
methods both work.
* Verify the overriding of properties.
@@ -76,80 +77,189 @@
*/
public class ConfigurationTest extends BaseTestCase
{
- public static final String SERVICE_PREFIX = "services.";
+ private static Log log =
LogFactory.getLog(ConfigurationTest.class);
+ public static final String SERVICE_PREFIX = "services.";
- /**
- * A <code>Service</code> property determining its implementing
- * class name .
- */
- public static final String CLASSNAME_SUFFIX = ".classname";
-
- private static TurbineConfig tc = null;
- private static TurbineXmlConfig txc = null;
-
- public ConfigurationTest(String name) throws Exception
- {
- super(name);
- }
-
- public static Test suite()
- {
- return new TestSuite(ConfigurationTest.class);
- }
-
- public void testCreateTurbineWithConfigurationXML() throws
Exception
- {
- txc = new TurbineXmlConfig(".",
"/conf/test/TurbineConfiguration.xml");
-
- try
- {
- txc.initialize();
-
- Configuration configuration = Turbine.getConfiguration();
- assertNotNull("No Configuration Object found!",
configuration);
- assertFalse("Make sure we have values",
configuration.isEmpty());
-
- // overridden value
- String key = "module.cache";
- assertEquals("Read a config value " + key + ", received:"
+ configuration.getString(key), "true", configuration.getString(key));
-
- // non overridden value
- key = "scheduledjob.cache.size";
- assertEquals("Read a config value " + key + ", received:"
+ configuration.getString(key), "10", configuration.getString(key));
- }
- catch (Exception e)
- {
- throw e;
- }
- finally
- {
- txc.dispose();
- }
- }
-
- public void testCreateTurbineWithConfiguration() throws Exception
- {
- tc = new TurbineConfig(".",
"/conf/test/TemplateService.properties");
-
- try
- {
- tc.initialize();
-
- Configuration configuration = Turbine.getConfiguration();
- assertNotNull("No Configuration Object found!",
configuration);
- assertFalse("Make sure we have values",
configuration.isEmpty());
-
- String key = "scheduledjob.cache.size";
- assertEquals("Read a config value " + key + ", received:"
+ configuration.getString(key), "10", configuration.getString(key));
- }
- catch (Exception e)
- {
- throw e;
- }
- finally
- {
- tc.dispose();
- }
- }
+ /**
+ * A <code>Service</code> property determining its implementing
+ * class name .
+ */
+ public static final String CLASSNAME_SUFFIX = ".classname";
+
+ private static TurbineConfig tc = null;
+ private static TurbineXmlConfig txc = null;
+
+ public ConfigurationTest(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(ConfigurationTest.class);
+ }
+
+ public void testCreateTurbineWithConfigurationXML() throws
Exception
+ {
+ txc = new TurbineXmlConfig(".",
"/conf/test/TurbineConfiguration.xml");
+
+ try
+ {
+ txc.initialize();
+
+ Configuration configuration =
Turbine.getConfiguration();
+ assertNotNull("No Configuration Object found!",
configuration);
+ assertFalse("Make sure we have values",
configuration.isEmpty());
+
+ // overridden value
+ String key = "module.cache";
+ assertEquals("Read a config value " + key + ",
received:" + configuration.getString(key), "true",
configuration.getString(key));
+
+ // non overridden value
+ key = "scheduledjob.cache.size";
+ assertEquals("Read a config value " + key + ",
received:" + configuration.getString(key), "10",
configuration.getString(key));
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ finally
+ {
+ txc.dispose();
+ }
+ }
+
+ public void testCreateTurbineWithConfiguration() throws
Exception
+ {
+ tc = new TurbineConfig(".",
"/conf/test/TemplateService.properties");
+
+ try
+ {
+ tc.initialize();
+
+ Configuration configuration =
Turbine.getConfiguration();
+ assertNotNull("No Configuration Object found!",
configuration);
+ assertFalse("Make sure we have values",
configuration.isEmpty());
+
+ String key = "scheduledjob.cache.size";
+ assertEquals("Read a config value " + key + ",
received:" + configuration.getString(key), "10",
configuration.getString(key));
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ finally
+ {
+ tc.dispose();
+ }
+ }
+
+ public void testConfigurationValuesInSameOrder() throws
Exception
+ {
+ Configuration simpleConfiguration = null;
+ Configuration compositeConfiguration = null;
+
+ tc = new TurbineConfig(".",
"/conf/test/TemplateService.properties");
+
+ try
+ {
+ tc.initialize();
+ simpleConfiguration =
Turbine.getConfiguration();
+ }
+ finally
+ {
+ tc.dispose();
+ }
+
+ txc = new TurbineXmlConfig(".",
"/conf/test/TurbineConfiguration.xml");
+ try
+ {
+ txc.initialize();
+ compositeConfiguration =
Turbine.getConfiguration();
+ }
+ finally
+ {
+ txc.dispose();
+ }
+ Configuration a =
simpleConfiguration.subset("services");
+ Configuration b =
compositeConfiguration.subset("services");
+
+ List keysSimpleConfiguration =
IteratorUtils.toList(a.getKeys());
+ List keysCompositeConfiguration =
IteratorUtils.toList(b.getKeys());
+
+ assertTrue("Size:" + keysSimpleConfiguration.size(),
keysSimpleConfiguration.size() > 0);
+ assertEquals(keysSimpleConfiguration.size(),
keysCompositeConfiguration.size());
+
+ for (int i = 0; i < keysSimpleConfiguration.size(); i++)
+ {
+ log.debug("Key " + i + ": " +
keysSimpleConfiguration.get(i) + " - " +
keysCompositeConfiguration.get(i));
+ assertEquals(keysSimpleConfiguration.get(i),
keysCompositeConfiguration.get(i));
+ }
+
+ }
+
+ public void testMappingInSameOrder() throws Exception
+ {
+ Configuration simpleConfiguration = null;
+ Configuration compositeConfiguration = null;
+ Configuration mapping = new BaseConfiguration();
+ Configuration mapping2 = new BaseConfiguration();
+
+ tc = new TurbineConfig(".",
"/conf/test/TemplateService.properties");
+
+ try
+ {
+ tc.initialize();
+ simpleConfiguration =
Turbine.getConfiguration();
+ }
+ finally
+ {
+ tc.dispose();
+ }
+
+ txc = new TurbineXmlConfig(".",
"/conf/test/TurbineConfiguration.xml");
+ try
+ {
+ txc.initialize();
+ compositeConfiguration =
Turbine.getConfiguration();
+ }
+ finally
+ {
+ txc.dispose();
+ }
+
+ for (Iterator keys = simpleConfiguration.getKeys();
keys.hasNext();)
+ {
+ String key = (String) keys.next();
+ String[] keyParts = StringUtils.split(key, ".");
+
+ if ((keyParts.length == 3) && (keyParts[0] +
".").equals(SERVICE_PREFIX) && ("." +
keyParts[2]).equals(CLASSNAME_SUFFIX))
+ {
+ String serviceKey = keyParts[1];
+
+ if (!mapping.containsKey(serviceKey))
+ {
+ mapping.setProperty(serviceKey,
simpleConfiguration.getString(key));
+ }
+ }
+ }
+
+ for (Iterator keys = compositeConfiguration.getKeys();
keys.hasNext();)
+ {
+ String key = (String) keys.next();
+ String[] keyParts = StringUtils.split(key, ".");
+
+ if ((keyParts.length == 3) && (keyParts[0] +
".").equals(SERVICE_PREFIX) && ("." +
keyParts[2]).equals(CLASSNAME_SUFFIX))
+ {
+ String serviceKey = keyParts[1];
+
+ if (!mapping2.containsKey(serviceKey))
+ {
+ mapping2.setProperty(serviceKey,
compositeConfiguration.getString(key));
+ }
+ }
+ }
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org