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