KickJava   Java API By Example, From Geeks To Geeks.

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


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.FieldCustomizerOperator;
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 of parameters of a field in a pop-up window.
44  * @author Roman Strobl
45  */

46 public class FieldCustomizer 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 = "FieldCustomizer";
60
61     // name of sample field
62
private static final String JavaDoc TEST_FIELD_NAME = "TestField";
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     /**
82      * Needs to be defined because of JUnit
83      * @param name test name
84      */

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

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

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

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

125     public void testCustomizeField() {
126         Node pn = new ProjectsTabOperator().getProjectRootNode(
127                 TEST_PROJECT_NAME);
128         pn.select();
129         
130         Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
131                 "org.netbeans.modules.java.j2seproject.Bundle",
132                 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
133                 +TEST_CLASS_NAME);
134         
135         n.select();
136         new OpenAction().perform();
137         
138         EditorOperator editor = new EditorOperator(TEST_CLASS_NAME);
139         
140         // type a String field into code
141
editor.insert("String "+TEST_FIELD_NAME+";\n", 14, 5);
142                                        
143         // open field properties
144
GuiUtilities.waitForChildNode(TEST_PROJECT_NAME,
145                 org.netbeans.jellytools.Bundle.getString(
146                 "org.netbeans.modules.java.j2seproject.Bundle",
147                 "NAME_src.dir")+"|"
148                 +TEST_PACKAGE_NAME+"|"+TEST_CLASS_NAME+"|"+TEST_CLASS_NAME+"|"
149                 +org.netbeans.jellytools.Bundle.getString(
150                 "org.netbeans.modules.java.ui.nodes.elements.Bundle",
151                 "Fields"), TEST_FIELD_NAME);
152
153         Node n2 = new Node(pn, org.netbeans.jellytools.Bundle.getString(
154                 "org.netbeans.modules.java.j2seproject.Bundle",
155                 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
156                 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME+"|"
157                 +org.netbeans.jellytools.Bundle.getString(
158                 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "Fields")
159                 +"|"+TEST_FIELD_NAME);
160         
161         n2.select();
162         n2.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString(
163                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
164         
165         FieldCustomizerOperator cco = new FieldCustomizerOperator(
166                 TEST_FIELD_NAME+" - "+org.netbeans.jellytools.Bundle.getString(
167                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
168         
169         PropertySheetOperator pso = new PropertySheetOperator(TEST_FIELD_NAME
170                 +" - "+org.netbeans.jellytools.Bundle.getString(
171                 "org.netbeans.core.Bundle", "CTL_PropertiesWindow"));
172         
173         // set some values to check if changes are propagated
174
new Property(pso, "Modifiers").setValue("private");
175         new Property(pso, "Initial value").setValue("\"xxx\"");
176         new Property(pso, "Type").setValue("Integer");
177         new Property(pso, "Initial value").setValue("12345");
178                 
179         cco.btClose().clickMouse();
180
181         // compare reference files
182
ref(editor.txtEditorPane().getText());
183         compareReferenceFiles();
184         
185         EditorOperator.closeDiscardAll();
186     }
187     
188 }
189
Popular Tags