2
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
4
* This software is open source.
5
* See the bottom of this file for the licence.
8
package org.dom4j.xpath;
10
import junit.textui.TestRunner;
12
import java.util.List;
14
import org.dom4j.AbstractTestCase;
15
import org.dom4j.DocumentHelper;
16
import org.dom4j.Node;
17
import org.dom4j.XPath;
19
import org.jaxen.SimpleVariableContext;
22
* Test harness for the valueOf() function
24
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
25
* @version $Revision: 1.4 $
27
public class VariableTest extends AbstractTestCase {
28
// TODO: uncomment these if jaxen bug is fixed
29
// http://jira.codehaus.org/browse/JAXEN-73
30
protected static String[] paths = {
35
// "$root/author[1]/@name",
39
private SimpleVariableContext variableContext = new SimpleVariableContext();
41
private Node rootNode;
43
private Node authorNode;
45
public static void main(String[] args) {
46
TestRunner.run(VariableTest.class);
50
// -------------------------------------------------------------------------
51
public void testXPaths() throws Exception {
52
int size = paths.length;
54
for (int i = 0; i < size; i++) {
59
protected void testXPath(String xpathText) {
60
XPath xpath = createXPath(xpathText);
61
List list = xpath.selectNodes(document);
63
log("Searched path: " + xpathText + " found: " + list.size()
66
assertTrue("Results should not contain the root node", !list
70
protected XPath createXPath(String xpath) {
71
return DocumentHelper.createXPath(xpath, variableContext);
74
protected void setUp() throws Exception {
77
rootNode = document.selectSingleNode("/root");
78
authorNode = document.selectSingleNode("/root/author[1]");
80
variableContext.setVariableValue("root", rootNode);
81
variableContext.setVariableValue("author", authorNode);
86
* Redistribution and use of this software and associated documentation
87
* ("Software"), with or without modification, are permitted provided that the
88
* following conditions are met:
90
* 1. Redistributions of source code must retain copyright statements and
91
* notices. Redistributions must also contain a copy of this document.
93
* 2. Redistributions in binary form must reproduce the above copyright notice,
94
* this list of conditions and the following disclaimer in the documentation
95
* and/or other materials provided with the distribution.
97
* 3. The name "DOM4J" must not be used to endorse or promote products derived
98
* from this Software without prior written permission of MetaStuff, Ltd. For
99
* written permission, please contact dom4j-info@metastuff.com.
101
* 4. Products derived from this Software may not be called "DOM4J" nor may
102
* "DOM4J" appear in their names without prior written permission of MetaStuff,
103
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
105
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
107
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
108
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
109
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
110
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
111
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
112
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
113
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
114
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
115
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
116
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
117
* POSSIBILITY OF SUCH DAMAGE.
119
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.