1 16 17 package org.apache.commons.configuration; 18 19 import junit.framework.TestCase; 20 21 import javax.naming.InitialContext ; 22 23 32 public class TestJNDIConfiguration extends TestCase { 33 34 public static final String CONTEXT_FACTORY = 35 "org.apache.commons.configuration.MockStaticMemoryInitialContextFactory"; 36 37 private JNDIConfiguration conf; 38 private NonStringTestHolder nonStringTestHolder; 39 40 public void setUp() throws Exception { 41 42 System.setProperty("java.naming.factory.initial", CONTEXT_FACTORY); 43 44 conf = new JNDIConfiguration(); 45 46 nonStringTestHolder = new NonStringTestHolder(); 47 nonStringTestHolder.setConfiguration(conf); 48 } 49 50 public void testBoolean() throws Exception { 51 nonStringTestHolder.testBoolean(); 52 } 53 54 public void testBooleanDefaultValue() throws Exception { 55 nonStringTestHolder.testBooleanDefaultValue(); 56 } 57 58 public void testByte() throws Exception { 59 nonStringTestHolder.testByte(); 60 } 61 62 public void testDouble() throws Exception { 63 nonStringTestHolder.testDouble(); 64 } 65 66 public void testDoubleDefaultValue() throws Exception { 67 nonStringTestHolder.testDoubleDefaultValue(); 68 } 69 70 public void testFloat() throws Exception { 71 nonStringTestHolder.testFloat(); 72 } 73 74 public void testFloatDefaultValue() throws Exception { 75 nonStringTestHolder.testFloatDefaultValue(); 76 } 77 78 public void testInteger() throws Exception { 79 nonStringTestHolder.testInteger(); 80 } 81 82 public void testIntegerDefaultValue() throws Exception { 83 nonStringTestHolder.testIntegerDefaultValue(); 84 } 85 86 public void testLong() throws Exception { 87 nonStringTestHolder.testLong(); 88 } 89 90 public void testLongDefaultValue() throws Exception { 91 nonStringTestHolder.testLongDefaultValue(); 92 } 93 94 public void testShort() throws Exception { 95 nonStringTestHolder.testShort(); 96 } 97 98 public void testShortDefaultValue() throws Exception { 99 nonStringTestHolder.testShortDefaultValue(); 100 } 101 102 public void testListMissing() throws Exception { 103 nonStringTestHolder.testListMissing(); 104 } 105 106 public void testSubset() throws Exception { 107 nonStringTestHolder.testSubset(); 108 } 109 110 public void testProperties() throws Exception { 111 Object o = conf.getProperty("test.boolean"); 112 assertNotNull(o); 113 assertEquals("true", o.toString()); 114 } 115 116 public void testContainsKey() 117 { 118 String key = "test.boolean"; 119 assertTrue("'" + key + "' not found", conf.containsKey(key)); 120 121 conf.clearProperty(key); 122 assertFalse("'" + key + "' still found", conf.containsKey(key)); 123 } 124 125 public void testChangePrefix() 126 { 127 assertEquals("'test.boolean' property", "true", conf.getString("test.boolean")); 128 assertEquals("'boolean' property", null, conf.getString("boolean")); 129 130 conf.setPrefix("test"); 132 assertEquals("'test.boolean' property", null, conf.getString("test.boolean")); 133 assertEquals("'boolean' property", "true", conf.getString("boolean")); 134 } 135 136 public void testResetRemovedProperties() throws Exception 137 { 138 assertEquals("'test.boolean' property", "true", conf.getString("test.boolean")); 139 140 conf.clearProperty("test.boolean"); 142 assertEquals("'test.boolean' property", null, conf.getString("test.boolean")); 143 144 conf.setContext(new InitialContext ()); 146 147 assertEquals("'test.boolean' property", "true", conf.getString("test.boolean")); 149 } 150 151 public void testConstructor() throws Exception 152 { 153 conf = new JNDIConfiguration(new InitialContext ()); 155 156 assertEquals("'test.boolean' property", "true", conf.getString("test.boolean")); 157 158 conf = new JNDIConfiguration(new InitialContext (), "test"); 160 161 assertEquals("'boolean' property", "true", conf.getString("boolean")); 162 } 163 164 } | Popular Tags |