01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: /** Constant for the first test configuration. */
37: static File CONF1 = new File("conf/testcombine1.xml");
38:
39: /** Constant for the second test configuration. */
40: static File CONF2 = new File("conf/testcombine2.xml");
41:
42: /** The combiner to be tested. */
43: protected NodeCombiner combiner;
44:
45: protected void setUp() throws Exception {
46: super .setUp();
47: combiner = createCombiner();
48: }
49:
50: /**
51: * Creates the combiner to be tested. This method is called by
52: * <code>setUp()</code>. It must be implemented in concrete sub classes.
53: *
54: * @return the combiner to be tested
55: */
56: protected abstract NodeCombiner createCombiner();
57:
58: /**
59: * Constructs a union configuration based on the source configurations.
60: *
61: * @return the union configuration
62: * @throws ConfigurationException if an error occurs
63: */
64: protected HierarchicalConfiguration createCombinedConfiguration()
65: throws ConfigurationException {
66: XMLConfiguration conf1 = new XMLConfiguration(CONF1);
67: XMLConfiguration conf2 = new XMLConfiguration(CONF2);
68: ConfigurationNode cn = combiner.combine(conf1.getRootNode(),
69: conf2.getRootNode());
70:
71: HierarchicalConfiguration result = new HierarchicalConfiguration();
72: result.setRootNode(cn);
73:
74: return result;
75: }
76:
77: /**
78: * Tests a newly created combiner.
79: */
80: public void testInit() {
81: assertTrue("Combiner has list nodes", combiner.getListNodes()
82: .isEmpty());
83: assertFalse("Node is list node", combiner
84: .isListNode(new DefaultConfigurationNode("test")));
85: }
86:
87: }
|