KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > TestParseText


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: TestParseText.java,v 1.4 2003/04/07 22:24:19 jstrachan 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.ozoneDB.xml.dom4j.O3DocumentHelper;
17
18 /** Tests the {@link org.ozoneDB.xml.dom4j.O3DocumentHelper#parseText(String)} method.
19   *
20   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
21   * @version $Revision: 1.4 $
22   */

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

116
Popular Tags