001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package gui;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import junit.textui.TestRunner;
047: import org.netbeans.jellytools.Bundle;
048: import org.netbeans.jellytools.EditorOperator;
049: import org.netbeans.jellytools.JellyTestCase;
050: import org.netbeans.jellytools.NbDialogOperator;
051: import org.netbeans.jellytools.RepositoryTabOperator;
052: import org.netbeans.jellytools.actions.PropertiesAction;
053: import org.netbeans.jellytools.nodes.JavaNode;
054: import org.netbeans.jellytools.nodes.Node;
055: import org.netbeans.jemmy.EventTool;
056: import org.netbeans.jemmy.operators.JCheckBoxOperator;
057: import org.netbeans.jemmy.operators.JComboBoxOperator;
058: import org.netbeans.jemmy.operators.JRadioButtonOperator;
059: import org.netbeans.junit.NbTestSuite;
060: import org.openide.actions.SaveAllAction;
061: import org.openide.filesystems.FileObject;
062: import org.openide.filesystems.Repository;
063: import org.openide.loaders.DataFolder;
064: import org.openide.loaders.DataObject;
065:
066: public class NewUnicastEventSource extends JellyTestCase {
067:
068: private static final String NAME_TEST_FILE = "TestFile";
069:
070: private static final String sampleDir = Utilities.findFileSystem(
071: "src").getDisplayName();
072:
073: /** Need to be defined because of JUnit */
074: public NewUnicastEventSource(String name) {
075: super (name);
076: }
077:
078: public static NbTestSuite suite() {
079: NbTestSuite suite = new NbTestSuite();
080: suite.addTest(new NewUnicastEventSource("testGenerateEmpty"));
081: suite.addTest(new NewUnicastEventSource(
082: "testGenerateImplementation"));
083: suite.addTest(new NewUnicastEventSource(
084: "testGenerateEventFiringMethods"));
085: suite.addTest(new NewUnicastEventSource(
086: "testPassEventAsParameter"));
087: return suite;
088: }
089:
090: /** Use for execution inside IDE */
091: public static void main(java.lang.String[] args) {
092: // run whole suite
093: TestRunner.run(suite());
094: // run only selected test case
095: //junit.textui.TestRunner.run(new BeansTemplates("testJavaBean"));
096: }
097:
098: /** setUp method */
099: public void setUp() {
100: System.out.println("######## " + getName() + " #######");
101:
102: FileObject testFile = Repository.getDefault().findResource(
103: "gui/data/" + NAME_TEST_FILE + ".java");
104: FileObject destination = Repository.getDefault()
105: .findFileSystem(sampleDir.replace('\\', '/')).getRoot();
106:
107: try {
108: DataObject.find(testFile).copy(
109: DataFolder.findFolder(destination));
110: } catch (IOException e) {
111: fail(e);
112: }
113: new PropertiesAction().perform();
114: }
115:
116: /** tearDown method */
117: public void tearDown() {
118: ((SaveAllAction) SaveAllAction.findObject(SaveAllAction.class,
119: true)).performAction();
120:
121: Utilities.delete(NAME_TEST_FILE + ".java");
122: }
123:
124: /** testGenerateEmpty method */
125: public void testGenerateEmpty() {
126: //
127: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
128:
129: Node repositoryRootNode = explorerOperator.getRootNode();
130: Node patternsNode = new Node(repositoryRootNode, sampleDir
131: + "|"
132: + NAME_TEST_FILE
133: + "|"
134: + "class "
135: + NAME_TEST_FILE
136: + "|"
137: + Bundle.getString("org.netbeans.modules.beans.Bundle",
138: "Patterns"));
139: patternsNode.select();
140: patternsNode.performPopupActionNoBlock("Add"
141: + "|"
142: + Bundle.getString("org.netbeans.modules.beans.Bundle",
143: "MENU_CREATE_UNICASTSE"));
144: String dialogTitle = Bundle.getString(
145: "org.netbeans.modules.beans.Bundle",
146: "CTL_TITLE_NewUniCastES");
147: NbDialogOperator nbDialogOperator = new NbDialogOperator(
148: dialogTitle);
149:
150: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
151: nbDialogOperator, 0);
152: jComboBoxOperator
153: .setSelectedItem("java.awt.event.ActionListener");
154:
155: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
156: nbDialogOperator, Bundle.getString(
157: "org.netbeans.modules.beans.Bundle",
158: "CTL_UEventSetPanel_emptyRadioButton"));
159: jRadioButtonOperator.push();
160:
161: new EventTool().waitNoEvent(2000);
162:
163: nbDialogOperator.ok();
164:
165: new JavaNode(repositoryRootNode, sampleDir + "|"
166: + NAME_TEST_FILE).open();
167:
168: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
169: ref(eo.getText());
170: compareReferenceFiles();
171: //
172: }
173:
174: /** testGenerateImplementation method */
175: public void testGenerateImplementation() {
176: //
177: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
178:
179: Node repositoryRootNode = explorerOperator.getRootNode();
180: Node patternsNode = new Node(repositoryRootNode, sampleDir
181: + "|"
182: + NAME_TEST_FILE
183: + "|"
184: + "class "
185: + NAME_TEST_FILE
186: + "|"
187: + Bundle.getString("org.netbeans.modules.beans.Bundle",
188: "Patterns"));
189: patternsNode.select();
190: patternsNode.performPopupActionNoBlock(Bundle.getString(
191: "org.openide.src.nodes.Bundle", "LAB_Add")
192: + "|"
193: + Bundle.getString("org.netbeans.modules.beans.Bundle",
194: "MENU_CREATE_UNICASTSE"));
195: String dialogTitle = Bundle.getString(
196: "org.netbeans.modules.beans.Bundle",
197: "CTL_TITLE_NewUniCastES");
198: NbDialogOperator nbDialogOperator = new NbDialogOperator(
199: dialogTitle);
200:
201: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
202: nbDialogOperator, 0);
203: jComboBoxOperator
204: .setSelectedItem("java.awt.event.ActionListener");
205:
206: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
207: nbDialogOperator, Bundle.getString(
208: "org.netbeans.modules.beans.Bundle",
209: "CTL_UEventSetPanel_implRadioButton"));
210: jRadioButtonOperator.push();
211:
212: new EventTool().waitNoEvent(2000);
213:
214: nbDialogOperator.ok();
215:
216: new JavaNode(repositoryRootNode, sampleDir + "|"
217: + NAME_TEST_FILE).open();
218:
219: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
220: ref(eo.getText());
221: compareReferenceFiles();
222: //
223: }
224:
225: /** testGenerateEventFiringMethods method */
226: public void testGenerateEventFiringMethods() {
227: //
228: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
229:
230: Node repositoryRootNode = explorerOperator.getRootNode();
231: Node patternsNode = new Node(repositoryRootNode, sampleDir
232: + "|"
233: + NAME_TEST_FILE
234: + "|"
235: + "class "
236: + NAME_TEST_FILE
237: + "|"
238: + Bundle.getString("org.netbeans.modules.beans.Bundle",
239: "Patterns"));
240: patternsNode.select();
241: patternsNode.performPopupActionNoBlock(Bundle.getString(
242: "org.openide.src.nodes.Bundle", "LAB_Add")
243: + "|"
244: + Bundle.getString("org.netbeans.modules.beans.Bundle",
245: "MENU_CREATE_UNICASTSE"));
246: String dialogTitle = Bundle.getString(
247: "org.netbeans.modules.beans.Bundle",
248: "CTL_TITLE_NewUniCastES");
249: NbDialogOperator nbDialogOperator = new NbDialogOperator(
250: dialogTitle);
251:
252: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
253: nbDialogOperator, 0);
254: jComboBoxOperator
255: .setSelectedItem("java.awt.event.ActionListener");
256:
257: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
258: nbDialogOperator, Bundle.getString(
259: "org.netbeans.modules.beans.Bundle",
260: "CTL_UEventSetPanel_implRadioButton"));
261: jRadioButtonOperator.push();
262:
263: JCheckBoxOperator jCheckBoxOperator = new JCheckBoxOperator(
264: nbDialogOperator, Bundle.getString(
265: "org.netbeans.modules.beans.Bundle",
266: "CTL_UEventSetPanel_fireCheckBox"));
267: jCheckBoxOperator.push();
268:
269: new EventTool().waitNoEvent(2000);
270:
271: nbDialogOperator.ok();
272:
273: new JavaNode(repositoryRootNode, sampleDir + "|"
274: + NAME_TEST_FILE).open();
275:
276: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
277: ref(eo.getText());
278: compareReferenceFiles();
279: //
280: }
281:
282: /** testPassEventAsParameter method */
283: public void testPassEventAsParameter() {
284: //
285: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
286:
287: Node repositoryRootNode = explorerOperator.getRootNode();
288: Node patternsNode = new Node(repositoryRootNode, sampleDir
289: + "|"
290: + NAME_TEST_FILE
291: + "|"
292: + "class "
293: + NAME_TEST_FILE
294: + "|"
295: + Bundle.getString("org.netbeans.modules.beans.Bundle",
296: "Patterns"));
297: patternsNode.select();
298: patternsNode.performPopupActionNoBlock(Bundle.getString(
299: "org.openide.src.nodes.Bundle", "LAB_Add")
300: + "|"
301: + Bundle.getString("org.netbeans.modules.beans.Bundle",
302: "MENU_CREATE_UNICASTSE"));
303: String dialogTitle = Bundle.getString(
304: "org.netbeans.modules.beans.Bundle",
305: "CTL_TITLE_NewUniCastES");
306: NbDialogOperator nbDialogOperator = new NbDialogOperator(
307: dialogTitle);
308:
309: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
310: nbDialogOperator, 0);
311: jComboBoxOperator
312: .setSelectedItem("java.awt.event.ActionListener");
313:
314: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
315: nbDialogOperator, Bundle.getString(
316: "org.netbeans.modules.beans.Bundle",
317: "CTL_UEventSetPanel_implRadioButton"));
318: jRadioButtonOperator.push();
319:
320: JCheckBoxOperator jCheckBoxOperator = new JCheckBoxOperator(
321: nbDialogOperator, Bundle.getString(
322: "org.netbeans.modules.beans.Bundle",
323: "CTL_UEventSetPanel_fireCheckBox"));
324: jCheckBoxOperator.push();
325: jCheckBoxOperator = new JCheckBoxOperator(nbDialogOperator,
326: Bundle.getString("org.netbeans.modules.beans.Bundle",
327: "CTL_UEventSetPanel_passEventCheckBox"));
328: jCheckBoxOperator.push();
329:
330: new EventTool().waitNoEvent(2000);
331:
332: nbDialogOperator.ok();
333:
334: new JavaNode(repositoryRootNode, sampleDir + "|"
335: + NAME_TEST_FILE).open();
336:
337: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
338: ref(eo.getText());
339: compareReferenceFiles();
340: //
341: }
342: }
|