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