View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.tests.util.config;
18  
19  import static org.junit.Assert.assertTrue;
20  
21  import org.junit.Test;
22  
23  import ch.elca.el4j.util.config.HierarchicalGenericConfig;
24  
25  //Checkstyle: MagicNumber off
26  //Checkstyle: EmptyBlock off
27  
28  /**
29   * This class tests {@link HierarchicalGenericConfig}.
30   *
31   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/test/java/ch/elca/el4j/tests/util/config/AbstractHierarchicalGenericConfigTest.java $
32   *
33   * @author Stefan Wismer (SWI)
34   */
35  public abstract class AbstractHierarchicalGenericConfigTest {
36  	/***/
37  	@Test
38  	public void testGenericConfig() {
39  		HierarchicalGenericConfig config = getDefaultConfig();
40  		
41  		assertTrue(config.get("ch.elca.el4j").equals("EL4J"));
42  		assertTrue(config.get("ch.elca.el4j.tests.core").equals("core"));
43  		assertTrue(config.getMap().size() == 8);
44  		
45  		HierarchicalGenericConfig subConfig
46  			= config.getSubConfig("ch.elca.el4j.default");
47  		assertTrue(subConfig.getMap().size() == 4);
48  		assertTrue(subConfig.getChildren().size() == 3);
49  		assertTrue(subConfig.get("a").equals("defaultA"));
50  		assertTrue(subConfig.get("b").equals("defaultB"));
51  		
52  		HierarchicalGenericConfig subsubConfig
53  			= (HierarchicalGenericConfig) subConfig.getChildren().get("c");
54  		assertTrue(subsubConfig.get("d").equals("defaultCD"));
55  		
56  		subConfig = config.getSubConfig("ch.elca.el4j.tests");
57  		
58  		assertTrue(subConfig.getMap().size() == 3);
59  		assertTrue(subConfig.get("core").equals("core"));
60  		assertTrue(subConfig.get("services").equals("services"));
61  		assertTrue(subConfig.get("util").equals("util"));
62  	}
63  	
64  	/***/
65  	@Test
66  	public void testSpecificConfig() {
67  		HierarchicalGenericConfig config = getSpecificConfig();
68  		assertTrue(config.get("ch.elca.el4j").equals("EL4J"));
69  		assertTrue(config.get("ch.elca.el4j.tests.core").equals("core2"));
70  		assertTrue(config.getMap().size() == 9);
71  		
72  		HierarchicalGenericConfig subConfig
73  			= config.getSubConfig("ch.elca.el4j.default");
74  		assertTrue(subConfig.getMap().size() == 4);
75  		assertTrue(subConfig.get("a").equals("defaultA"));
76  		assertTrue(subConfig.get("b").equals("defaultB"));
77  		
78  		subConfig = config.getSubConfig("ch.elca.el4j.tests");
79  		
80  		assertTrue(subConfig.getMap().size() == 3);
81  		assertTrue(subConfig.get("core").equals("core2"));
82  		assertTrue(subConfig.get("services").equals("services"));
83  		assertTrue(subConfig.get("util").equals("util"));
84  	}
85  	
86  	/**
87  	 * @return    the default configuration
88  	 */
89  	protected abstract HierarchicalGenericConfig getDefaultConfig();
90  	
91  	/**
92  	 * @return    the specific configuration
93  	 */
94  	protected abstract HierarchicalGenericConfig getSpecificConfig();
95  }
96  
97  //Checkstyle: EmptyBlock on
98  //Checkstyle: MagicNumber on