KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestBadPath.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.XPath;
16 import test.dom4j.AbstractTestCase;
17
18 /** Tests bad XPath expressions
19   *
20   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
21   * @version $Revision: 1.1 $
22   */

23 public class TestBadPath extends AbstractTestCase {
24
25     String JavaDoc[] paths = {
26         "+",
27         "/foo/bar/",
28     };
29
30     public static void main( String JavaDoc[] args ) {
31         TestRunner.run( suite() );
32     }
33
34     public static Test suite() {
35         return new TestSuite( TestBadPath.class );
36     }
37
38     public TestBadPath(String JavaDoc name) {
39         super(name);
40     }
41
42     // Test case(s)
43
//-------------------------------------------------------------------------
44
public void testBadPaths() throws Exception JavaDoc {
45         for ( int i = 0, size = paths.length; i < size; i++ ) {
46             String JavaDoc path = paths[i];
47             testBadPath( path );
48         }
49     }
50
51     protected void testBadPath(String JavaDoc path) throws Exception JavaDoc {
52         try {
53             document.selectObject( path );
54
55             fail( "Should have thrown exception for: " + path );
56         }
57         catch (Exception JavaDoc e) {
58             log( "Successfully caught: " + e );
59         }
60         try {
61             XPath xpath = document.createXPath( path );
62
63             fail( "Should have thrown exception for: " + path );
64         }
65         catch (Exception JavaDoc e) {
66             log( "Successfully caught: " + e );
67         }
68     }
69 }
70
71
72
73
74 /*
75  * Redistribution and use of this software and associated documentation
76  * ("Software"), with or without modification, are permitted provided
77  * that the following conditions are met:
78  *
79  * 1. Redistributions of source code must retain copyright
80  * statements and notices. Redistributions must also contain a
81  * copy of this document.
82  *
83  * 2. Redistributions in binary form must reproduce the
84  * above copyright notice, this list of conditions and the
85  * following disclaimer in the documentation and/or other
86  * materials provided with the distribution.
87  *
88  * 3. The name "DOM4J" must not be used to endorse or promote
89  * products derived from this Software without prior written
90  * permission of MetaStuff, Ltd. For written permission,
91  * please contact dom4j-info@metastuff.com.
92  *
93  * 4. Products derived from this Software may not be called "DOM4J"
94  * nor may "DOM4J" appear in their names without prior written
95  * permission of MetaStuff, Ltd. DOM4J is a registered
96  * trademark of MetaStuff, Ltd.
97  *
98  * 5. Due credit should be given to the DOM4J Project
99  * (http://dom4j.org/).
100  *
101  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
102  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
103  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
104  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
105  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
106  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
107  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
108  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
109  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
110  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
111  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
112  * OF THE POSSIBILITY OF SUCH DAMAGE.
113  *
114  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
115  *
116  * $Id: TestBadPath.java,v 1.1 2003/07/07 10:30:30 per_nyfelt Exp $
117  */

118
Popular Tags