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