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

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/configuration/tree/xpath/TestXPathExpressionEngineInConfig.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.tree.xpath;
18
 
 
19
 
import junit.framework.TestCase;
20
 
 
21
 
import org.apache.commons.configuration.XMLConfiguration;
22
 
 
23
 
/**
24
 
 * A test class for XPathExpressionEngine that tests the engine integrated into
25
 
 * a hierarchical configuration.
26
 
 *
27
 
 * @author <a
28
 
 *         href="http://commons.apache.org/configuration/team-list.html">Commons
29
 
 *         Configuration team</a>
30
 
 * @version $Id: TestXPathExpressionEngineInConfig.java 1152343 2011-07-29 19:23:09Z oheger $
31
 
 */
32
 
public class TestXPathExpressionEngineInConfig extends TestCase
33
 
{
34
 
    /** Constant for a test key. */
35
 
    private static final String KEY = "test/expression/xpath";
36
 
 
37
 
    /** Constant for a value for test properties. */
38
 
    private static final String VALUE = "success";
39
 
 
40
 
    /** The test configuration. */
41
 
    private XMLConfiguration config;
42
 
 
43
 
    protected void setUp() throws Exception
44
 
    {
45
 
        super.setUp();
46
 
        config = new XMLConfiguration();
47
 
        config.setExpressionEngine(new XPathExpressionEngine());
48
 
    }
49
 
 
50
 
    /**
51
 
     * Tests whether an already existing property can be changed using
52
 
     * setProperty().
53
 
     */
54
 
    public void testSetPropertyExisting()
55
 
    {
56
 
        config.addProperty(" " + KEY, "failure");
57
 
        config.setProperty(KEY, VALUE);
58
 
        assertEquals("Value not changed", VALUE, config.getString(KEY));
59
 
    }
60
 
 
61
 
    /**
62
 
     * Tests setProperty() if the specified path partly exists.
63
 
     */
64
 
    public void testSetPropertyPartlyExisting()
65
 
    {
66
 
        final String testKey = KEY + "/sub";
67
 
        config.addProperty(" " + KEY, "test");
68
 
        config.setProperty(testKey, VALUE);
69
 
        assertEquals("Value not set", VALUE, config.getString(testKey));
70
 
    }
71
 
 
72
 
    /**
73
 
     * Tests whether setProperty() can be used to add a new attribute.
74
 
     */
75
 
    public void testSetPropertyNewAttribute()
76
 
    {
77
 
        final String keyAttr = KEY + "/@attr";
78
 
        config.addProperty(" " + KEY, "test");
79
 
        config.setProperty(keyAttr, VALUE);
80
 
        assertEquals("Value not set", VALUE, config.getString(keyAttr));
81
 
    }
82
 
 
83
 
    /**
84
 
     * Tests whether setProperty() can be used to create a completely new key.
85
 
     */
86
 
    public void testSetPropertyNewKey()
87
 
    {
88
 
        config.setProperty(KEY, VALUE);
89
 
        assertEquals("Value not set", VALUE, config.getString(KEY));
90
 
    }
91
 
 
92
 
    /**
93
 
     * Tests whether addProperty() can be used to create more complex
94
 
     * hierarchical structures.
95
 
     */
96
 
    public void testAddPropertyComplexStructures()
97
 
    {
98
 
        config.addProperty("tables/table/name", "tasks");
99
 
        config.addProperty("tables/table[last()]/@type", "system");
100
 
        config.addProperty("tables/table[last()]/fields/field/name", "taskid");
101
 
        config.addProperty("tables/table[last()]/fields/field[last()]/@type",
102
 
                "int");
103
 
        config.addProperty("tables table/name", "documents");
104
 
        assertEquals("Wrong table 1", "tasks",
105
 
                config.getString("tables/table[1]/name"));
106
 
        assertEquals("Wrong table 2", "documents",
107
 
                config.getString("tables/table[2]/name"));
108
 
        assertEquals("Wrong field type", "int",
109
 
                config.getString("tables/table[1]/fields/field[1]/@type"));
110
 
    }
111
 
}