1 16 17 package org.apache.commons.configuration; 18 19 import java.io.File ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.cactus.ServletTestCase; 24 import org.apache.commons.collections.IteratorUtils; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 public class TestConfigurationFactoryWithJNDI extends ServletTestCase 29 { 30 private File testDigesterFile = new File ("conf/testDigesterConfigurationWJNDI.xml"); 31 private static Log log = LogFactory.getLog(TestConfigurationFactoryWithJNDI.class); 32 33 public void testLoadingWithDigester() throws Exception 34 { 35 ConfigurationFactory cf = new ConfigurationFactory(); 36 cf.setConfigurationFileName(testDigesterFile.toString()); 37 CompositeConfiguration compositeConfiguration = (CompositeConfiguration) cf.getConfiguration(); 38 39 assertEquals("Verify how many configs", 4, compositeConfiguration.getNumberOfConfigurations()); 40 41 assertEquals(JNDIConfiguration.class, compositeConfiguration.getConfiguration(1).getClass()); 42 assertEquals(PropertiesConfiguration.class, compositeConfiguration.getConfiguration(2).getClass()); 43 PropertiesConfiguration pc = (PropertiesConfiguration) compositeConfiguration.getConfiguration(2); 45 46 assertNotNull("Make sure we have a fileName:" + pc.getFileName(), pc.getFileName()); 47 48 assertTrue("Make sure we have loaded our key", compositeConfiguration.getBoolean("test.boolean")); 49 assertEquals("I'm complex!", compositeConfiguration.getProperty("element2.subelement.subsubelement")); 50 51 assertEquals("Make sure the JNDI config overwrites everything else!", "80", compositeConfiguration.getString("test.overwrite")); 52 } 53 54 59 public void testGetKeys() throws Exception 60 { 61 ConfigurationFactory cf = new ConfigurationFactory(); 62 cf.setConfigurationFileName(testDigesterFile.toString()); 63 64 Configuration c = cf.getConfiguration(); 65 66 List iteratedList = IteratorUtils.toList(c.getKeys()); 67 assertTrue(iteratedList.contains("test.jndi")); 68 } 69 70 75 public void testGetKeysWithString() throws Exception 76 { 77 String KEY = "test"; 78 ConfigurationFactory cf = new ConfigurationFactory(); 79 cf.setConfigurationFileName(testDigesterFile.toString()); 80 81 Configuration c = cf.getConfiguration(); 82 83 List iteratedList = IteratorUtils.toList(c.getKeys(KEY)); 84 85 assertTrue("Size:" + iteratedList.size(), iteratedList.size() > 0); 86 assertTrue(iteratedList.contains("test.jndi")); 87 for (Iterator i = iteratedList.iterator(); i.hasNext();) 88 { 89 String foundKey = (String ) i.next(); 90 assertTrue(foundKey.startsWith(KEY)); 91 } 92 } 93 94 100 public void testGetKeysWithString2() throws Exception 101 { 102 String KEY = "test.deep"; 103 ConfigurationFactory cf = new ConfigurationFactory(); 104 cf.setConfigurationFileName(testDigesterFile.toString()); 105 106 Configuration c = cf.getConfiguration(); 107 108 List iteratedList = IteratorUtils.toList(c.getKeys(KEY)); 109 110 assertTrue("Size:" + iteratedList.size(), iteratedList.size() == 2); 111 assertTrue(iteratedList.contains("test.deep.somekey")); 112 for (Iterator i = iteratedList.iterator(); i.hasNext();) 113 { 114 String foundKey = (String ) i.next(); 115 assertTrue(foundKey.startsWith(KEY)); 116 } 117 } 118 119 } 120 | Popular Tags |