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  import org.springframework.context.ApplicationContext;
23  
24  import ch.elca.el4j.core.context.ModuleApplicationContext;
25  import ch.elca.el4j.util.config.HierarchicalGenericConfig;
26  
27  //Checkstyle: MagicNumber off
28  //Checkstyle: EmptyBlock off
29  
30  /**
31   * This class tests {@link HierarchicalGenericConfigSpringTest}
32   * using pure Java (no Spring).
33   *
34   * @svnLink $Revision: 3875 $;$Date: 2009-08-04 14:35:53 +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/HierarchicalGenericConfigSpringTest.java $
35   *
36   * @author Stefan Wismer (SWI)
37   */
38  public class HierarchicalGenericConfigSpringTest
39  	extends AbstractHierarchicalGenericConfigTest {
40  	
41  	/** The application context. */
42  	final ApplicationContext m_appContext;
43  
44  	/**
45  	 * Default constructor.
46  	 */
47  	public HierarchicalGenericConfigSpringTest() {
48  		m_appContext = new ModuleApplicationContext(
49  			"classpath:scenarios/util/config/hierarchicalGenericConfig.xml",
50  			false);
51  	}
52  	
53  	/** {@inheritDoc} */
54  	@Override
55  	protected HierarchicalGenericConfig getDefaultConfig() {
56  		return (HierarchicalGenericConfig)
57  			m_appContext.getBean("DefaultConfig");
58  	}
59  	
60  	/** {@inheritDoc} */
61  	@Override
62  	protected HierarchicalGenericConfig getSpecificConfig() {
63  		return (HierarchicalGenericConfig)
64  			m_appContext.getBean("SpecificConfig");
65  	}
66  	
67  	/***/
68  	@Test
69  	public void testMultipleParents() {
70  		HierarchicalGenericConfig config = (HierarchicalGenericConfig)
71  			m_appContext.getBean("configABCD");
72  		
73  		HierarchicalGenericConfig subConfig
74  			= config.getSubConfig("ch.elca.el4j.default");
75  		assertTrue(subConfig.getMap().size() == 4);
76  		assertTrue(subConfig.get("a").equals("defaultA"));
77  		assertTrue(subConfig.get("b").equals("defaultB2"));
78  		assertTrue(subConfig.get("c.d").equals("defaultCD"));
79  		assertTrue(subConfig.get("c.e").equals("defaultCE2"));
80  	}
81  }
82  
83  //Checkstyle: EmptyBlock on
84  //Checkstyle: MagicNumber on