When trying to add a unit test to check all XML elements supported by ConfigurationFactory I faced a problem with JNDIConfiguration. This class seems to be incompatible with ConfigurationFactory when used in the <additional> section.

I did not much further research, but I suspect that the problem is in getKeys(), which always returns an empty iterator though getString() returns values for some keys. I also found out that the getProperty() method always throws an exception which would cause further problems if a correct iterator was returned. I suppose it would be better to delegate to getString() instead(?).

Attached is a patch for TestConfigurationFactory that demonstrates the problem. The other file is a configuration definition file that must be placed in the conf directory.

Oliver

Eric Pugh wrote:

Okay, I put the missing code back in.. It would be nice to have a unit test that caught that.

Eric



-----Original Message-----
From: Oliver Heger [mailto:[EMAIL PROTECTED]
Sent: Friday, January 23, 2004 11:07 AM
To: Jakarta Commons Developers List
Subject: Re: ConfigurationFactory and hierarchicalDom4j


This is strange: If you have a look at the source xrefs for the ConfigurationFactory class at http://jakarta.apache.org/commons/configuration/xref/org/apach
e/commons/configuration/ConfigurationFactory.html
you will see that the missing rule is present. So it must have been accidently deleted in one of the last commits(?).
Oliver


Eric Pugh schrieb:



Oliver, would you like to submit a patch for this? Also,

if you could submit a unit test showing the problem.. Not good when all the unit tests pass, but a bug still exists!


In terms of a release, basically we are just wrangling over

whether to throw a ConfigurationException.. At this point, the feeling seems to be that no good solution really exists right now. We need (in Configuration 2 or 1.5 or whatever) to refactor the process of loading a configuration object from the process of having a configuration object. That way cool stuff like multiple reloading strategies etc become possible.


At this point, there are a coupld throws Exception that I

am going to replace with a checked ConfigurationInitializationException or ConfigurationLoadException...


So, 1.0 is coming down the pike very soon..

Eric
 -----Original Message-----
 From: Oliver Kim [mailto:[EMAIL PROTECTED]
 Sent: Friday, January 23, 2004 8:27 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: ConfigurationFactory and hierarchicalDom4j


You guys probably would have figured this out pretty


quickly, but since I found it, I thought I'd let you know...


The following code snipped should contain a rule for

hierarchicalDom4j:


protected void initDigesterSectionRules(Digester digester,
String matchString, boolean additional)
{
setupDigesterInstance(
digester,
matchString + "properties",
new


BasePathConfigurationFactory(PropertiesConfiguration.class),


METH_LOAD,
additional);
setupDigesterInstance(
digester,
matchString + "dom4j",
new


BasePathConfigurationFactory(DOM4JConfiguration.class),


             METH_LOAD,
             additional);
         setupDigesterInstance(
             digester,
             matchString + "jndi",
             new JNDIConfigurationFactory(),
             null,
             additional);
     }


Like so:


protected void initDigesterSectionRules(Digester digester,
String matchString, boolean additional)
{
setupDigesterInstance(
digester,
matchString + "properties",
new


BasePathConfigurationFactory(PropertiesConfiguration.class),


METH_LOAD,
additional);
setupDigesterInstance(
digester,
matchString + "dom4j",
new


BasePathConfigurationFactory(DOM4JConfiguration.class),


METH_LOAD,
additional);
setupDigesterInstance(
digester,
matchString + "hierarchicalDom4j",
new


BasePathConfigurationFactory(HierarchicalDOM4JConfiguration.class),


             METH_LOAD,
             additional);
         setupDigesterInstance(
             digester,
             matchString + "jndi",
             new JNDIConfigurationFactory(),
             null,
             additional);
     }

It seems to work fine once you do this.

As an aside? How close do you think Configuration is to

release? I'm considering using it in one of my projects.


Thanks,

Oliver Kim


--
Oliver Heger
Zentrale Informationsverarbeitung (ZIV) / Bereich Anwenderverfahren
Klinikum der Philipps-UniversitÃt Marburg
BunsenstraÃe 3,
D-35037 Marburg
Tel: +49 6421 28-66592
mailto:[EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Configuration test file that checks all known configuration types -->

<configuration>
  <additional>
    <dom4j fileName="test.xml"/>
    <hierarchicalDom4j fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
    <properties fileName="testDigesterConfigurationInclude2.properties" at="mail"/>
    <jndi prefix=""/>
  </additional>
</configuration>

  




Index: src/test/org/apache/commons/configuration/TestConfigurationFactory.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java,v
retrieving revision 1.4
diff -u -r1.4 TestConfigurationFactory.java
--- src/test/org/apache/commons/configuration/TestConfigurationFactory.java     23 Jan 
2004 11:52:36 -0000      1.4
+++ src/test/org/apache/commons/configuration/TestConfigurationFactory.java     23 Jan 
2004 19:26:50 -0000
@@ -77,6 +77,7 @@
     private File testDigesterFileNamespaceAware = new 
File("conf/testDigesterConfigurationNamespaceAware.xml");
     private File testDigesterFileBasePath = new 
File("conf/testDigesterConfigurationBasePath.xml");
     private File testDigesterFileEnhanced = new 
File("conf/testDigesterConfiguration2.xml");
+    private File testDigesterFileComplete = new 
File("conf/testDigesterConfiguration3.xml");
     private File testDigesterBadXML = new File("conf/testDigesterBadXML.xml");
 
     private String testBasePath = new File("conf").getAbsolutePath();
@@ -190,6 +191,19 @@
        catch (ConfigurationLoadException cle){
                assertTrue(cle.getCause() instanceof SAXParseException);
        }
+    }
+    
+    // Tests if properties from all sources can be loaded
+    public void testAllConfiguration() throws Exception
+    {
+        configurationFactory.setConfigurationURL(testDigesterFileComplete.toURL());
+        Configuration config = configurationFactory.getConfiguration();
+        assertFalse(config.isEmpty());
+        
+        assertNotNull(config.getProperty("tables.table(0).fields.field(2).name"));
+        assertNotNull(config.getProperty("element2.subelement.subsubelement"));
+        assertNotNull(config.getProperty("mail.account.user"));
+        assertNotNull(config.getProperty("test/key"));
     }
     
     private void checkUnionConfig() throws Exception
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to