KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > TestAddAttribute


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  */

8
9 package test.dom4j;
10
11 import junit.framework.Test;
12 import junit.framework.TestSuite;
13 import junit.textui.TestRunner;
14 import org.dom4j.Element;
15 import org.dom4j.Node;
16
17 /** A test harness to test the addAttribute() methods on attributes
18   *
19   * @author <a HREF="mailto:maartenc@users.sourceforge.net">Maarten Coene</a>
20   */

21 public class TestAddAttribute extends AbstractTestCase {
22
23     public static void main( String JavaDoc[] args ) {
24         TestRunner.run( suite() );
25     }
26
27     public static Test suite() {
28         return new TestSuite( TestAddAttribute.class );
29     }
30
31     public TestAddAttribute(String JavaDoc name) {
32         super(name);
33     }
34
35     // Test case(s)
36
//-------------------------------------------------------------------------
37
public void testAddAttributeNormalValue() throws Exception JavaDoc {
38         String JavaDoc testAttributeName = "testAtt";
39         String JavaDoc testAttributeValue = "testValue";
40
41         Node authorNode = document.selectSingleNode("//root/author[1]");
42
43         assertTrue(authorNode instanceof Element);
44
45         Element authorEl = (Element) authorNode;
46         authorEl.addAttribute(testAttributeName, testAttributeValue);
47
48         assertEquals(3, authorEl.attributeCount());
49         assertEquals(testAttributeValue, authorEl.attributeValue(testAttributeName));
50     }
51
52     public void testAddAttributeNullValue() throws Exception JavaDoc {
53         String JavaDoc testAttributeName = "location";
54         String JavaDoc testAttributeValue = null;
55
56         Node authorNode = document.selectSingleNode("//root/author[1]");
57
58         assertTrue(authorNode instanceof Element);
59
60         Element authorEl = (Element) authorNode;
61         authorEl.addAttribute(testAttributeName, testAttributeValue);
62
63         assertEquals(1, authorEl.attributeCount());
64         assertNull(authorEl.attributeValue(testAttributeName));
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: TestAddAttribute.java,v 1.1 2003/07/07 10:30:29 per_nyfelt Exp $
115  */

116
Popular Tags