01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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: package org.kuali.rice.config;
17:
18: import java.util.Properties;
19:
20: import junit.framework.TestCase;
21:
22: import org.junit.Test;
23:
24: public class HierarchicalConfigParserTest extends TestCase {
25:
26: /**
27: * Tests the resolution to issue EN-68 where the overrides are working properly
28: * after attempting to overrdide a property after a few levels of depth.
29: */
30: @Test
31: public void testHierarchicalConfigParser() throws Exception {
32: // first load the hier-config-3.xml file
33: // HierarchicalConfigParser parser = new HierarchicalConfigParser(null);
34: SimpleConfig simpleConfig = new SimpleConfig(
35: "classpath:org/kuali/rice/config/hier-config-3.xml");
36: simpleConfig.parseConfig();
37: // String fileLoc1 = ;
38: // Map propertyMap = parser.parse(fileLoc1);
39: Properties properties = simpleConfig.getProperties();
40: assertNotNull(properties);
41: assertEquals("user3", properties.get("axis:user"));
42: assertEquals("password3", properties.get("axis:password"));
43: assertEquals("user3", properties.get("user"));
44: assertEquals("password3", properties.get("password"));
45:
46: // next load the hier-config-2.xml file
47:
48: String fileLoc2 = "classpath:org/kuali/rice/config/hier-config-2.xml";
49: simpleConfig = new SimpleConfig(fileLoc2);
50: simpleConfig.parseConfig();
51: properties = simpleConfig.getProperties();
52: assertNotNull(properties);
53: assertEquals("user3", properties.get("user"));
54: assertEquals("password3", properties.get("password"));
55: assertEquals("user3", properties.get("axis:user"));
56: assertEquals("password3", properties.get("axis:password"));
57: assertEquals("user3", properties.get("user2"));
58: assertEquals("password3", properties.get("password2"));
59:
60: // next load the hier-config-1.xml file
61: String fileLoc3 = "classpath:org/kuali/rice/config/hier-config-1.xml";
62: simpleConfig = new SimpleConfig(fileLoc3);
63: simpleConfig.parseConfig();
64: properties = simpleConfig.getProperties();
65: assertNotNull(properties);
66:
67: // pull the configuration for hier-config-3 out of the parsing of hier-config-1
68: // properties = (Properties)propertyMap.get(fileLoc1);
69: assertEquals("user3", properties.get("axis:user"));
70: assertEquals("password3", properties.get("axis:password"));
71: assertEquals("user3", properties.get("user"));
72: assertEquals("password3", properties.get("password"));
73: }
74:
75: /**
76: * all we can do is test that this xml won't blow the parser up.
77: * <param name="config.location">${alt.config.location}</param>
78: * making the logging look good is out of our hands.
79: *
80: * @throws Exception
81: */
82: @Test
83: public void testParsingOfAltConfigLocation() throws Exception {
84: String fileLoc1 = "classpath:org/kuali/rice/config/config-alt-location-param.xml";
85: SimpleConfig simpleConfig = new SimpleConfig(fileLoc1);
86: simpleConfig.parseConfig();
87: assertNotNull(simpleConfig.getProperties());
88: }
89:
90: }
|