KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestFind


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * TestFind - test the find feature
21  *
22  * Search property value, attribute value and any value.
23  *
24  */

25
26 import java.io.*;
27 import java.util.*;
28 import org.w3c.dom.*;
29
30 import org.netbeans.modules.schema2beans.*;
31
32 import java.beans.*;
33
34 import book.*;
35
36
37 public class TestFind extends BaseTest
38 {
39     public static void main(String JavaDoc[] argv) {
40         BaseTest o = new TestFind();
41         if (argv.length > 0)
42             o.setDocumentDir(argv[0]);
43         try {
44             o.run();
45         } catch (Exception JavaDoc e) {
46             e.printStackTrace();
47             System.exit(1);
48         }
49         System.exit(0);
50     }
51     
52     
53     public void run()
54         throws Exception JavaDoc
55     {
56         Book b1, b2, b3;
57
58         this.readDocument();
59         out("creating the bean graph");
60         Book book = Book.createGraph(doc);
61
62         //GraphManager.debug(true);
63
// Check that we can read the graph an it is complete
64
out("bean graph created");
65
66         //
67
// Find property value
68
//
69
setTest("Test findProperty -");
70         String JavaDoc []r = book.findPropertyValue("Word", "Good book");
71         check(r.length == 1, "found element");
72         if (r.length > 0)
73             out(r[0]);
74         r = book.findPropertyValue("Line", "31");
75         check(r.length == 2, "found elements");
76         if (r.length > 1)
77         {
78             out(r[0]);
79             out(r[1]);
80         }
81         
82         r = book.findPropertyValue("Page", "1234");
83         check(r.length == 0, "not found element");
84
85         //
86
// Find property and/or attribute value
87
//
88
setTest("Test findValue -");
89         r = book.findValue("31");
90         check(r.length == 3, "found elements");
91         if (r.length > 2)
92         {
93             out(r[0]);
94             out(r[1]);
95             out(r[2]);
96         }
97
98         r = book.findValue("E-Tool");
99         check(r.length == 1, "found element");
100         if (r.length > 0)
101         {
102             out(r[0]);
103         }
104
105         r = book.findValue("this is not in the XML document");
106         check(r.length == 0, "not found element");
107
108         r = book.findValue("yes");
109         check(r.length == 2, "found elements");
110         if (r.length > 1)
111         {
112             out(r[0]);
113             out(r[1]);
114         }
115
116         r = book.findValue("no");
117         check(r.length == 1, "found element");
118         if (r.length > 0)
119         {
120             out(r[0]);
121         }
122         
123         //
124
// Find attribute value
125
//
126
setTest("Test findAttributeValue -");
127         r = book.findAttributeValue("Color", "red");
128         check(r.length == 1, "found element");
129         if (r.length > 0)
130         {
131             out(r[0]);
132         }
133
134         // try with the dtd name (color instead of Color)
135
r = book.findAttributeValue("color", "blue");
136         check(r.length == 1, "found element");
137         if (r.length > 0)
138         {
139             out(r[0]);
140         }
141
142         r = book.findAttributeValue("Color", "black");
143         check(r.length == 0, "not found element");
144         
145         r = book.findAttributeValue("freq", "1");
146         check(r.length == 2, "found elements");
147         if (r.length > 1)
148         {
149             out(r[0]);
150             out(r[1]);
151         }
152         
153         r = book.findAttributeValue("Good", "no");
154         check(r.length == 1, "found element");
155         if (r.length > 0)
156         {
157             out(r[0]);
158         }
159
160         //
161
// Try to remove an element by value the by reference
162
//
163

164     }
165 }
166
167
168
Popular Tags