1 19 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 [] argv) { 40 BaseTest o = new TestFind(); 41 if (argv.length > 0) 42 o.setDocumentDir(argv[0]); 43 try { 44 o.run(); 45 } catch (Exception e) { 46 e.printStackTrace(); 47 System.exit(1); 48 } 49 System.exit(0); 50 } 51 52 53 public void run() 54 throws Exception 55 { 56 Book b1, b2, b3; 57 58 this.readDocument(); 59 out("creating the bean graph"); 60 Book book = Book.createGraph(doc); 61 62 out("bean graph created"); 65 66 setTest("Test findProperty -"); 70 String []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 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 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 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 164 } 165 } 166 167 168 | Popular Tags |