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 org.netbeans.jellytools.actions;
043:
044: import java.awt.event.KeyEvent;
045: import junit.framework.Test;
046: import junit.framework.TestSuite;
047: import junit.textui.TestRunner;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jellytools.EditorOperator;
050: import org.netbeans.jellytools.JellyTestCase;
051: import org.netbeans.jellytools.NbDialogOperator;
052: import org.netbeans.jellytools.NewFileWizardOperator;
053: import org.netbeans.jellytools.NewProjectWizardOperator;
054: import org.netbeans.jellytools.nodes.Node;
055: import org.netbeans.jellytools.nodes.SourcePackagesNode;
056: import org.netbeans.junit.NbTestSuite;
057:
058: /** Test of org.netbeans.jellytools.actions.ActionNoBlock
059: *
060: * @author <a href="mailto:adam.sotona@sun.com">Adam Sotona</a>
061: * @author Jiri.Skrivanek@sun.com
062: */
063: public class ActionNoBlockTest extends JellyTestCase {
064:
065: /** constructor required by JUnit
066: * @param testName method name to be used as testcase
067: */
068: public ActionNoBlockTest(String testName) {
069: super (testName);
070: }
071:
072: /** method used for explicit testsuite definition
073: */
074: public static Test suite() {
075: TestSuite suite = new NbTestSuite();
076: suite.addTest(new ActionNoBlockTest("testPerformMenu"));
077: suite.addTest(new ActionNoBlockTest("testPerformPopupOnNodes"));
078: suite.addTest(new ActionNoBlockTest(
079: "testPerformPopupOnComponent"));
080: suite.addTest(new ActionNoBlockTest("testPerformAPI"));
081: suite.addTest(new ActionNoBlockTest("testPerformShortcut"));
082: return suite;
083: }
084:
085: /** Use for internal test execution inside IDE
086: * @param args command line arguments
087: */
088: public static void main(java.lang.String[] args) {
089: TestRunner.run(suite());
090: }
091:
092: /** simple test case
093: */
094: public void testPerformMenu() {
095: /** File|New Project..." main menu path. */
096: String menuPath = Bundle.getStringTrimmed(
097: "org.netbeans.core.Bundle", "Menu/File")
098: + "|"
099: + Bundle
100: .getStringTrimmed(
101: "org.netbeans.modules.project.ui.actions.Bundle",
102: "LBL_NewProjectAction_Name");
103:
104: new ActionNoBlock(menuPath, null).perform();
105: new NewProjectWizardOperator().close();
106: }
107:
108: /** simple test case
109: */
110: public void testPerformPopupOnNodes() {
111: SourcePackagesNode sourceNode = new SourcePackagesNode(
112: "SampleProject");
113: Node nodes[] = {
114: new Node(sourceNode, "sample1|SampleClass1.java"), // NOI18N
115: new Node(sourceNode,
116: "sample1.sample2|SampleClass2.java") // NOI18N
117: };
118: String deletePopup = Bundle.getStringTrimmed(
119: "org.openide.actions.Bundle", "Delete");
120: new ActionNoBlock(null, deletePopup).perform(nodes);
121: // "Safe Delete"
122: String safeDeleteTitle = Bundle.getString(
123: "org.netbeans.modules.refactoring.spi.impl.Bundle",
124: "LBL_SafeDel"); // NOI18N
125: new NbDialogOperator(safeDeleteTitle).cancel();
126: String openPopup = Bundle.getStringTrimmed(
127: "org.openide.actions.Bundle", "Open");
128: new ActionNoBlock(null, openPopup).perform(nodes[0]);
129: }
130:
131: /** simple test case
132: */
133: public void testPerformPopupOnComponent() {
134: EditorOperator eo = new EditorOperator("SampleClass");// NOI18N
135: // "New Watch..."
136: String newWatchItem = Bundle.getString(
137: "org.netbeans.editor.Bundle", "add-watch");
138: new ActionNoBlock(null, newWatchItem).perform(eo);
139: // "New Watch"
140: String newWatchTitle = Bundle.getString(
141: "org.netbeans.modules.debugger.ui.actions.Bundle",
142: "CTL_WatchDialog_Title");
143: new NbDialogOperator(newWatchTitle).close();
144: eo.closeDiscard();
145: }
146:
147: /** simple test case
148: */
149: public void testPerformAPI() {
150: new NewFileAction().performAPI();
151: new NewFileWizardOperator().close();
152: }
153:
154: /** simple test case
155: */
156: public void testPerformShortcut() {
157: new ActionNoBlock(null, null, null,
158: new Action.Shortcut(KeyEvent.VK_N, KeyEvent.CTRL_MASK
159: | KeyEvent.SHIFT_MASK)).perform();
160: new NewProjectWizardOperator().close();
161: // On some linux it may happen autorepeat is activated and it
162: // opens dialog multiple times. So, we need to close all modal dialogs.
163: // See issue http://www.netbeans.org/issues/show_bug.cgi?id=56672.
164: closeAllModal();
165: }
166:
167: }
|