KickJava   Java API By Example, From Geeks To Geeks.

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


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.MethodCustomizerOperator;
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 /**
43  * Tests editing parameters of a method in a pop-up window.
44  * @author Roman Strobl
45  */

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

67     protected static PrintStream JavaDoc err;
68     
69     /**
70      * standard log
71      */

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

84     public MethodCustomizer(String JavaDoc name) {
85         super(name);
86     }
87
88     /**
89      * Adds tests into the test suite.
90      * @return suite
91      */

92     public static NbTestSuite suite() {
93         NbTestSuite suite = new NbTestSuite();
94         suite.addTest(new MethodCustomizer("testCustomizeMethod"));
95         return suite;
96     }
97     
98     /**
99      * Main method for standalone execution.
100      * @param args the command line arguments
101      */

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

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

124     public void testCustomizeMethod() {
125         Node pn = new ProjectsTabOperator().getProjectRootNode(
126                 TEST_PROJECT_NAME);
127         pn.select();
128
129         Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
130                 "org.netbeans.modules.java.j2seproject.Bundle",
131                 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
132                 +TEST_CLASS_NAME);
133         
134         n.select();
135         new OpenAction().perform();
136
137         EditorOperator editor = new EditorOperator(TEST_CLASS_NAME);
138         
139         // type a method into code
140
editor.insert("String "+TEST_METHOD_NAME+"(){ };\n", 14, 5);
141                 
142         // open method properties window
143
GuiUtilities.waitForChildNode(TEST_PROJECT_NAME, "Source Packages|"
144                 +TEST_PACKAGE_NAME+"|"+TEST_CLASS_NAME+"|"+TEST_CLASS_NAME+"|"
145                 +org.netbeans.jellytools.Bundle.getString(
146                 "org.netbeans.modules.java.ui.nodes.elements.Bundle",
147                 "Methods"), TEST_METHOD_NAME);
148
149         Node n2 = new Node(pn, "Source Packages|"+TEST_PACKAGE_NAME+"|"
150                 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME+"|"
151                 +org.netbeans.jellytools.Bundle.getString(
152                 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "Methods")
153                 +"|"+TEST_METHOD_NAME); // NOI18N
154

155
156         n2.select();
157         n2.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString(
158                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
159         
160         MethodCustomizerOperator cco = new MethodCustomizerOperator(
161                 TEST_METHOD_NAME+" - "+org.netbeans.jellytools.Bundle.getString(
162                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
163         
164         PropertySheetOperator pso = new PropertySheetOperator(TEST_METHOD_NAME
165                 +" - "+org.netbeans.jellytools.Bundle.getString(
166                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
167         
168         // try to set some values to see if customization works
169
new Property(pso, "Modifiers").setValue("private");
170         new Property(pso, "Return Type").setValue("void");
171         new Property(pso, "Exceptions").setValue("Exception");
172                 
173         cco.btClose().clickMouse();
174
175         // compare reference files
176
ref(editor.getText());
177         compareReferenceFiles();
178         
179         EditorOperator.closeDiscardAll();
180     }
181     
182 }
183
Popular Tags