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 NewMulticastEventSource 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 NewMulticastEventSource(String name) {
075: super (name);
076: }
077:
078: public static NbTestSuite suite() {
079: NbTestSuite suite = new NbTestSuite();
080: suite.addTest(new NewMulticastEventSource("testGenerateEmpty"));
081: suite.addTest(new NewMulticastEventSource(
082: "testGenerateArrayListImplementation"));
083: suite.addTest(new NewMulticastEventSource(
084: "testGenerateEventListenerListImplementation"));
085: suite.addTest(new NewMulticastEventSource(
086: "testGenerateEventFiringMethods"));
087: suite.addTest(new NewMulticastEventSource(
088: "testPassEventAsParameter"));
089: return suite;
090: }
091:
092: /** Use for execution inside IDE */
093: public static void main(java.lang.String[] args) {
094: // run whole suite
095: TestRunner.run(suite());
096: // run only selected test case
097: //junit.textui.TestRunner.run(new BeansTemplates("testJavaBean"));
098: }
099:
100: /** setUp method */
101: public void setUp() {
102: System.out.println("######## " + getName() + " #######");
103:
104: FileObject testFile = Repository.getDefault().findResource(
105: "gui/data/" + NAME_TEST_FILE + ".java");
106: FileObject destination = Repository.getDefault()
107: .findFileSystem(sampleDir.replace('\\', '/')).getRoot();
108:
109: try {
110: DataObject.find(testFile).copy(
111: DataFolder.findFolder(destination));
112: } catch (IOException e) {
113: fail(e);
114: }
115: new PropertiesAction().perform();
116: }
117:
118: /** tearDown method */
119: public void tearDown() {
120: ((SaveAllAction) SaveAllAction.findObject(SaveAllAction.class,
121: true)).performAction();
122:
123: Utilities.delete(NAME_TEST_FILE + ".java");
124: }
125:
126: public void testGenerateEmpty() {
127: //
128: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
129:
130: Node repositoryRootNode = explorerOperator.getRootNode();
131: Node patternsNode = new Node(repositoryRootNode, sampleDir
132: + "|"
133: + NAME_TEST_FILE
134: + "|"
135: + "class "
136: + NAME_TEST_FILE
137: + "|"
138: + Bundle.getString("org.netbeans.modules.beans.Bundle",
139: "Patterns"));
140: patternsNode.select();
141: patternsNode.performPopupActionNoBlock(Bundle.getString(
142: "org.openide.src.nodes.Bundle", "LAB_Add")
143: + "|"
144: + Bundle.getString("org.netbeans.modules.beans.Bundle",
145: "MENU_CREATE_MULTICASTSE"));
146: String dialogTitle = Bundle.getString(
147: "org.netbeans.modules.beans.Bundle",
148: "CTL_TITLE_NewMultiCastES");
149: NbDialogOperator nbDialogOperator = new NbDialogOperator(
150: dialogTitle);
151:
152: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
153: nbDialogOperator, 0);
154: jComboBoxOperator
155: .setSelectedItem("java.awt.event.ActionListener");
156:
157: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
158: nbDialogOperator, Bundle.getString(
159: "org.netbeans.modules.beans.Bundle",
160: "CTL_EventSetPanel_emptyRadioButton"));
161: jRadioButtonOperator.push();
162:
163: new EventTool().waitNoEvent(2000);
164:
165: nbDialogOperator.ok();
166:
167: new JavaNode(repositoryRootNode, sampleDir + "|"
168: + NAME_TEST_FILE).open();
169:
170: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
171: ref(eo.getText());
172: compareReferenceFiles();
173: //
174: }
175:
176: public void testGenerateArrayListImplementation() {
177: //
178: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
179:
180: Node repositoryRootNode = explorerOperator.getRootNode();
181: Node patternsNode = new Node(repositoryRootNode, sampleDir
182: + "|"
183: + NAME_TEST_FILE
184: + "|"
185: + "class "
186: + NAME_TEST_FILE
187: + "|"
188: + Bundle.getString("org.netbeans.modules.beans.Bundle",
189: "Patterns"));
190: patternsNode.select();
191: patternsNode.performPopupActionNoBlock(Bundle.getString(
192: "org.openide.src.nodes.Bundle", "LAB_Add")
193: + "|"
194: + Bundle.getString("org.netbeans.modules.beans.Bundle",
195: "MENU_CREATE_MULTICASTSE"));
196: String dialogTitle = Bundle.getString(
197: "org.netbeans.modules.beans.Bundle",
198: "CTL_TITLE_NewMultiCastES");
199: NbDialogOperator nbDialogOperator = new NbDialogOperator(
200: dialogTitle);
201:
202: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
203: nbDialogOperator, 0);
204: jComboBoxOperator
205: .setSelectedItem("java.awt.event.ActionListener");
206:
207: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
208: nbDialogOperator, Bundle.getString(
209: "org.netbeans.modules.beans.Bundle",
210: "CTL_EventSetPanel_alRadioButton"));
211: jRadioButtonOperator.push();
212:
213: new EventTool().waitNoEvent(2000);
214:
215: nbDialogOperator.ok();
216:
217: new JavaNode(repositoryRootNode, sampleDir + "|"
218: + NAME_TEST_FILE).open();
219:
220: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
221: ref(eo.getText());
222: compareReferenceFiles();
223: //
224: }
225:
226: public void testGenerateEventListenerListImplementation() {
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_MULTICASTSE"));
246: String dialogTitle = Bundle.getString(
247: "org.netbeans.modules.beans.Bundle",
248: "CTL_TITLE_NewMultiCastES");
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_EventSetPanel_ellRadioButton"));
261: jRadioButtonOperator.push();
262:
263: new EventTool().waitNoEvent(3000);
264:
265: nbDialogOperator.ok();
266:
267: new JavaNode(repositoryRootNode, sampleDir + "|"
268: + NAME_TEST_FILE).open();
269:
270: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
271: ref(eo.getText());
272: compareReferenceFiles();
273: //
274: }
275:
276: public void testGenerateEventFiringMethods() {
277: //
278: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
279:
280: Node repositoryRootNode = explorerOperator.getRootNode();
281: Node patternsNode = new Node(repositoryRootNode, sampleDir
282: + "|"
283: + NAME_TEST_FILE
284: + "|"
285: + "class "
286: + NAME_TEST_FILE
287: + "|"
288: + Bundle.getString("org.netbeans.modules.beans.Bundle",
289: "Patterns"));
290: patternsNode.select();
291: patternsNode.performPopupActionNoBlock(Bundle.getString(
292: "org.openide.src.nodes.Bundle", "LAB_Add")
293: + "|"
294: + Bundle.getString("org.netbeans.modules.beans.Bundle",
295: "MENU_CREATE_MULTICASTSE"));
296: String dialogTitle = Bundle.getString(
297: "org.netbeans.modules.beans.Bundle",
298: "CTL_TITLE_NewMultiCastES");
299: NbDialogOperator nbDialogOperator = new NbDialogOperator(
300: dialogTitle);
301:
302: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
303: nbDialogOperator, 0);
304: jComboBoxOperator
305: .setSelectedItem("java.awt.event.ActionListener");
306:
307: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
308: nbDialogOperator, Bundle.getString(
309: "org.netbeans.modules.beans.Bundle",
310: "CTL_EventSetPanel_alRadioButton"));
311: jRadioButtonOperator.push();
312: JCheckBoxOperator jCheckBoxOperator = new JCheckBoxOperator(
313: nbDialogOperator, Bundle.getString(
314: "org.netbeans.modules.beans.Bundle",
315: "CTL_EventSetPanel_fireCheckBox"));
316: jCheckBoxOperator.push();
317:
318: new EventTool().waitNoEvent(3000);
319:
320: nbDialogOperator.ok();
321:
322: new JavaNode(repositoryRootNode, sampleDir + "|"
323: + NAME_TEST_FILE).open();
324:
325: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
326: ref(eo.getText());
327: compareReferenceFiles();
328: //
329: }
330:
331: public void testPassEventAsParameter() {
332: //
333: RepositoryTabOperator explorerOperator = new RepositoryTabOperator();
334:
335: Node repositoryRootNode = explorerOperator.getRootNode();
336: Node patternsNode = new Node(repositoryRootNode, sampleDir
337: + "|"
338: + NAME_TEST_FILE
339: + "|"
340: + "class "
341: + NAME_TEST_FILE
342: + "|"
343: + Bundle.getString("org.netbeans.modules.beans.Bundle",
344: "Patterns"));
345: patternsNode.select();
346: patternsNode.performPopupActionNoBlock(Bundle.getString(
347: "org.openide.src.nodes.Bundle", "LAB_Add")
348: + "|"
349: + Bundle.getString("org.netbeans.modules.beans.Bundle",
350: "MENU_CREATE_MULTICASTSE"));
351: String dialogTitle = Bundle.getString(
352: "org.netbeans.modules.beans.Bundle",
353: "CTL_TITLE_NewMultiCastES");
354: NbDialogOperator nbDialogOperator = new NbDialogOperator(
355: dialogTitle);
356:
357: JComboBoxOperator jComboBoxOperator = new JComboBoxOperator(
358: nbDialogOperator, 0);
359: jComboBoxOperator
360: .setSelectedItem("java.awt.event.ActionListener");
361:
362: JRadioButtonOperator jRadioButtonOperator = new JRadioButtonOperator(
363: nbDialogOperator, Bundle.getString(
364: "org.netbeans.modules.beans.Bundle",
365: "CTL_EventSetPanel_ellRadioButton"));
366: jRadioButtonOperator.push();
367: JCheckBoxOperator jCheckBoxOperator = new JCheckBoxOperator(
368: nbDialogOperator, Bundle.getString(
369: "org.netbeans.modules.beans.Bundle",
370: "CTL_EventSetPanel_fireCheckBox"));
371: jCheckBoxOperator.push();
372: jCheckBoxOperator = new JCheckBoxOperator(nbDialogOperator,
373: Bundle.getString("org.netbeans.modules.beans.Bundle",
374: "CTL_EventSetPanel_passEventCheckBox"));
375: jCheckBoxOperator.push();
376:
377: new EventTool().waitNoEvent(3000);
378:
379: nbDialogOperator.ok();
380:
381: new JavaNode(repositoryRootNode, sampleDir + "|"
382: + NAME_TEST_FILE).open();
383:
384: EditorOperator eo = new EditorOperator(NAME_TEST_FILE);
385: ref(eo.getText());
386: compareReferenceFiles();
387: //
388: }
389:
390: }
|