KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > TestBackedList


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: TestBackedList.java,v 1.2 2003/11/02 18:31:28 per_nyfelt Exp $
8  */

9
10 package test.dom4j;
11
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.textui.TestRunner;
15 import org.dom4j.Element;
16 import org.dom4j.NodeFactory;
17 import org.dom4j.io.XMLWriter;
18 import org.ozoneDB.xml.dom4j.o3impl.OzoneDocumentFactoryImpl;
19
20 import java.util.List JavaDoc;
21
22 /** A test harness to test the backed list feature of DOM4J
23   *
24   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
25   * @version $Revision: 1.2 $
26   */

27 public class TestBackedList extends AbstractTestCase {
28
29     public static void main( String JavaDoc[] args ) {
30         TestRunner.run( suite() );
31     }
32
33     public static Test suite() {
34         return new TestSuite( TestBackedList.class );
35     }
36
37     public TestBackedList(String JavaDoc name) {
38         super(name);
39     }
40
41     // Test case(s)
42
//-------------------------------------------------------------------------
43
public void testXPaths() throws Exception JavaDoc {
44         Element element = (Element) document.selectSingleNode( "/root" );
45         mutate(element);
46         element = (Element) document.selectSingleNode( "//author" );
47         mutate(element);
48     }
49
50     // Implementation methods
51
//-------------------------------------------------------------------------
52
protected void mutate(Element element) throws Exception JavaDoc {
53         NodeFactory factory = OzoneDocumentFactoryImpl.getInstance(db());
54
55         List JavaDoc list = element.elements();
56         list.add(factory.createElement("last" ));
57         list.add(0, factory.createElement("first" ));
58
59         List JavaDoc list2 = element.elements();
60
61         assertTrue( "Both lists should contain same number of elements", list.size() == list2.size() );
62
63         XMLWriter writer = new XMLWriter( System.out );
64
65         log( "Element content is now: " + element.content() );
66         writer.write( element );
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: TestBackedList.java,v 1.2 2003/11/02 18:31:28 per_nyfelt Exp $
117  */

118
Popular Tags