View Javadoc

1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.core.config;
18  
19  import java.io.IOException;
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.Properties;
23  
24  import junit.framework.TestCase;
25  
26  import org.junit.Test;
27  import org.kuali.rice.core.config.SimpleConfig;
28  
29  public class BaseConfigTest extends TestCase {
30      /**
31       * Tests the hierarchical override capabilities.
32       */
33      @Test public void testBaseConfig() throws IOException {
34      	Properties base = new Properties();
35          base.setProperty("foo", "base:foo");
36          base.setProperty("boo", "base:boo");
37          List<String> configs = new ArrayList<String>(1);
38          configs.add("classpath:org/kuali/rice/core/config/config-1.xml");
39          Config sc = new JAXBConfigImpl(configs, base);
40          sc.parseConfig();
41          assertEquals("base:boo", sc.getProperty("boo"));
42          assertEquals("config-1:foo base:boo", sc.getProperty("foo"));
43          assertEquals("config-2:bar config-1:baz", sc.getProperty("bar"));
44          assertEquals("config-2:blah base:boo", sc.getProperty("blah"));
45          assertEquals("config-2:quux", sc.getProperty("quux"));
46          
47          String r1 = sc.getProperty("random1");
48          String r2 = sc.getProperty("random2");
49          String r3 = sc.getProperty("random3");
50          
51          assertNotNull(r1);
52          assertNotNull(r2);
53          assertNotNull(r3);
54          
55          assertTrue(between(100, 199, Integer.parseInt(r1)));
56          assertTrue(between(200, 299, Integer.parseInt(r2)));
57          assertTrue(between(300, 399, Integer.parseInt(r3)));
58      }
59      
60      protected boolean between(int min, int max, int val) {
61          return val >= min && val <= max;
62      }
63  }