KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestValid


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 import java.io.*;
20 import book.*;
21
22 import org.netbeans.modules.schema2beans.*;
23
24
25 public class TestValid extends BaseTest
26 {
27     public static void main(String JavaDoc[] argv) {
28         BaseTest o = new TestValid();
29         if (argv.length > 0)
30             o.setDocumentDir(argv[0]);
31         try {
32             o.run();
33         } catch (Exception JavaDoc e) {
34             e.printStackTrace();
35             System.exit(1);
36         }
37         System.exit(0);
38     }
39     
40     public void run()
41         throws Exception JavaDoc
42     {
43         readDocument();
44         
45         // Create the graph from the input stream
46
Book book = Book.createGraph(this.doc);
47
48         out("Current XML document:");
49         book.write(System.out);
50
51         out("Should add paperback after chapter:");
52         book.setPaperback(true);
53         book.write(System.out);
54
55         out("Should add summary after paperback:");
56         book.setSummary("Summary of the book");
57         book.write(System.out);
58
59         out("Should add chapter before paperback");
60         Chapter c = new Chapter();
61         c.setTitle("title1");
62         book.addChapter(c);
63         c = new Chapter();
64         c.setTitle("title2");
65         book.addChapter(c);
66         c = new Chapter();
67         c.setTitle("title3");
68         book.addChapter(c);
69         c = new Chapter();
70         c.setTitle("title4");
71         book.addChapter(c);
72         c = new Chapter();
73         c.setTitle("title5");
74         book.addChapter(c);
75
76         // Mix to index/Dom Node to test the property indexed case
77
Chapter[] c2 = book.getChapter();
78         c = c2[2];
79         c2[2] = c2[0];
80         c2[0] = c;
81         c = c2[3];
82         c2[3] = c2[1];
83         c2[1] = c;
84         book.setChapter(c2);
85         
86         out(book);
87
88         out("Should add title as the first property of book:");
89         book.setTitle("Title of the book");
90         out(book);
91         
92         out("Should add price as the last property of book:");
93         book.setPrice("19.99");
94         out(book);
95         
96         out("Should add isbn before the price:");
97         book.setIsbn("120394857");
98         out(book);
99
100         out("Should add ending at the end of the chapter:");
101         c = book.getChapter(0);
102         c.setEnding("And this is how this chapter ends.");
103         out(book);
104         
105         out("Should add conclusion before the ending");
106         c.setConclusion("And this concludes this chapter.");
107         out(book);
108
109         out("Should add Note with year before copyright");
110         Note n = new Note();
111         n.setYear("2000");
112         n.setCopyright("1997");
113         book.setNote(n);
114         out(book);
115
116         out("Should set Note with date before copyright");
117         n = new Note();
118         n.setDate("2001");
119         n.setCopyright("1996");
120         book.setNote(n);
121         out(book);
122     }
123 }
124
125
Popular Tags