KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > data > DataElementTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.data;
11
12 import org.jgap.*;
13
14 import junit.framework.*;
15
16 /**
17  * Tests for DataElement class
18  *
19  * @author Klaus Meffert
20  * @since 2.6
21  */

22 public class DataElementTest
23     extends JGAPTestCase {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.2 $";
26
27   public static Test suite() {
28     TestSuite suite = new TestSuite(DataElementTest.class);
29     return suite;
30   }
31
32   /**
33    * @throws Exception
34    * @author Klaus Meffert
35    * @since 2.6
36    */

37   public void testAppendChild_0()
38       throws Exception JavaDoc {
39     DataElement el = new DataElement("xyz");
40     DataElement child = new DataElement("tag1");
41     el.appendChild(child);
42     assertEquals(1, el.getChildNodes().getLength());
43     assertEquals(child, el.getChildNodes().item(0));
44   }
45
46   /**
47    * @throws Exception
48    * @author Klaus Meffert
49    * @since 2.6
50    */

51   public void testGetElementsByTagName_0()
52       throws Exception JavaDoc {
53     DataElement el = new DataElement("xyz");
54     assertEquals("xyz", el.getTagName());
55     IDataElementList list = el.getElementsByTagName("myTag");
56     assertEquals(0, list.getLength());
57     DataElement child = new DataElement("tag1");
58     el.appendChild(child);
59     list = el.getElementsByTagName("myTag");
60     assertEquals(0, list.getLength());
61     DataElement child2 = new DataElement("myTag");
62     el.appendChild(child2);
63     DataElement child3 = new DataElement("tag3");
64     el.appendChild(child3);
65     list = el.getElementsByTagName("myTag");
66     assertEquals(1, list.getLength());
67   }
68
69   /**
70    * @throws Exception
71    * @author Klaus Meffert
72    * @since 2.6
73    */

74   public void testGetNodeType_0()
75       throws Exception JavaDoc {
76     DataElement el = new DataElement("xyz");
77     assertEquals(1, el.getNodeType());
78     assertNull(el.getNodeValue());
79   }
80
81   /**
82    * @throws Exception
83    * @author Klaus Meffert
84    * @since 2.6
85    */

86   public void testAttributes_0()
87       throws Exception JavaDoc {
88     DataElement el = new DataElement("xyz");
89     assertNull(el.getNodeValue());
90     assertEquals(0, el.getAttributes().size());
91     el.setAttribute("att1", "val1");
92     assertEquals(1, el.getAttributes().size());
93     assertEquals("val1", el.getAttributes().get("att1"));
94     el.setAttribute("att2", "val2");
95     assertEquals(2, el.getAttributes().size());
96     assertEquals("val2", el.getAttributes().get("att2"));
97   }
98 }
99
Popular Tags