KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > gui > customizers > ClassCustomizer


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 package org.netbeans.test.java.gui.customizers;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import junit.textui.TestRunner;
27 import org.netbeans.jellytools.EditorOperator;
28 import org.netbeans.jellytools.JellyTestCase;
29 import org.netbeans.jellytools.ProjectsTabOperator;
30 import org.netbeans.jellytools.actions.OpenAction;
31 import org.netbeans.jellytools.modules.java.ClassCustomizerOperator;
32 import org.netbeans.jellytools.nodes.Node;
33 import org.netbeans.jellytools.properties.Property;
34 import org.netbeans.jellytools.properties.PropertySheetOperator;
35 import org.netbeans.jemmy.JemmyProperties;
36 import org.netbeans.jemmy.TestOut;
37 import org.netbeans.jemmy.operators.JEditorPaneOperator;
38 import org.netbeans.junit.NbTestSuite;
39 import org.netbeans.test.java.gui.GuiUtilities;
40
41 /**
42  * Tests editing of class parameters through a pop-up window.
43  * @author Roman Strobl
44  */

45 public class ClassCustomizer extends JellyTestCase {
46     
47     // name of sample project
48
private static final String JavaDoc TEST_PROJECT_NAME = "default";
49     
50     // path to sample files
51
private static final String JavaDoc TEST_PACKAGE_PATH =
52             "org.netbeans.test.java.gui.customizers";
53     
54     // name of sample package
55
private static final String JavaDoc TEST_PACKAGE_NAME = TEST_PACKAGE_PATH+".test";
56     
57     // name of sample class
58
private static final String JavaDoc TEST_CLASS_NAME = "ClassCustomizer";
59     
60     /**
61      * error log
62      */

63     protected static PrintStream JavaDoc err;
64     
65     /**
66      * standard log
67      */

68     protected static PrintStream JavaDoc log;
69     
70     // workdir, default /tmp, changed to NBJUnit workdir during test
71
private String JavaDoc workDir = "/tmp";
72     
73     // actual directory with project
74
private static String JavaDoc projectDir;
75     
76     
77     /**
78      * Needs to be defined because of JUnit
79      * @param name test name
80      */

81     public ClassCustomizer(String JavaDoc name) {
82         super(name);
83     }
84     
85     /**
86      * Adds tests into the test suite.
87      * @return suite
88      */

89     public static NbTestSuite suite() {
90         NbTestSuite suite = new NbTestSuite();
91         // prepare testing project and package - not a core test but needed
92
suite.addTest(new ClassCustomizer("testCustomizeClass"));
93         return suite;
94     }
95     
96     /**
97      * Main method for standalone execution.
98      * @param args the command line arguments
99      */

100     public static void main(java.lang.String JavaDoc[] args) {
101         TestRunner.run(suite());
102     }
103     
104     /**
105      * Sets up logging facilities.
106      */

107     public void setUp() {
108         System.out.println("######## "+getName()+" #######");
109         err = getLog();
110         log = getRef();
111         JemmyProperties.getProperties().setOutput(new TestOut(null,
112                 new PrintWriter JavaDoc(err, true), new PrintWriter JavaDoc(err, false), null));
113         try {
114             File JavaDoc wd = getWorkDir();
115             workDir = wd.toString();
116         } catch (IOException JavaDoc e) { }
117     }
118     
119     /**
120      * Tests customizing of a class.
121      */

122     public void testCustomizeClass() {
123         Node pn = new ProjectsTabOperator().getProjectRootNode(
124                 TEST_PROJECT_NAME);
125         pn.select();
126         
127         GuiUtilities.waitForChildNode(TEST_PROJECT_NAME,
128                 org.netbeans.jellytools.Bundle.getString(
129                 "org.netbeans.modules.java.j2seproject.Bundle",
130                 "NAME_src.dir")
131                 +"|"+TEST_PACKAGE_NAME+"|"+TEST_CLASS_NAME, TEST_CLASS_NAME);
132         
133         // open the properties pop-up
134
Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
135                 "org.netbeans.modules.java.j2seproject.Bundle",
136                 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
137                 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME);
138         
139         n.select();
140         new OpenAction().perform();
141         
142         n.select();
143         n.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString(
144                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
145         
146         ClassCustomizerOperator cco = new ClassCustomizerOperator(
147                 TEST_CLASS_NAME+" - "+org.netbeans.jellytools.Bundle.getString(
148                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
149         
150         PropertySheetOperator pso = new PropertySheetOperator(TEST_CLASS_NAME
151                 +" - "+org.netbeans.jellytools.Bundle.getString(
152                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
153         
154         // set some values to see if customization works
155
new Property(pso, "Implements").setValue("Thread");
156         new Property(pso, "Extends").setValue("java.lang.Object");
157         
158         cco.btClose().clickMouse();
159         
160         // compare reference files
161
ref(new EditorOperator(TEST_CLASS_NAME).getText());
162         compareReferenceFiles();
163         
164         EditorOperator.closeDiscardAll();
165     }
166 }
167
Popular Tags