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