commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons/configuration project.xml
Date Sun, 15 Feb 2004 11:58:37 GMT
epugh       2004/02/15 03:58:37

  Modified:    configuration/xdocs changes.xml
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationFactory.java
                        TestJNDIConfiguration.java
               configuration/src/java/org/apache/commons/configuration
                        JNDIConfiguration.java ConfigurationFactory.java
               configuration project.xml
  Log:
  Work on fixing JNDIConfiguration.getKeys()
  
  Revision  Changes    Path
  1.11      +1 -1      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- changes.xml	14 Feb 2004 20:06:23 -0000	1.10
  +++ changes.xml	15 Feb 2004 11:58:37 -0000	1.11
  @@ -6,7 +6,7 @@
     </properties>
   
     <body>
  -    <release version="1.0-dev-4" date=""> 
  +    <release version="1.0-dev-4" date="">     
   	 <action dev="epugh" type="update">
         	Bugzilla 16504 Enhancement: Configuration Comparator
        </action>        
  
  
  
  1.7       +218 -94   jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
  
  Index: TestConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestConfigurationFactory.java	12 Feb 2004 12:59:19 -0000	1.6
  +++ TestConfigurationFactory.java	15 Feb 2004 11:58:37 -0000	1.7
  @@ -71,11 +71,19 @@
   {
       /** The Files that we test with */
       private File digesterRules = new File("conf/digesterRules.xml");
  -    private File testDigesterFile = new File("conf/testDigesterConfiguration.xml");
  -    private File testDigesterFileReverseOrder = new File("conf/testDigesterConfigurationReverseOrder.xml");
  -    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 testDigesterFile =
  +        new File("conf/testDigesterConfiguration.xml");
  +    private File testDigesterFileReverseOrder =
  +        new File("conf/testDigesterConfigurationReverseOrder.xml");
  +    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();
  @@ -89,34 +97,63 @@
           configurationFactory = new ConfigurationFactory();
       }
   
  -    public void testLoadingConfiguration() throws Exception
  +    public void testJNDI()
       {
  -        configurationFactory.setConfigurationFileName(testDigesterFile.toString());
  +        JNDIConfiguration jndiConfiguration = new JNDIConfiguration();
  +        jndiConfiguration.setPrefix("");
  +        Object o = jndiConfiguration.getProperty("test.boolean");
  +        assertNotNull(o);
  +        assertEquals("true",o.toString());
   
  -        compositeConfiguration = (CompositeConfiguration) configurationFactory.getConfiguration();
  -
  -        assertEquals("Verify how many configs", 3, compositeConfiguration.getNumberOfConfigurations());
  -        assertEquals(PropertiesConfiguration.class, compositeConfiguration.getConfiguration(0).getClass());
  -        PropertiesConfiguration pc = (PropertiesConfiguration) compositeConfiguration.getConfiguration(0);
  +    }
  +    public void testLoadingConfiguration() throws Exception
  +    {
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFile.toString());
   
  -        assertNotNull("Make sure we have a fileName:" + pc.getFileName(), pc.getFileName());
  +        compositeConfiguration =
  +            (CompositeConfiguration) configurationFactory.getConfiguration();
   
  -        assertTrue("Make sure we have loades our key", compositeConfiguration.getBoolean("test.boolean"));
  -        assertEquals("I'm complex!", compositeConfiguration.getProperty("element2.subelement.subsubelement"));
  +        assertEquals(
  +            "Verify how many configs",
  +            3,
  +            compositeConfiguration.getNumberOfConfigurations());
  +        assertEquals(
  +            PropertiesConfiguration.class,
  +            compositeConfiguration.getConfiguration(0).getClass());
  +        PropertiesConfiguration pc =
  +            (PropertiesConfiguration) compositeConfiguration.getConfiguration(
  +                0);
  +
  +        assertNotNull(
  +            "Make sure we have a fileName:" + pc.getFileName(),
  +            pc.getFileName());
  +
  +        assertTrue(
  +            "Make sure we have loades our key",
  +            compositeConfiguration.getBoolean("test.boolean"));
  +        assertEquals(
  +            "I'm complex!",
  +            compositeConfiguration.getProperty(
  +                "element2.subelement.subsubelement"));
   
           configuration = (Configuration) compositeConfiguration;
  -        assertEquals("I'm complex!", configuration.getProperty("element2.subelement.subsubelement"));
  +        assertEquals(
  +            "I'm complex!",
  +            configuration.getProperty("element2.subelement.subsubelement"));
       }
   
       public void testLoadingConfigurationReverseOrder() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(testDigesterFileReverseOrder.toString());
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFileReverseOrder.toString());
   
           configuration = configurationFactory.getConfiguration();
   
           assertEquals("8", configuration.getProperty("test.short"));
   
  -        configurationFactory.setConfigurationFileName(testDigesterFile.toString());
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFile.toString());
   
           configuration = configurationFactory.getConfiguration();
           assertEquals("1", configuration.getProperty("test.short"));
  @@ -124,30 +161,51 @@
   
       public void testLoadingConfigurationWithRulesXML() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(testDigesterFile.toString());
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFile.toString());
           configurationFactory.setDigesterRules(digesterRules.toURL());
   
  -        compositeConfiguration = (CompositeConfiguration) configurationFactory.getConfiguration();
  -
  -        assertEquals("Verify how many configs", 3, compositeConfiguration.getNumberOfConfigurations());
  -
  -        assertEquals(PropertiesConfiguration.class, compositeConfiguration.getConfiguration(0).getClass());
  +        compositeConfiguration =
  +            (CompositeConfiguration) configurationFactory.getConfiguration();
   
  -        PropertiesConfiguration pc = (PropertiesConfiguration) compositeConfiguration.getConfiguration(0);
  -        assertNotNull("Make sure we have a fileName:" + pc.getFileName(), pc.getFileName());
  -        assertTrue("Make sure we have loaded our key", pc.getBoolean("test.boolean"));
  -
  -        assertTrue("Make sure we have loaded our key", compositeConfiguration.getBoolean("test.boolean"));
  -
  -        assertEquals("I'm complex!", compositeConfiguration.getProperty("element2.subelement.subsubelement"));
  +        assertEquals(
  +            "Verify how many configs",
  +            3,
  +            compositeConfiguration.getNumberOfConfigurations());
  +
  +        assertEquals(
  +            PropertiesConfiguration.class,
  +            compositeConfiguration.getConfiguration(0).getClass());
  +
  +        PropertiesConfiguration pc =
  +            (PropertiesConfiguration) compositeConfiguration.getConfiguration(
  +                0);
  +        assertNotNull(
  +            "Make sure we have a fileName:" + pc.getFileName(),
  +            pc.getFileName());
  +        assertTrue(
  +            "Make sure we have loaded our key",
  +            pc.getBoolean("test.boolean"));
  +
  +        assertTrue(
  +            "Make sure we have loaded our key",
  +            compositeConfiguration.getBoolean("test.boolean"));
  +
  +        assertEquals(
  +            "I'm complex!",
  +            compositeConfiguration.getProperty(
  +                "element2.subelement.subsubelement"));
   
           configuration = (Configuration) compositeConfiguration;
  -        assertEquals("I'm complex!", configuration.getProperty("element2.subelement.subsubelement"));
  +        assertEquals(
  +            "I'm complex!",
  +            configuration.getProperty("element2.subelement.subsubelement"));
       }
   
       public void testLoadingConfigurationNamespaceAware() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(testDigesterFileNamespaceAware.toString());
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFileNamespaceAware.toString());
           //configurationFactory.setDigesterRules(digesterRules.toURL());
           configurationFactory.setDigesterRuleNamespaceURI("namespace-one");
   
  @@ -156,90 +214,156 @@
   
       public void testLoadingConfigurationBasePath() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(testDigesterFileBasePath.toString());
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFileBasePath.toString());
   
           configurationFactory.setBasePath(testBasePath);
   
           //configurationFactory.setDigesterRules(digesterRules.toURL());
           //configurationFactory.setDigesterRuleNamespaceURI("namespace-one");
   
  -		checkCompositeConfiguration();
  +        checkCompositeConfiguration();
       }
  -    
  +
       public void testLoadingAdditional() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(testDigesterFileEnhanced.toString());
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterFileEnhanced.toString());
           configurationFactory.setBasePath(null);
  -        checkUnionConfig();        
  +        checkUnionConfig();
       }
  -    
  +
       public void testLoadingURL() throws Exception
       {
  -        configurationFactory.setConfigurationURL(testDigesterFileEnhanced.toURL());
  +        configurationFactory.setConfigurationURL(
  +            testDigesterFileEnhanced.toURL());
           checkUnionConfig();
       }
  -    
  -    public void testThrowingConfigurationInitializationException() throws Exception
  -	{
  -    	configurationFactory.setConfigurationFileName(testDigesterBadXML.toString());
  -    	try {
  -    		configurationFactory.getConfiguration();
  -    		fail("Should have throw an Exception");
  -    	}
  -    	catch (ConfigurationException cle){
  -    		assertTrue(cle.getCause() instanceof SAXParseException);
  -    	}
  +
  +    public void testThrowingConfigurationInitializationException()
  +        throws Exception
  +    {
  +        configurationFactory.setConfigurationFileName(
  +            testDigesterBadXML.toString());
  +        try
  +        {
  +            configurationFactory.getConfiguration();
  +            fail("Should have throw an Exception");
  +        }
  +        catch (ConfigurationException 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());
  +        assertTrue(config instanceof CompositeConfiguration);
  +        CompositeConfiguration cc = (CompositeConfiguration)config;
  +        assertTrue(cc.getNumberOfConfigurations()>1);
  +        // Currently fails, should be 4?  Only 2?
  +        //assertEquals(4,cc.getNumberOfConfigurations());
  +
  +        assertNotNull(
  +            config.getProperty("tables.table(0).fields.field(2).name"));
  +        assertNotNull(config.getProperty("element2.subelement.subsubelement"));
  +        assertNotNull(config.getProperty("mail.account.user"));
  +        // Fails, because we don't seem to reach the underlying JNDIConfiguraiton     
  
  +        //assertNotNull(config.getProperty("test.boolean"));
  +    }
  +
       private void checkUnionConfig() throws Exception
       {
  -        compositeConfiguration = (CompositeConfiguration) configurationFactory.getConfiguration();
  -        assertEquals("Verify how many configs", 3, compositeConfiguration.getNumberOfConfigurations());
  -        
  -         // Test if union was constructed correctly
  +        compositeConfiguration =
  +            (CompositeConfiguration) configurationFactory.getConfiguration();
  +        assertEquals(
  +            "Verify how many configs",
  +            3,
  +            compositeConfiguration.getNumberOfConfigurations());
  +
  +        // Test if union was constructed correctly
           Object prop = compositeConfiguration.getProperty("tables.table.name");
           assertTrue(prop instanceof Collection);
           assertEquals(3, ((Collection) prop).size());
  -        assertEquals("users", compositeConfiguration.getProperty("tables.table(0).name"));
  -        assertEquals("documents", compositeConfiguration.getProperty("tables.table(1).name"));
  -        assertEquals("tasks", compositeConfiguration.getProperty("tables.table(2).name"));
  -        
  -        prop = compositeConfiguration.getProperty("tables.table.fields.field.name");
  +        assertEquals(
  +            "users",
  +            compositeConfiguration.getProperty("tables.table(0).name"));
  +        assertEquals(
  +            "documents",
  +            compositeConfiguration.getProperty("tables.table(1).name"));
  +        assertEquals(
  +            "tasks",
  +            compositeConfiguration.getProperty("tables.table(2).name"));
  +
  +        prop =
  +            compositeConfiguration.getProperty(
  +                "tables.table.fields.field.name");
           assertTrue(prop instanceof Collection);
           assertEquals(17, ((Collection) prop).size());
  -        
  -        assertEquals("smtp.mydomain.org", compositeConfiguration.getString("mail.host.smtp"));
  -        assertEquals("pop3.mydomain.org", compositeConfiguration.getString("mail.host.pop"));
  -        
  +
  +        assertEquals(
  +            "smtp.mydomain.org",
  +            compositeConfiguration.getString("mail.host.smtp"));
  +        assertEquals(
  +            "pop3.mydomain.org",
  +            compositeConfiguration.getString("mail.host.pop"));
  +
           // This was overriden
  -        assertEquals("masterOfPost", compositeConfiguration.getString("mail.account.user"));
  -        assertEquals("topsecret", compositeConfiguration.getString("mail.account.psswd"));
  -        
  +        assertEquals(
  +            "masterOfPost",
  +            compositeConfiguration.getString("mail.account.user"));
  +        assertEquals(
  +            "topsecret",
  +            compositeConfiguration.getString("mail.account.psswd"));
  +
           // This was overriden, too, but not in additional section
  -        assertEquals("enhanced factory", compositeConfiguration.getString("test.configuration"));
  +        assertEquals(
  +            "enhanced factory",
  +            compositeConfiguration.getString("test.configuration"));
  +    }
  +
  +    private void checkCompositeConfiguration() throws Exception
  +    {
  +        compositeConfiguration =
  +            (CompositeConfiguration) configurationFactory.getConfiguration();
  +
  +        assertEquals(
  +            "Verify how many configs",
  +            2,
  +            compositeConfiguration.getNumberOfConfigurations());
  +
  +        assertEquals(
  +            PropertiesConfiguration.class,
  +            compositeConfiguration.getConfiguration(0).getClass());
  +
  +        PropertiesConfiguration pc =
  +            (PropertiesConfiguration) compositeConfiguration.getConfiguration(
  +                0);
  +        assertNotNull(
  +            "Make sure we have a fileName:" + pc.getFileName(),
  +            pc.getFileName());
  +        assertTrue(
  +            "Make sure we have loaded our key",
  +            pc.getBoolean("test.boolean"));
  +
  +        assertTrue(
  +            "Make sure we have loaded our key",
  +            compositeConfiguration.getBoolean("test.boolean"));
  +
  +        try
  +        {
  +            compositeConfiguration.getProperty(
  +                "element2.subelement.subsubelement");
  +            fail("Should have thrown an exception");
  +        }
  +        catch (java.util.NoSuchElementException nsee)
  +        {
  +        }
       }
  -    
  -	private void checkCompositeConfiguration() throws Exception
  -	{
  -		compositeConfiguration = (CompositeConfiguration) configurationFactory.getConfiguration();
  -
  -		assertEquals("Verify how many configs", 2, compositeConfiguration.getNumberOfConfigurations());
  -
  -		assertEquals(PropertiesConfiguration.class, compositeConfiguration.getConfiguration(0).getClass());
  -
  -		PropertiesConfiguration pc = (PropertiesConfiguration) compositeConfiguration.getConfiguration(0);
  -		assertNotNull("Make sure we have a fileName:" + pc.getFileName(), pc.getFileName());
  -		assertTrue("Make sure we have loaded our key", pc.getBoolean("test.boolean"));
  -
  -		assertTrue("Make sure we have loaded our key", compositeConfiguration.getBoolean("test.boolean"));
  -
  -		try
  -		{
  -			compositeConfiguration.getProperty("element2.subelement.subsubelement");
  -			fail("Should have thrown an exception");
  -		}
  -		catch (java.util.NoSuchElementException nsee)
  -		{
  -		}
  -	}    
   }
  
  
  
  1.4       +14 -1     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestJNDIConfiguration.java
  
  Index: TestJNDIConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestJNDIConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestJNDIConfiguration.java	14 Feb 2004 20:06:23 -0000	1.3
  +++ TestJNDIConfiguration.java	15 Feb 2004 11:58:37 -0000	1.4
  @@ -54,6 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.Iterator;
  +
   import junit.framework.TestCase;
   
   /**
  @@ -161,9 +163,20 @@
   	  public void testProperties() throws Exception{
   	      Object o = conf.getProperty("test.boolean");
   	      assertNotNull(o);
  +	      assertEquals("true",o.toString());
   	      
   	  }
   
  +	  /** 
  +	   * Currently failing in that we don't get back any keys!
  +	   * @throws Exception
  +	   */
  +	  public void testGetKeys() throws Exception{
  +	      Iterator i = conf.getKeys();
  +	      for (;i.hasNext();){
  +	          System.out.println(i.next());
  +	      }
  +	  }
   
       
   
  
  
  
  1.5       +8 -1      jakarta-commons/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java
  
  Index: JNDIConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JNDIConfiguration.java	14 Feb 2004 20:06:23 -0000	1.4
  +++ JNDIConfiguration.java	15 Feb 2004 11:58:37 -0000	1.5
  @@ -179,7 +179,14 @@
               }
               if (context != null)
               {
  +                NamingEnumeration enum2 = context.list("");
  +                for(;enum2.hasMore();){
  +                    System.out.println(enum2.next());
  +                }
                   NamingEnumeration enum = context.listBindings("");
  +                for(;enum.hasMore();){
  +                    System.out.println(enum.next());
  +                }
                   recursiveGetKeys(keys, enum, key);
               }
           }
  
  
  
  1.7       +6 -6      jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java
  
  Index: ConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConfigurationFactory.java	30 Jan 2004 14:46:37 -0000	1.6
  +++ ConfigurationFactory.java	15 Feb 2004 11:58:37 -0000	1.7
  @@ -110,7 +110,7 @@
        * the configuration to load and used unless no other base path was
        * explicitely specified.
        */
  -    private String impliciteBasePath;
  +    private String implicitBasePath;
       /** The basePath to prefix file paths for file based property files. */
       private String basePath;
       /** static logger */
  @@ -154,7 +154,7 @@
           try {
           if(url == null)
           {
  -            url = ConfigurationUtils.getURL(impliciteBasePath,
  +            url = ConfigurationUtils.getURL(implicitBasePath,
               getConfigurationFileName());
           }  /* if */
           input = url.openStream();
  @@ -215,7 +215,7 @@
       {
           File file = new File(configurationFileName).getAbsoluteFile();
           this.configurationFileName = file.getName();
  -        impliciteBasePath = file.getParent();
  +        implicitBasePath = file.getParent();
       }
   
       /**
  @@ -235,7 +235,7 @@
       public void setConfigurationURL(URL url)
       {
           configurationURL = url;
  -        impliciteBasePath = url.toString();
  +        implicitBasePath = url.toString();
   
           // The following is a hack caused by the need to keep backwards
           // compatibility: Per default the base path is set to the current
  @@ -411,7 +411,7 @@
       public String getBasePath()
       {
           String path = StringUtils.isEmpty(basePath) ? 
  -        impliciteBasePath : basePath;
  +        implicitBasePath : basePath;
           return StringUtils.isEmpty(path) ? "." : path;
       }
       /**
  
  
  
  1.10      +2 -2      jakarta-commons/configuration/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/project.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.xml	14 Feb 2004 18:54:32 -0000	1.9
  +++ project.xml	15 Feb 2004 11:58:37 -0000	1.10
  @@ -202,7 +202,7 @@
   
       <dependency>
         <id>simple-jndi</id>
  -      <version>0.8</version>
  +      <version>0.9.1</version>
         <url>http://www.osjava.org/simple-jndi/</url> 
       </dependency>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message