KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xdm > visitor > FindVisitorTest


1 /*
2  * FindVisitorTest.java
3  * JUnit based test
4  *
5  * Created on October 14, 2005, 1:39 PM
6  */

7
8 package org.netbeans.modules.xml.xdm.visitor;
9
10 import java.io.BufferedReader JavaDoc;
11 import java.io.InputStreamReader JavaDoc;
12 import junit.framework.*;
13 import org.netbeans.modules.xml.xdm.XDMModel;
14 import org.netbeans.modules.xml.xdm.nodes.*;
15 import org.netbeans.modules.xml.xdm.Util;
16
17 /**
18  *
19  * @author ajit
20  */

21 public class FindVisitorTest extends TestCase {
22     
23     public FindVisitorTest(String JavaDoc testName) {
24         super(testName);
25     }
26     
27     public static Test suite() {
28         TestSuite suite = new TestSuite(FindVisitorTest.class);
29         
30         return suite;
31     }
32     
33     public void testFind() {
34         
35         FindVisitor instance = new FindVisitor();
36
37         Document root = xmlModel.getDocument();
38
39         // try to find company
40
Element company = (Element)root.getChildNodes().item(0);
41         Node result = instance.find(root, company.getId());
42         assertEquals(company, result);
43
44         // try to find attribute
45
Element employee = (Element)company.getChildNodes().item(1);
46         Attribute attr = (Attribute)employee.getAttributes().item(0);
47         result = instance.find(root, attr.getId());
48         assertEquals(attr, result);
49
50         // try to find text
51
Text txt = (Text)employee.getChildNodes().item(0);
52         result = instance.find(root, txt.getId());
53         assertEquals(txt, result);
54     }
55     
56     protected void setUp() throws Exception JavaDoc {
57         xmlModel = Util.loadXDMModel("visitor/test.xml");
58         xmlModel.sync();
59     }
60     
61     private XDMModel xmlModel;
62 }
63
Popular Tags