KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestMdd


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  * TestMdd - test the attribute features
21  *
22  * TestMdd.dtd and TestMdd.xml has to be kept in sync with this test.
23  */

24
25 import java.io.*;
26 import java.util.*;
27 import org.w3c.dom.*;
28
29 import org.netbeans.modules.schema2beans.*;
30 import java.beans.*;
31 import book.*;
32
33
34 public class TestMdd extends BaseTest
35 {
36     public static void main(String JavaDoc[] argv) {
37         BaseTest o = new TestMdd();
38         if (argv.length > 0)
39             o.setDocumentDir(argv[0]);
40         try {
41             o.run();
42         } catch (Exception JavaDoc e) {
43             e.printStackTrace();
44             System.exit(1);
45         }
46         System.exit(0);
47     }
48     
49     public void run()
50         throws Exception JavaDoc
51     {
52         Book book;
53
54         this.readDocument();
55         out("creating the bean graph");
56         //out(DDFactory.XmlToString(doc));
57
book = Book.createGraph(doc);
58         out("bean graph created");
59         
60         // Check Wrapper class and float scalar
61
{
62             setTest("get non scalar wrapper object");
63             Object JavaDoc obj = book.getDate();
64             check(obj instanceof book.MyDate);
65             out(obj.toString());
66
67             setTest("get float scalar value");
68             float f = book.getPrice();
69             float ref = (float)10.95;
70             float f2 = (float)9.99;
71             check(f == ref);
72             out("Setting new price to " + f2);
73             book.setPrice(f2);
74             f = book.getPrice();
75             check(f == f2);
76             out("Price and date should match", book.dumpDomNode(2));
77         }
78
79         // Check Character
80
{
81             setTest("get char scalar value");
82             Index idx = book.getIndex(0);
83             char c = idx.getAlpha();
84             check(c == 'a');
85             idx.setAlpha('x');
86             check(idx.getAlpha() == 'x');
87             out("Alpha should be 'x'", idx.dumpDomNode(2));
88         }
89         
90         // Check Integer as an indexed property
91
{
92             setTest("get int/int[] scalar values");
93             Ref ref = book.getIndex(0).getRef(0);
94             int[] i = ref.getLine();
95             check(i.length == 3);
96             check(ref.getPage() == 22);
97             check(i[0] == 12);
98             check(i[1] == 22);
99             check(i[2] == 32);
100             i[2] = 323;
101             ref.setLine(i);
102             check(ref.getPage() == 22);
103             check(ref.getLine(0) == 12);
104             check(ref.getLine(1) == 22);
105             check(ref.getLine(2) == 323);
106             out("Lines should be 12/22/323", ref.dumpDomNode(2));
107         }
108     }
109 }
110
111
112
Popular Tags