1 16 17 package org.apache.commons.configuration; 18 19 import org.apache.cactus.ServletTestCase; 20 import java.io.File ; 21 22 public class TestJNDIAndCompositeConfiguration extends ServletTestCase 23 { 24 private String testProperties = new File ("conf/test.properties").getAbsolutePath(); 25 26 private CompositeConfiguration cc; 27 private PropertiesConfiguration conf1; 28 private JNDIConfiguration jndiConf; 29 30 public void setUp() throws Exception 31 { 32 jndiConf = new JNDIConfiguration(); 33 jndiConf.setPrefix("java:comp/env"); 34 35 cc = new CompositeConfiguration(); 36 conf1 = new PropertiesConfiguration(testProperties); 37 38 cc.addConfiguration(jndiConf); 39 cc.addConfiguration(conf1); 40 } 41 42 public void testSimpleGet() throws Exception 43 { 44 String s = cc.getString("test.overwrite"); 45 assertEquals("80", s); 46 47 cc.clear(); 48 cc.addConfiguration(conf1); 49 cc.addConfiguration(jndiConf); 50 assertEquals("1", cc.getString("test.overwrite")); 51 } 52 53 56 public void testClearingProperty() throws Exception 57 { 58 59 cc.clearProperty("test.short"); 60 assertTrue("Make sure test.short is gone!", !cc.containsKey("test.short")); 61 } 62 63 66 public void testAddingProperty() throws Exception 67 { 68 cc.addProperty("test.short", "88"); 69 assertEquals("Make sure test.short is overridden!", "88", cc.getString("test.short")); 70 } 71 72 75 public void testSettingMissingProperty() throws Exception 76 { 77 cc.setProperty("my.new.property", "supernew"); 78 assertEquals("supernew", cc.getString("my.new.property")); 79 } 80 } 81 | Popular Tags |