KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > xpath > TestAttribute


1 /*
2  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  *
7  * $Id: TestAttribute.java,v 1.1 2003/07/07 10:30:30 per_nyfelt Exp $
8  */

9
10 package test.dom4j.xpath;
11
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.textui.TestRunner;
15 import org.dom4j.Attribute;
16 import org.dom4j.XPath;
17 import org.ozoneDB.xml.dom4j.O3DocumentHelper;
18 import test.dom4j.AbstractTestCase;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 /** Test harness for the attribute axis
24   *
25   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
26   * @version $Revision: 1.1 $
27   */

28 public class TestAttribute extends AbstractTestCase {
29
30     protected static boolean VERBOSE = false;
31
32     protected static String JavaDoc[] paths = {
33         "attribute::*",
34         "/root/author/attribute::*",
35         "//attribute::*",
36         "@name"
37     };
38
39
40     public static void main( String JavaDoc[] args ) {
41         TestRunner.run( suite() );
42     }
43
44     public static Test suite() {
45         return new TestSuite( TestAttribute.class );
46     }
47
48     public TestAttribute(String JavaDoc name) {
49         super(name);
50     }
51
52     // Test case(s)
53
//-------------------------------------------------------------------------
54
public void testXPaths() throws Exception JavaDoc {
55         int size = paths.length;
56         for ( int i = 0; i < size; i++ ) {
57             testXPath( paths[i] );
58         }
59     }
60
61     // Implementation methods
62
//-------------------------------------------------------------------------
63
protected void testXPath(String JavaDoc xpathText) {
64         XPath xpath = O3DocumentHelper.createXPath(xpathText);
65         List JavaDoc list = xpath.selectNodes( document );
66
67         log( "Searched path: " + xpathText + " found: " + list.size() + " result(s)" );
68
69         if ( VERBOSE ) {
70             log( "xpath: " + xpath );
71             log( "results: " + list );
72         }
73
74         for ( Iterator JavaDoc iter = list.iterator(); iter.hasNext(); ) {
75             Object JavaDoc object = iter.next();
76
77             log( "Found Result: " + object );
78
79             assertTrue( "Results should be Attribute objects", object instanceof Attribute );
80
81             Attribute attribute = (Attribute) object;
82
83             assertTrue( "Results should support the parent relationship", attribute.supportsParent() );
84             assertTrue( "Results should contain reference to the parent element", attribute.getParent() != null );
85             assertTrue( "Results should contain reference to the owning document", attribute.getDocument() != null );
86         }
87     }
88 }
89
90
91
92
93 /*
94  * Redistribution and use of this software and associated documentation
95  * ("Software"), with or without modification, are permitted provided
96  * that the following conditions are met:
97  *
98  * 1. Redistributions of source code must retain copyright
99  * statements and notices. Redistributions must also contain a
100  * copy of this document.
101  *
102  * 2. Redistributions in binary form must reproduce the
103  * above copyright notice, this list of conditions and the
104  * following disclaimer in the documentation and/or other
105  * materials provided with the distribution.
106  *
107  * 3. The name "DOM4J" must not be used to endorse or promote
108  * products derived from this Software without prior written
109  * permission of MetaStuff, Ltd. For written permission,
110  * please contact dom4j-info@metastuff.com.
111  *
112  * 4. Products derived from this Software may not be called "DOM4J"
113  * nor may "DOM4J" appear in their names without prior written
114  * permission of MetaStuff, Ltd. DOM4J is a registered
115  * trademark of MetaStuff, Ltd.
116  *
117  * 5. Due credit should be given to the DOM4J Project
118  * (http://dom4j.org/).
119  *
120  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
121  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
122  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
123  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
124  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
125  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
126  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
127  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
128  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
129  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
130  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
131  * OF THE POSSIBILITY OF SUCH DAMAGE.
132  *
133  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
134  *
135  * $Id: TestAttribute.java,v 1.1 2003/07/07 10:30:30 per_nyfelt Exp $
136  */

137
Popular Tags