KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestPositions


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
20 /*
21  * TestPositions - test the basic features.
22  *
23  * The following test assumes that we know the content of the
24  * graph as we get elements, add and change them. Therefore, the TestPositions.xml
25  * file and this java test should be kept in sync.
26  *
27  * Test the following:
28  *
29  * single String: get/set/remove/set/get
30  * boolean (from true): get/set true/get/set false/get/set true/get
31  * boolean (from false): get/set false/get/set true/get/set false/get
32  * String[]: get/set (null & !null)/add/remove
33  * Bean: remove/set(null)/create bean and graph of beans/set/add
34  *
35  */

36
37 import java.io.*;
38 import java.util.*;
39 import org.w3c.dom.*;
40
41 import menus.*;
42
43
44 public class TestPositions extends BaseTest {
45     public static void main(String JavaDoc[] argv) {
46         TestPositions o = new TestPositions();
47         if (argv.length > 0)
48             o.setDocumentDir(argv[0]);
49         try {
50             o.run();
51         } catch (Exception JavaDoc e) {
52             e.printStackTrace();
53             System.exit(1);
54         }
55         System.exit(0);
56     }
57     
58     public void run() throws Exception JavaDoc {
59         Menus menus;
60
61         this.readDocument();
62
63         out("creating the bean graph");
64         menus = Menus.read(doc);
65     
66         // Check that we can read the graph an it is complete
67
out("bean graph created");
68         menus.write(out);
69
70         out("Check to make sure that elements with the same name get put into the right spot");
71         Foo foo = menus.getFoo();
72         check(foo.sizeName() == 2, "There are 2 names");
73         check("name2".equals(foo.getName2()), "name2 is in the right spot");
74         check("name3".equals(foo.getName3()), "name3 is in the right spot");
75
76         out("Adding some colors to the menu.");
77         Menu menu = menus.getMenu(0);
78         menu.addMenuItem("red");
79         menu.addMenuItem("magenta");
80         menu.addMenuItem("blue");
81         menu.addSeparator(new Separator());
82         menu.addMenuItem("cyan");
83         menu.addSeparator(new Separator());
84         menu.addMenuItem("green");
85         menus.write(out);
86         check(8 == menu.sizeMenuItem(), "sizeMenuItem="+menu.sizeMenuItem());
87         out(menu.getMenuItem());
88
89         out("Replacing menu items with many numbers");
90         menu.setMenuItem(new String JavaDoc[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"});
91         menus.write(out);
92
93         out("Removing 7");
94         menu.removeMenuItem("7");
95         menus.write(out);
96
97         out("Replacing menu items with few letters");
98         menu.setMenuItem(new String JavaDoc[] {"a", "b", "c"});
99         menus.write(out);
100     }
101 }
102
Popular Tags