KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tax > AbstractFactoryTest


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  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.tax;
20
21 import org.netbeans.tax.TreeElementDecl.ContentType;
22 import org.netbeans.tests.xml.XTest;
23 import org.openide.util.Utilities;
24
25 abstract class AbstractFactoryTest extends XTest {
26     final private static String JavaDoc NOT_EXCEPTION = "The InvalidArgumetException wasn't throwed ";
27
28     public AbstractFactoryTest(String JavaDoc testName) {
29         super(testName);
30     }
31
32
33     //--------------------------------------------------------------------------
34

35
36     static TreeAttlistDecl createAttlistDecl(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
37         TreeAttlistDecl node = new TreeAttlistDecl(string);
38         
39         assertEquals(node, view);
40         cloneNodeTest(node, view);
41         return node;
42     }
43     
44     static void createAttlistDeclInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
45         try {
46             new TreeAttlistDecl(string);
47             // Fail if previous line doesn't trhow exception.
48
fail(NOT_EXCEPTION + "from: new TreeAttlistDecl(string)");
49         } catch (InvalidArgumentException e) {
50             // OK
51
}
52     }
53     
54     
55     //--------------------------------------------------------------------------
56

57     
58     static TreeAttribute createAttribute(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, boolean boolean_val, String JavaDoc view) throws Exception JavaDoc {
59         TreeAttribute node = new TreeAttribute(string, string1, boolean_val);
60         
61         assertEquals(node, view);
62         cloneNodeTest(node, view);
63         return node;
64     }
65     
66     static void createAttributeInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, boolean boolean_val) throws Exception JavaDoc {
67         try {
68             new TreeAttribute(string, string1, boolean_val);
69             // Fail if previous line doesn't trhow exception.
70
fail(NOT_EXCEPTION + "from: new TreeAttribute(string, string1, boolean_val)");
71         } catch (InvalidArgumentException e) {
72             // OK
73
}
74     }
75     
76     
77     //--------------------------------------------------------------------------
78

79     
80     static TreeAttribute createAttribute(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, String JavaDoc view) throws Exception JavaDoc {
81         TreeAttribute node = new TreeAttribute(string, string1);
82         
83         assertEquals(node, view);
84         cloneNodeTest(node, view);
85         return node;
86     }
87     
88     static void createAttributeInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1) throws Exception JavaDoc {
89         try {
90             new TreeAttribute(string, string1);
91             // Fail if previous line doesn't trhow exception.
92
fail(NOT_EXCEPTION + "from: new TreeAttribute(string, string1)");
93         } catch (InvalidArgumentException e) {
94             // OK
95
}
96     }
97     
98     
99     //--------------------------------------------------------------------------
100

101     
102     static TreeCDATASection createCDATASection(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
103         TreeCDATASection node = new TreeCDATASection(string);
104         
105         assertEquals(node, view);
106         cloneNodeTest(node, view);
107         return node;
108     }
109     
110     static void createCDATASectionInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
111         try {
112             new TreeCDATASection(string);
113             // Fail if previous line doesn't trhow exception.
114
fail(NOT_EXCEPTION + "from: new TreeCDATASection(string)");
115         } catch (InvalidArgumentException e) {
116             // OK
117
}
118     }
119     
120     
121     //--------------------------------------------------------------------------
122

123     
124     static TreeCharacterReference createCharacterReference(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
125         TreeCharacterReference node = new TreeCharacterReference(string);
126         
127         assertEquals(node, view);
128         cloneNodeTest(node, view);
129         return node;
130     }
131     
132     static void createCharacterReferenceInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
133         try {
134             new TreeCharacterReference(string);
135             // Fail if previous line doesn't trhow exception.
136
fail(NOT_EXCEPTION + "from: new TreeCharacterReference(string)");
137         } catch (InvalidArgumentException e) {
138             // OK
139
}
140     }
141     
142     
143     //--------------------------------------------------------------------------
144

145     
146     static TreeComment createComment(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
147         TreeComment node = new TreeComment(string);
148         
149         assertEquals(node, view);
150         cloneNodeTest(node, view);
151         return node;
152     }
153     
154     static void createCommentInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
155         try {
156             new TreeComment(string);
157             // Fail if previous line doesn't trhow exception.
158
fail(NOT_EXCEPTION + "from: new TreeComment(string)");
159         } catch (InvalidArgumentException e) {
160             // OK
161
}
162     }
163     
164     
165     //--------------------------------------------------------------------------
166

167     
168     static TreeConditionalSection createConditionalSection(boolean boolean_val, String JavaDoc view) throws Exception JavaDoc {
169         TreeConditionalSection node = new TreeConditionalSection(boolean_val);
170         
171         assertEquals(node, view);
172         cloneNodeTest(node, view);
173         return node;
174     }
175     
176     
177     //--------------------------------------------------------------------------
178

179     
180     static TreeDTD createDTD(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, String JavaDoc view) throws Exception JavaDoc {
181         TreeDTD node = new TreeDTD(string, string1);
182         
183         assertEquals(node, view);
184         cloneNodeTest(node, view);
185         return node;
186     }
187     
188     static void createDTDInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1) throws Exception JavaDoc {
189         try {
190             new TreeDTD(string, string1);
191             // Fail if previous line doesn't trhow exception.
192
fail(NOT_EXCEPTION + "from: new TreeDTD(string, string1)");
193         } catch (InvalidArgumentException e) {
194             // OK
195
}
196     }
197     
198     
199     //--------------------------------------------------------------------------
200

201     
202     static TreeDocument createDocument(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2, String JavaDoc view) throws Exception JavaDoc {
203         TreeDocument node = new TreeDocument(string, string1, string2);
204         
205         assertEquals(node, view);
206         cloneNodeTest(node, view);
207         return node;
208     }
209     
210     static void createDocumentInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2) throws Exception JavaDoc {
211         try {
212             new TreeDocument(string, string1, string2);
213             // Fail if previous line doesn't trhow exception.
214
fail(NOT_EXCEPTION + "from: new TreeDocument(string, string1, string2)");
215         } catch (InvalidArgumentException e) {
216             // OK
217
}
218     }
219     
220     
221     //--------------------------------------------------------------------------
222

223     
224     static TreeDocumentFragment createDocumentFragment(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, String JavaDoc view) throws Exception JavaDoc {
225         TreeDocumentFragment node = new TreeDocumentFragment(string, string1);
226         
227         assertEquals(node, view);
228         cloneNodeTest(node, view);
229         return node;
230     }
231     
232     static void createDocumentFragmentInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1) throws Exception JavaDoc {
233         try {
234             new TreeDocumentFragment(string, string1);
235             // Fail if previous line doesn't trhow exception.
236
fail(NOT_EXCEPTION + "from: new TreeDocumentFragment(string, string1)");
237         } catch (InvalidArgumentException e) {
238             // OK
239
}
240     }
241     
242     
243     //--------------------------------------------------------------------------
244

245     
246     static TreeDocumentType createDocumentType(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2, String JavaDoc view) throws Exception JavaDoc {
247         TreeDocumentType node = new TreeDocumentType(string, string1, string2);
248         
249         assertEquals(node, view);
250         cloneNodeTest(node, view);
251         return node;
252     }
253     
254     static void createDocumentTypeInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2) throws Exception JavaDoc {
255         try {
256             new TreeDocumentType(string, string1, string2);
257             // Fail if previous line doesn't trhow exception.
258
fail(NOT_EXCEPTION + "from: new TreeDocumentType(string, string1, string2)");
259         } catch (InvalidArgumentException e) {
260             // OK
261
}
262     }
263     
264     
265     //--------------------------------------------------------------------------
266

267     
268     static TreeDocumentType createDocumentType(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
269         TreeDocumentType node = new TreeDocumentType(string);
270         
271         assertEquals(node, view);
272         cloneNodeTest(node, view);
273         return node;
274     }
275     
276     static void createDocumentTypeInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
277         try {
278             new TreeDocumentType(string);
279             // Fail if previous line doesn't trhow exception.
280
fail(NOT_EXCEPTION + "from: new TreeDocumentType(string)");
281         } catch (InvalidArgumentException e) {
282             // OK
283
}
284     }
285     
286     
287     //--------------------------------------------------------------------------
288

289     
290     static TreeElement createElement(java.lang.String JavaDoc string, boolean boolean_val, String JavaDoc view) throws Exception JavaDoc {
291         TreeElement node = new TreeElement(string, boolean_val);
292         
293         assertEquals(node, view);
294         cloneNodeTest(node, view);
295         return node;
296     }
297     
298     static void createElementInvalid(java.lang.String JavaDoc string, boolean boolean_val) throws Exception JavaDoc {
299         try {
300             new TreeElement(string, boolean_val);
301             // Fail if previous line doesn't trhow exception.
302
fail(NOT_EXCEPTION + "from: new TreeElement(string, boolean_val)");
303         } catch (InvalidArgumentException e) {
304             // OK
305
}
306     }
307     
308     
309     //--------------------------------------------------------------------------
310

311     
312     static TreeElement createElement(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
313         TreeElement node = new TreeElement(string);
314         
315         assertEquals(node, view);
316         cloneNodeTest(node, view);
317         return node;
318     }
319     
320     static void createElementInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
321         try {
322             new TreeElement(string);
323             // Fail if previous line doesn't trhow exception.
324
fail(NOT_EXCEPTION + "from: new TreeElement(string)");
325         } catch (InvalidArgumentException e) {
326             // OK
327
}
328     }
329     
330     
331     //--------------------------------------------------------------------------
332

333     
334     static TreeElementDecl createElementDecl(java.lang.String JavaDoc string, ContentType treeelementdecl$contenttype, String JavaDoc view) throws Exception JavaDoc {
335         TreeElementDecl node = new TreeElementDecl(string, treeelementdecl$contenttype);
336         
337         assertEquals(node, view);
338         cloneNodeTest(node, view);
339         return node;
340     }
341     
342     static void createElementDeclInvalid(java.lang.String JavaDoc string, ContentType treeelementdecl$contenttype) throws Exception JavaDoc {
343         try {
344             new TreeElementDecl(string, treeelementdecl$contenttype);
345             // Fail if previous line doesn't trhow exception.
346
fail(NOT_EXCEPTION + "from: new TreeElementDecl(string, treeelementdecl$contenttype)");
347         } catch (InvalidArgumentException e) {
348             // OK
349
}
350     }
351     
352     
353     //--------------------------------------------------------------------------
354

355 /*
356     static TreeElementDecl createElementDecl(java.lang.String string, java.lang.String string1, String view) throws Exception {
357         TreeElementDecl node = new TreeElementDecl(string, string1);
358  
359         assertEquals(node, view);
360         cloneNodeTest(node, view);
361         return node;
362     }
363  
364     static void createElementDeclInvalid(java.lang.String string, java.lang.String string1) throws Exception {
365         try {
366             new TreeElementDecl(string, string1);
367             // Fail if previous line doesn't trhow exception.
368             fail(NOT_EXCEPTION + "from: new TreeElementDecl(string, string1)");
369         } catch (InvalidArgumentException e) {
370             // OK
371         }
372     }
373  
374  */

375     //--------------------------------------------------------------------------
376

377     
378     static TreeEntityDecl createEntityDecl(boolean boolean_val, java.lang.String JavaDoc string, java.lang.String JavaDoc string2, String JavaDoc view) throws Exception JavaDoc {
379         TreeEntityDecl node = new TreeEntityDecl(boolean_val, string, string2);
380         
381         assertEquals(node, view);
382         cloneNodeTest(node, view);
383         return node;
384     }
385     
386     static void createEntityDeclInvalid(boolean boolean_val, java.lang.String JavaDoc string, java.lang.String JavaDoc string2) throws Exception JavaDoc {
387         try {
388             new TreeEntityDecl(boolean_val, string, string2);
389             // Fail if previous line doesn't trhow exception.
390
fail(NOT_EXCEPTION + "from: new TreeEntityDecl(boolean_val, string, string2)");
391         } catch (InvalidArgumentException e) {
392             // OK
393
}
394     }
395     
396     
397     //--------------------------------------------------------------------------
398

399     
400     static TreeEntityDecl createEntityDecl(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, String JavaDoc view) throws Exception JavaDoc {
401         TreeEntityDecl node = new TreeEntityDecl(string, string1);
402         
403         assertEquals(node, view);
404         cloneNodeTest(node, view);
405         return node;
406     }
407     
408     static void createEntityDeclInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1) throws Exception JavaDoc {
409         try {
410             new TreeEntityDecl(string, string1);
411             // Fail if previous line doesn't trhow exception.
412
fail(NOT_EXCEPTION + "from: new TreeEntityDecl(string, string1)");
413         } catch (InvalidArgumentException e) {
414             // OK
415
}
416     }
417     
418     
419     //--------------------------------------------------------------------------
420

421     
422     static TreeEntityDecl createEntityDecl(boolean boolean_val, java.lang.String JavaDoc string, java.lang.String JavaDoc string2, java.lang.String JavaDoc string3, String JavaDoc view) throws Exception JavaDoc {
423         TreeEntityDecl node = new TreeEntityDecl(boolean_val, string, string2, string3);
424         
425         assertEquals(node, view);
426         cloneNodeTest(node, view);
427         return node;
428     }
429     
430     static void createEntityDeclInvalid(boolean boolean_val, java.lang.String JavaDoc string, java.lang.String JavaDoc string2, java.lang.String JavaDoc string3) throws Exception JavaDoc {
431         try {
432             new TreeEntityDecl(boolean_val, string, string2, string3);
433             // Fail if previous line doesn't trhow exception.
434
fail(NOT_EXCEPTION + "from: new TreeEntityDecl(boolean_val, string, string2, string3)");
435         } catch (InvalidArgumentException e) {
436             // OK
437
}
438     }
439     
440     
441     //--------------------------------------------------------------------------
442

443     
444     static TreeEntityDecl createEntityDecl(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2, String JavaDoc view) throws Exception JavaDoc {
445         TreeEntityDecl node = new TreeEntityDecl(string, string1, string2);
446         
447         assertEquals(node, view);
448         cloneNodeTest(node, view);
449         return node;
450     }
451     
452     static void createEntityDeclInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2) throws Exception JavaDoc {
453         try {
454             new TreeEntityDecl(string, string1, string2);
455             // Fail if previous line doesn't trhow exception.
456
fail(NOT_EXCEPTION + "from: new TreeEntityDecl(string, string1, string2)");
457         } catch (InvalidArgumentException e) {
458             // OK
459
}
460     }
461     
462     
463     //--------------------------------------------------------------------------
464

465     
466     static TreeEntityDecl createEntityDecl(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2, java.lang.String JavaDoc string3, String JavaDoc view) throws Exception JavaDoc {
467         TreeEntityDecl node = new TreeEntityDecl(string, string1, string2, string3);
468         
469         assertEquals(node, view);
470         cloneNodeTest(node, view);
471         return node;
472     }
473     
474     static void createEntityDeclInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2, java.lang.String JavaDoc string3) throws Exception JavaDoc {
475         try {
476             new TreeEntityDecl(string, string1, string2, string3);
477             // Fail if previous line doesn't trhow exception.
478
fail(NOT_EXCEPTION + "from: new TreeEntityDecl(string, string1, string2, string3)");
479         } catch (InvalidArgumentException e) {
480             // OK
481
}
482     }
483     
484     
485     //--------------------------------------------------------------------------
486

487     
488     static TreeGeneralEntityReference createGeneralEntityReference(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
489         TreeGeneralEntityReference node = new TreeGeneralEntityReference(string);
490         
491         assertEquals(node, view);
492         cloneNodeTest(node, view);
493         return node;
494     }
495     
496     static void createGeneralEntityReferenceInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
497         try {
498             new TreeGeneralEntityReference(string);
499             // Fail if previous line doesn't trhow exception.
500
fail(NOT_EXCEPTION + "from: new TreeGeneralEntityReference(string)");
501         } catch (InvalidArgumentException e) {
502             // OK
503
}
504     }
505     
506     
507     //--------------------------------------------------------------------------
508

509     
510     static TreeNotationDecl createNotationDecl(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2, String JavaDoc view) throws Exception JavaDoc {
511         TreeNotationDecl node = new TreeNotationDecl(string, string1, string2);
512         
513         assertEquals(node, view);
514         cloneNodeTest(node, view);
515         return node;
516     }
517     
518     static void createNotationDeclInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, java.lang.String JavaDoc string2) throws Exception JavaDoc {
519         try {
520             new TreeNotationDecl(string, string1, string2);
521             // Fail if previous line doesn't trhow exception.
522
fail(NOT_EXCEPTION + "from: new TreeNotationDecl(string, string1, string2)");
523         } catch (InvalidArgumentException e) {
524             // OK
525
}
526     }
527     
528     
529     //--------------------------------------------------------------------------
530

531     
532     static TreeParameterEntityReference createParameterEntityReference(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
533         TreeParameterEntityReference node = new TreeParameterEntityReference(string);
534         
535         assertEquals(node, view);
536         cloneNodeTest(node, view);
537         return node;
538     }
539     
540     static void createParameterEntityReferenceInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
541         try {
542             new TreeParameterEntityReference(string);
543             // Fail if previous line doesn't trhow exception.
544
fail(NOT_EXCEPTION + "from: new TreeParameterEntityReference(string)");
545         } catch (InvalidArgumentException e) {
546             // OK
547
}
548     }
549     
550     
551     //--------------------------------------------------------------------------
552

553     
554     static TreeProcessingInstruction createProcessingInstruction(java.lang.String JavaDoc string, java.lang.String JavaDoc string1, String JavaDoc view) throws Exception JavaDoc {
555         TreeProcessingInstruction node = new TreeProcessingInstruction(string, string1);
556         
557         assertEquals(node, view);
558         cloneNodeTest(node, view);
559         return node;
560     }
561     
562     static void createProcessingInstructionInvalid(java.lang.String JavaDoc string, java.lang.String JavaDoc string1) throws Exception JavaDoc {
563         try {
564             new TreeProcessingInstruction(string, string1);
565             // Fail if previous line doesn't trhow exception.
566
fail(NOT_EXCEPTION + "from: new TreeProcessingInstruction(string, string1)");
567         } catch (InvalidArgumentException e) {
568             // OK
569
}
570     }
571     
572     
573     //--------------------------------------------------------------------------
574

575     
576     static TreeText createText(java.lang.String JavaDoc string, String JavaDoc view) throws Exception JavaDoc {
577         TreeText node = new TreeText(string);
578         
579         assertEquals(node, view);
580         cloneNodeTest(node, view);
581         return node;
582     }
583     
584     static void createTextInvalid(java.lang.String JavaDoc string) throws Exception JavaDoc {
585         try {
586             new TreeText(string);
587             // Fail if previous line doesn't trhow exception.
588
fail(NOT_EXCEPTION + "from: new TreeText(string)");
589         } catch (InvalidArgumentException e) {
590             // OK
591
}
592     }
593     
594     
595     private static void cloneNodeTest(TreeParentNode node, String JavaDoc view) throws Exception JavaDoc {
596         TreeParentNode clone = (TreeParentNode) node.clone(true);
597         assertNotEquals(clone, node);
598         assertEquals(clone, view);
599         
600         clone = (TreeParentNode) node.clone(false);
601         assertNotEquals(clone, node);
602         assertEquals(clone, view);
603     }
604     
605     private static void cloneNodeTest(TreeNode node, String JavaDoc view) throws Exception JavaDoc {
606         TreeNode clone = (TreeNode) node.clone();
607         assertNotEquals(clone, node);
608         assertEquals(clone, view);
609     }
610     
611     private static void assertNotEquals(Object JavaDoc orig, Object JavaDoc clone) {
612         if (orig == clone) {
613             fail("Invalid clone.");
614         }
615     }
616     
617     private static void assertEquals(TreeNode node, String JavaDoc view) throws TreeException{
618         String JavaDoc str = Utilities.replaceString(TestUtil.nodeToString(node), "\n", "");
619         if (!!! str.equals(view)) {
620             fail("Invalid node view \n is : \"" + str + "\"\n should be: \"" + view + "\"");
621         }
622     }
623 }
624
Popular Tags