KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > TestJNDIAndCompositeConfiguration


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.configuration;
18
19 import org.apache.cactus.ServletTestCase;
20 import java.io.File JavaDoc;
21
22 public class TestJNDIAndCompositeConfiguration extends ServletTestCase
23 {
24     private String JavaDoc testProperties = new File JavaDoc("conf/test.properties").getAbsolutePath();
25
26     private CompositeConfiguration cc;
27     private PropertiesConfiguration conf1;
28     private JNDIConfiguration jndiConf;
29
30     public void setUp() throws Exception JavaDoc
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 JavaDoc
43     {
44         String JavaDoc 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     /**
54      * Tests setting values. These are set in memory mode only!
55      */

56     public void testClearingProperty() throws Exception JavaDoc
57     {
58
59         cc.clearProperty("test.short");
60         assertTrue("Make sure test.short is gone!", !cc.containsKey("test.short"));
61     }
62
63     /**
64      * Tests adding values. Make sure they override any other properties!
65      */

66     public void testAddingProperty() throws Exception JavaDoc
67     {
68         cc.addProperty("test.short", "88");
69         assertEquals("Make sure test.short is overridden!", "88", cc.getString("test.short"));
70     }
71
72     /**
73      * Tests setting values. These are set in memory mode only!
74      */

75     public void testSettingMissingProperty() throws Exception JavaDoc
76     {
77         cc.setProperty("my.new.property", "supernew");
78         assertEquals("supernew", cc.getString("my.new.property"));
79     }
80 }
81
Popular Tags