~ubuntu-branches/ubuntu/saucy/commons-configuration/saucy

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-07-01 16:29:44 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130701162944-98waq5gogha5gpn1
Tags: 1.9-1
* New upstream release
* debian/control:
  - Updated Standards-Version to 3.9.4 (no changes)
  - Use canonical URLs for the Vcs-* fields
  - Added new build dependencies (libjavacc-maven-plugin-java, junit4)
  - Upgraded the dependency on the Servlet API (2.5 -> 3.0)
  - Removed the dependency on the Activation Framework (glassfish-activation)
  - Replaced the dependency on glassfish-mail with libgnumail-java
  - Removed the unused dependencies:
    liblog4j1.2-java-doc, libmaven-assembly-plugin-java
  - Replaced the dependency on libcommons-jexl-java by libcommons-jexl2-java
* debian/watch: Changed to point the official Apache distribution server
* Removed the obsolete file debian/ant.properties
* Installed the upstream changelog in the binary packages
* Added the report plugins to maven.ignoreRules
* Added the classpath attribute to the jar manifest

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     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;
18
 
 
19
 
import java.io.File;
20
 
import java.util.ArrayList;
21
 
import java.util.HashSet;
22
 
import java.util.Iterator;
23
 
import java.util.List;
24
 
import java.util.NoSuchElementException;
25
 
import java.util.Set;
26
 
 
27
 
import junit.framework.TestCase;
28
 
 
29
 
import org.apache.commons.collections.CollectionUtils;
30
 
import org.apache.commons.configuration.event.ConfigurationEvent;
31
 
import org.apache.commons.configuration.event.ConfigurationListener;
32
 
import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
33
 
import org.apache.commons.configuration.reloading.FileAlwaysReloadingStrategy;
34
 
import org.apache.commons.configuration.tree.ConfigurationNode;
35
 
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
36
 
import org.apache.commons.lang.text.StrLookup;
37
 
 
38
 
/**
39
 
 * Test case for SubnodeConfiguration.
40
 
 *
41
 
 * @author Oliver Heger
42
 
 * @version $Id: TestSubnodeConfiguration.java 757114 2009-03-22 00:55:25Z joehni $
43
 
 */
44
 
public class TestSubnodeConfiguration extends TestCase
45
 
{
46
 
    /** An array with names of tables (test data). */
47
 
    private static final String[] TABLE_NAMES =
48
 
    { "documents", "users" };
49
 
 
50
 
    /** An array with the fields of the test tables (test data). */
51
 
    private static final String[][] TABLE_FIELDS =
52
 
    {
53
 
    { "docid", "docname", "author", "dateOfCreation", "version", "size" },
54
 
    { "userid", "uname", "firstName", "lastName" } };
55
 
 
56
 
    /** Constant for a test output file.*/
57
 
    private static final File TEST_FILE = new File("target/test.xml");
58
 
 
59
 
    /** Constant for an updated table name.*/
60
 
    private static final String NEW_TABLE_NAME = "newTable";
61
 
 
62
 
    /** The parent configuration. */
63
 
    HierarchicalConfiguration parent;
64
 
 
65
 
    /** The subnode configuration to be tested. */
66
 
    SubnodeConfiguration config;
67
 
 
68
 
    /** Stores a counter for the created nodes. */
69
 
    int nodeCounter;
70
 
 
71
 
    protected void setUp() throws Exception
72
 
    {
73
 
        super.setUp();
74
 
        parent = setUpParentConfig();
75
 
        nodeCounter = 0;
76
 
    }
77
 
 
78
 
    protected void tearDown() throws Exception
79
 
    {
80
 
        // remove the test output file if necessary
81
 
        if (TEST_FILE.exists())
82
 
        {
83
 
            assertTrue("Could not remove test file", TEST_FILE.delete());
84
 
        }
85
 
    }
86
 
 
87
 
    /**
88
 
     * Tests creation of a subnode config.
89
 
     */
90
 
    public void testInitSubNodeConfig()
91
 
    {
92
 
        setUpSubnodeConfig();
93
 
        assertSame("Wrong root node in subnode", getSubnodeRoot(parent), config
94
 
                .getRoot());
95
 
        assertSame("Wrong parent config", parent, config.getParent());
96
 
    }
97
 
 
98
 
    /**
99
 
     * Tests constructing a subnode configuration with a null parent. This
100
 
     * should cause an exception.
101
 
     */
102
 
    public void testInitSubNodeConfigWithNullParent()
103
 
    {
104
 
        try
105
 
        {
106
 
            config = new SubnodeConfiguration(null, getSubnodeRoot(parent));
107
 
            fail("Could set a null parent config!");
108
 
        }
109
 
        catch (IllegalArgumentException iex)
110
 
        {
111
 
            // ok
112
 
        }
113
 
    }
114
 
 
115
 
    /**
116
 
     * Tests constructing a subnode configuration with a null root node. This
117
 
     * should cause an exception.
118
 
     */
119
 
    public void testInitSubNodeConfigWithNullNode()
120
 
    {
121
 
        try
122
 
        {
123
 
            config = new SubnodeConfiguration(parent, null);
124
 
            fail("Could set a null root node!");
125
 
        }
126
 
        catch (IllegalArgumentException iex)
127
 
        {
128
 
            // ok
129
 
        }
130
 
    }
131
 
 
132
 
    /**
133
 
     * Tests if properties of the sub node can be accessed.
134
 
     */
135
 
    public void testGetProperties()
136
 
    {
137
 
        setUpSubnodeConfig();
138
 
        assertEquals("Wrong table name", TABLE_NAMES[0], config
139
 
                .getString("name"));
140
 
        List fields = config.getList("fields.field.name");
141
 
        assertEquals("Wrong number of fields", TABLE_FIELDS[0].length, fields
142
 
                .size());
143
 
        for (int i = 0; i < TABLE_FIELDS[0].length; i++)
144
 
        {
145
 
            assertEquals("Wrong field at position " + i, TABLE_FIELDS[0][i],
146
 
                    fields.get(i));
147
 
        }
148
 
    }
149
 
 
150
 
    /**
151
 
     * Tests setting of properties in both the parent and the subnode
152
 
     * configuration and whether the changes are visible to each other.
153
 
     */
154
 
    public void testSetProperty()
155
 
    {
156
 
        setUpSubnodeConfig();
157
 
        config.setProperty(null, "testTable");
158
 
        config.setProperty("name", TABLE_NAMES[0] + "_tested");
159
 
        assertEquals("Root value was not set", "testTable", parent
160
 
                .getString("tables.table(0)"));
161
 
        assertEquals("Table name was not changed", TABLE_NAMES[0] + "_tested",
162
 
                parent.getString("tables.table(0).name"));
163
 
 
164
 
        parent.setProperty("tables.table(0).fields.field(1).name", "testField");
165
 
        assertEquals("Field name was not changed", "testField", config
166
 
                .getString("fields.field(1).name"));
167
 
    }
168
 
 
169
 
    /**
170
 
     * Tests adding of properties.
171
 
     */
172
 
    public void testAddProperty()
173
 
    {
174
 
        setUpSubnodeConfig();
175
 
        config.addProperty("[@table-type]", "test");
176
 
        assertEquals("parent.createNode() was not called", 1, nodeCounter);
177
 
        assertEquals("Attribute not set", "test", parent
178
 
                .getString("tables.table(0)[@table-type]"));
179
 
 
180
 
        parent.addProperty("tables.table(0).fields.field(-1).name", "newField");
181
 
        List fields = config.getList("fields.field.name");
182
 
        assertEquals("New field was not added", TABLE_FIELDS[0].length + 1,
183
 
                fields.size());
184
 
        assertEquals("Wrong last field", "newField", fields
185
 
                .get(fields.size() - 1));
186
 
    }
187
 
 
188
 
    /**
189
 
     * Tests listing the defined keys.
190
 
     */
191
 
    public void testGetKeys()
192
 
    {
193
 
        setUpSubnodeConfig();
194
 
        Set keys = new HashSet();
195
 
        CollectionUtils.addAll(keys, config.getKeys());
196
 
        assertEquals("Incorrect number of keys", 2, keys.size());
197
 
        assertTrue("Key 1 not contained", keys.contains("name"));
198
 
        assertTrue("Key 2 not contained", keys.contains("fields.field.name"));
199
 
    }
200
 
 
201
 
    /**
202
 
     * Tests setting the exception on missing flag. The subnode config obtains
203
 
     * this flag from its parent.
204
 
     */
205
 
    public void testSetThrowExceptionOnMissing()
206
 
    {
207
 
        parent.setThrowExceptionOnMissing(true);
208
 
        setUpSubnodeConfig();
209
 
        assertTrue("Exception flag not fetchted from parent", config
210
 
                .isThrowExceptionOnMissing());
211
 
        try
212
 
        {
213
 
            config.getString("non existing key");
214
 
            fail("Could fetch non existing key!");
215
 
        }
216
 
        catch (NoSuchElementException nex)
217
 
        {
218
 
            // ok
219
 
        }
220
 
 
221
 
        config.setThrowExceptionOnMissing(false);
222
 
        assertTrue("Exception flag reset on parent", parent
223
 
                .isThrowExceptionOnMissing());
224
 
    }
225
 
 
226
 
    /**
227
 
     * Tests handling of the delimiter parsing disabled flag. This is shared
228
 
     * with the parent, too.
229
 
     */
230
 
    public void testSetDelimiterParsingDisabled()
231
 
    {
232
 
        parent.setDelimiterParsingDisabled(true);
233
 
        setUpSubnodeConfig();
234
 
        parent.setDelimiterParsingDisabled(false);
235
 
        assertTrue("Delimiter parsing flag was not received from parent",
236
 
                config.isDelimiterParsingDisabled());
237
 
        config.addProperty("newProp", "test1,test2,test3");
238
 
        assertEquals("New property was splitted", "test1,test2,test3", parent
239
 
                .getString("tables.table(0).newProp"));
240
 
        parent.setDelimiterParsingDisabled(true);
241
 
        config.setDelimiterParsingDisabled(false);
242
 
        assertTrue("Delimiter parsing flag was reset on parent", parent
243
 
                .isDelimiterParsingDisabled());
244
 
    }
245
 
 
246
 
    /**
247
 
     * Tests manipulating the list delimiter. This piece of data is derived from
248
 
     * the parent.
249
 
     */
250
 
    public void testSetListDelimiter()
251
 
    {
252
 
        parent.setListDelimiter('/');
253
 
        setUpSubnodeConfig();
254
 
        parent.setListDelimiter(';');
255
 
        assertEquals("List delimiter not obtained from parent", '/', config
256
 
                .getListDelimiter());
257
 
        config.addProperty("newProp", "test1,test2/test3");
258
 
        assertEquals("List was incorrectly splitted", "test1,test2", parent
259
 
                .getString("tables.table(0).newProp"));
260
 
        config.setListDelimiter(',');
261
 
        assertEquals("List delimiter changed on parent", ';', parent
262
 
                .getListDelimiter());
263
 
    }
264
 
 
265
 
    /**
266
 
     * Tests changing the expression engine.
267
 
     */
268
 
    public void testSetExpressionEngine()
269
 
    {
270
 
        parent.setExpressionEngine(new XPathExpressionEngine());
271
 
        setUpSubnodeConfig();
272
 
        assertEquals("Wrong field name", TABLE_FIELDS[0][1], config
273
 
                .getString("fields/field[2]/name"));
274
 
        Set keys = new HashSet();
275
 
        CollectionUtils.addAll(keys, config.getKeys());
276
 
        assertEquals("Wrong number of keys", 2, keys.size());
277
 
        assertTrue("Key 1 not contained", keys.contains("name"));
278
 
        assertTrue("Key 2 not contained", keys.contains("fields/field/name"));
279
 
        config.setExpressionEngine(null);
280
 
        assertTrue("Expression engine reset on parent", parent
281
 
                .getExpressionEngine() instanceof XPathExpressionEngine);
282
 
    }
283
 
 
284
 
    /**
285
 
     * Tests the configurationAt() method.
286
 
     */
287
 
    public void testConfiguarationAt()
288
 
    {
289
 
        setUpSubnodeConfig();
290
 
        SubnodeConfiguration sub2 = (SubnodeConfiguration) config
291
 
                .configurationAt("fields.field(1)");
292
 
        assertEquals("Wrong value of property", TABLE_FIELDS[0][1], sub2
293
 
                .getString("name"));
294
 
        assertEquals("Wrong parent", config.getParent(), sub2.getParent());
295
 
    }
296
 
 
297
 
    /**
298
 
     * Tests interpolation features. The subnode config should use its parent
299
 
     * for interpolation.
300
 
     */
301
 
    public void testInterpolation()
302
 
    {
303
 
        parent.addProperty("tablespaces.tablespace.name", "default");
304
 
        parent.addProperty("tablespaces.tablespace(-1).name", "test");
305
 
        parent.addProperty("tables.table(0).tablespace",
306
 
                "${tablespaces.tablespace(0).name}");
307
 
        assertEquals("Wrong interpolated tablespace", "default", parent
308
 
                .getString("tables.table(0).tablespace"));
309
 
 
310
 
        setUpSubnodeConfig();
311
 
        assertEquals("Wrong interpolated tablespace in subnode", "default",
312
 
                config.getString("tablespace"));
313
 
    }
314
 
 
315
 
    /**
316
 
     * An additional test for interpolation when the configurationAt() method is
317
 
     * involved.
318
 
     */
319
 
    public void testInterpolationFromConfigurationAt()
320
 
    {
321
 
        parent.addProperty("base.dir", "/home/foo");
322
 
        parent.addProperty("test.absolute.dir.dir1", "${base.dir}/path1");
323
 
        parent.addProperty("test.absolute.dir.dir2", "${base.dir}/path2");
324
 
        parent.addProperty("test.absolute.dir.dir3", "${base.dir}/path3");
325
 
 
326
 
        Configuration sub = parent.configurationAt("test.absolute.dir");
327
 
        for (int i = 1; i < 4; i++)
328
 
        {
329
 
            assertEquals("Wrong interpolation in parent", "/home/foo/path" + i,
330
 
                    parent.getString("test.absolute.dir.dir" + i));
331
 
            assertEquals("Wrong interpolation in subnode",
332
 
                    "/home/foo/path" + i, sub.getString("dir" + i));
333
 
        }
334
 
    }
335
 
 
336
 
    /**
337
 
     * An additional test for interpolation when the configurationAt() method is
338
 
     * involved for a local interpolation.
339
 
     */
340
 
    public void testLocalInterpolationFromConfigurationAt()
341
 
    {
342
 
        parent.addProperty("base.dir", "/home/foo");
343
 
        parent.addProperty("test.absolute.dir.dir1", "${base.dir}/path1");
344
 
        parent.addProperty("test.absolute.dir.dir2", "${dir1}");
345
 
 
346
 
        Configuration sub = parent.configurationAt("test.absolute.dir");
347
 
        assertEquals("Wrong interpolation in subnode",
348
 
            "/home/foo/path1", sub.getString("dir1"));
349
 
        assertEquals("Wrong local interpolation in subnode",
350
 
            "/home/foo/path1", sub.getString("dir2"));
351
 
    }
352
 
 
353
 
    /**
354
 
     * Tests manipulating the interpolator.
355
 
     */
356
 
    public void testInterpolator()
357
 
    {
358
 
        parent.addProperty("tablespaces.tablespace.name", "default");
359
 
        parent.addProperty("tablespaces.tablespace(-1).name", "test");
360
 
 
361
 
        setUpSubnodeConfig();
362
 
        InterpolationTestHelper.testGetInterpolator(config);
363
 
    }
364
 
 
365
 
    public void testLocalLookupsInInterpolatorAreInherited() {
366
 
        parent.addProperty("tablespaces.tablespace.name", "default");
367
 
        parent.addProperty("tablespaces.tablespace(-1).name", "test");
368
 
        parent.addProperty("tables.table(0).var", "${brackets:x}");
369
 
        
370
 
        ConfigurationInterpolator interpolator = parent.getInterpolator();
371
 
        interpolator.registerLookup("brackets", new StrLookup(){
372
 
 
373
 
            public String lookup(String key) {
374
 
                return "(" + key +")";
375
 
            }
376
 
            
377
 
        });
378
 
        setUpSubnodeConfig();
379
 
        assertEquals("Local lookup was not inherited", "(x)", config.getString("var", ""));
380
 
    }
381
 
 
382
 
    /**
383
 
     * Tests a reload operation for the parent configuration when the subnode
384
 
     * configuration does not support reloads. Then the new value should not be
385
 
     * detected.
386
 
     */
387
 
    public void testParentReloadNotSupported() throws ConfigurationException
388
 
    {
389
 
        Configuration c = setUpReloadTest(false);
390
 
        assertEquals("Name changed in sub config", TABLE_NAMES[1], config
391
 
                .getString("name"));
392
 
        assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
393
 
                .getString("tables.table(1).name"));
394
 
    }
395
 
 
396
 
    /**
397
 
     * Tests a reload operation for the parent configuration when the subnode
398
 
     * configuration does support reloads. The new value should be returned.
399
 
     */
400
 
    public void testParentReloadSupported() throws ConfigurationException
401
 
    {
402
 
        Configuration c = setUpReloadTest(true);
403
 
        assertEquals("Name not changed in sub config", NEW_TABLE_NAME, config
404
 
                .getString("name"));
405
 
        assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
406
 
                .getString("tables.table(1).name"));
407
 
    }
408
 
 
409
 
    /**
410
 
     * Tests whether events are fired if a change of the parent is detected.
411
 
     */
412
 
    public void testParentReloadEvents() throws ConfigurationException
413
 
    {
414
 
        setUpReloadTest(true);
415
 
        ConfigurationListenerTestImpl l = new ConfigurationListenerTestImpl();
416
 
        config.addConfigurationListener(l);
417
 
        config.getString("name");
418
 
        assertEquals("Wrong number of events", 2, l.events.size());
419
 
        boolean before = true;
420
 
        for (Iterator it = l.events.iterator(); it.hasNext();)
421
 
        {
422
 
            ConfigurationEvent e = (ConfigurationEvent) it.next();
423
 
            assertEquals("Wrong configuration", config, e.getSource());
424
 
            assertEquals("Wrong event type",
425
 
                    HierarchicalConfiguration.EVENT_SUBNODE_CHANGED, e
426
 
                            .getType());
427
 
            assertNull("Got a property name", e.getPropertyName());
428
 
            assertNull("Got a property value", e.getPropertyValue());
429
 
            assertEquals("Wrong before flag", before, e.isBeforeUpdate());
430
 
            before = !before;
431
 
        }
432
 
    }
433
 
 
434
 
    /**
435
 
     * Tests a reload operation for the parent configuration when the subnode
436
 
     * configuration is aware of reloads, and the parent configuration is
437
 
     * accessed first. The new value should be returned.
438
 
     */
439
 
    public void testParentReloadSupportAccessParent()
440
 
            throws ConfigurationException
441
 
    {
442
 
        Configuration c = setUpReloadTest(true);
443
 
        assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
444
 
                .getString("tables.table(1).name"));
445
 
        assertEquals("Name not changed in sub config", NEW_TABLE_NAME, config
446
 
                .getString("name"));
447
 
    }
448
 
 
449
 
    /**
450
 
     * Tests whether reloads work with sub subnode configurations.
451
 
     */
452
 
    public void testParentReloadSubSubnode() throws ConfigurationException
453
 
    {
454
 
        setUpReloadTest(true);
455
 
        SubnodeConfiguration sub = config.configurationAt("fields", true);
456
 
        assertEquals("Wrong subnode key", "tables.table(1).fields", sub
457
 
                .getSubnodeKey());
458
 
        assertEquals("Changed field not detected", "newField", sub
459
 
                .getString("field(0).name"));
460
 
    }
461
 
 
462
 
    /**
463
 
     * Tests creating a sub sub config when the sub config is not aware of
464
 
     * changes. Then the sub sub config shouldn't be either.
465
 
     */
466
 
    public void testParentReloadSubSubnodeNoChangeSupport()
467
 
            throws ConfigurationException
468
 
    {
469
 
        setUpReloadTest(false);
470
 
        SubnodeConfiguration sub = config.configurationAt("fields", true);
471
 
        assertNull("Sub sub config is attached to parent", sub.getSubnodeKey());
472
 
        assertEquals("Changed field name returned", TABLE_FIELDS[1][0], sub
473
 
                .getString("field(0).name"));
474
 
    }
475
 
 
476
 
    /**
477
 
     * Prepares a test for a reload operation.
478
 
     *
479
 
     * @param supportReload a flag whether the subnode configuration should
480
 
     * support reload operations
481
 
     * @return the parent configuration that can be used for testing
482
 
     * @throws ConfigurationException if an error occurs
483
 
     */
484
 
    private XMLConfiguration setUpReloadTest(boolean supportReload)
485
 
            throws ConfigurationException
486
 
    {
487
 
        XMLConfiguration xmlConf = new XMLConfiguration(parent);
488
 
        xmlConf.setFile(TEST_FILE);
489
 
        xmlConf.save();
490
 
        config = xmlConf.configurationAt("tables.table(1)", supportReload);
491
 
        assertEquals("Wrong table name", TABLE_NAMES[1], config
492
 
                .getString("name"));
493
 
        xmlConf.setReloadingStrategy(new FileAlwaysReloadingStrategy());
494
 
        // Now change the configuration file
495
 
        XMLConfiguration confUpdate = new XMLConfiguration(TEST_FILE);
496
 
        confUpdate.setProperty("tables.table(1).name", NEW_TABLE_NAME);
497
 
        confUpdate.setProperty("tables.table(1).fields.field(0).name",
498
 
                "newField");
499
 
        confUpdate.save();
500
 
        return xmlConf;
501
 
    }
502
 
 
503
 
    /**
504
 
     * Tests a manipulation of the parent configuration that causes the subnode
505
 
     * configuration to become invalid. In this case the sub config should be
506
 
     * detached and keep its old values.
507
 
     */
508
 
    public void testParentChangeDetach()
509
 
    {
510
 
        final String key = "tables.table(1)";
511
 
        config = parent.configurationAt(key, true);
512
 
        assertEquals("Wrong subnode key", key, config.getSubnodeKey());
513
 
        assertEquals("Wrong table name", TABLE_NAMES[1], config
514
 
                .getString("name"));
515
 
        parent.clearTree(key);
516
 
        assertEquals("Wrong table name after change", TABLE_NAMES[1], config
517
 
                .getString("name"));
518
 
        assertNull("Sub config was not detached", config.getSubnodeKey());
519
 
    }
520
 
 
521
 
    /**
522
 
     * Tests detaching a subnode configuration when an exception is thrown
523
 
     * during reconstruction. This can happen e.g. if the expression engine is
524
 
     * changed for the parent.
525
 
     */
526
 
    public void testParentChangeDetatchException()
527
 
    {
528
 
        config = parent.configurationAt("tables.table(1)", true);
529
 
        parent.setExpressionEngine(new XPathExpressionEngine());
530
 
        assertEquals("Wrong name of table", TABLE_NAMES[1], config
531
 
                .getString("name"));
532
 
        assertNull("Sub config was not detached", config.getSubnodeKey());
533
 
    }
534
 
 
535
 
    /**
536
 
     * Initializes the parent configuration. This method creates the typical
537
 
     * structure of tables and fields nodes.
538
 
     *
539
 
     * @return the parent configuration
540
 
     */
541
 
    protected HierarchicalConfiguration setUpParentConfig()
542
 
    {
543
 
        HierarchicalConfiguration conf = new HierarchicalConfiguration()
544
 
        {
545
 
            // Provide a special implementation of createNode() to check
546
 
            // if it is called by the subnode config
547
 
            protected Node createNode(String name)
548
 
            {
549
 
                nodeCounter++;
550
 
                return super.createNode(name);
551
 
            }
552
 
        };
553
 
        for (int i = 0; i < TABLE_NAMES.length; i++)
554
 
        {
555
 
            conf.addProperty("tables.table(-1).name", TABLE_NAMES[i]);
556
 
            for (int j = 0; j < TABLE_FIELDS[i].length; j++)
557
 
            {
558
 
                conf.addProperty("tables.table.fields.field(-1).name",
559
 
                        TABLE_FIELDS[i][j]);
560
 
            }
561
 
        }
562
 
        return conf;
563
 
    }
564
 
 
565
 
    /**
566
 
     * Returns the root node for the subnode config. This method returns the
567
 
     * first table node.
568
 
     *
569
 
     * @param conf the parent config
570
 
     * @return the root node for the subnode config
571
 
     */
572
 
    protected ConfigurationNode getSubnodeRoot(HierarchicalConfiguration conf)
573
 
    {
574
 
        ConfigurationNode root = conf.getRoot();
575
 
        return root.getChild(0).getChild(0);
576
 
    }
577
 
 
578
 
    /**
579
 
     * Performs a standard initialization of the subnode config to test.
580
 
     */
581
 
    protected void setUpSubnodeConfig()
582
 
    {
583
 
        config = new SubnodeConfiguration(parent, getSubnodeRoot(parent));
584
 
    }
585
 
 
586
 
    /**
587
 
     * A specialized configuration listener for testing whether the expected
588
 
     * events are fired.
589
 
     */
590
 
    private static class ConfigurationListenerTestImpl implements ConfigurationListener
591
 
    {
592
 
        /** Stores the events received.*/
593
 
        final List events = new ArrayList();
594
 
 
595
 
        public void configurationChanged(ConfigurationEvent event)
596
 
        {
597
 
            events.add(event);
598
 
        }
599
 
    }
600
 
}