1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.tree;
18
19 import java.io.File;
20
21 import org.apache.commons.configuration.ConfigurationException;
22 import org.apache.commons.configuration.HierarchicalConfiguration;
23 import org.apache.commons.configuration.XMLConfiguration;
24
25 import junit.framework.TestCase;
26
27 /***
28 * A base class for testing combiner implementations. This base class provides
29 * some functionality for loading the test configurations, which are to be
30 * combined. Concrete sub classes only need to create the correct combiner
31 * object.
32 *
33 * @version $Id: AbstractCombinerTest.java 439648 2006-09-02 20:42:10Z oheger $
34 */
35 public abstract class AbstractCombinerTest extends TestCase
36 {
37 /*** Constant for the first test configuration. */
38 static File CONF1 = new File("conf/testcombine1.xml");
39
40 /*** Constant for the second test configuration. */
41 static File CONF2 = new File("conf/testcombine2.xml");
42
43 /*** The combiner to be tested. */
44 protected NodeCombiner combiner;
45
46 protected void setUp() throws Exception
47 {
48 super.setUp();
49 combiner = createCombiner();
50 }
51
52 /***
53 * Creates the combiner to be tested. This method is called by
54 * <code>setUp()</code>. It must be implemented in concrete sub classes.
55 *
56 * @return the combiner to be tested
57 */
58 protected abstract NodeCombiner createCombiner();
59
60 /***
61 * Constructs a union configuration based on the source configurations.
62 *
63 * @return the union configuration
64 * @throws ConfigurationException if an error occurs
65 */
66 protected HierarchicalConfiguration createCombinedConfiguration()
67 throws ConfigurationException
68 {
69 XMLConfiguration conf1 = new XMLConfiguration(CONF1);
70 XMLConfiguration conf2 = new XMLConfiguration(CONF2);
71 ConfigurationNode cn = combiner.combine(conf1.getRootNode(), conf2
72 .getRootNode());
73
74 HierarchicalConfiguration result = new HierarchicalConfiguration();
75 result.setRootNode(cn);
76
77 return result;
78 }
79
80 /***
81 * Tests a newly created combiner.
82 */
83 public void testInit()
84 {
85 assertTrue("Combiner has list nodes", combiner.getListNodes().isEmpty());
86 assertFalse("Node is list node", combiner
87 .isListNode(new DefaultConfigurationNode("test")));
88 }
89
90 }