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.qa.form.visualDevelopment;
043:
044: import org.netbeans.jellytools.modules.form.ComponentInspectorOperator;
045: import org.netbeans.jellytools.modules.form.FormDesignerOperator;
046: import org.netbeans.junit.NbTestSuite;
047: import java.util.*;
048: import org.netbeans.jellytools.actions.*;
049: import org.netbeans.jellytools.*;
050: import org.netbeans.jellytools.nodes.Node;
051: import org.netbeans.jemmy.operators.Operator;
052: import org.netbeans.qa.form.ExtJellyTestCase;
053:
054: /**
055: * Menu and popup menu tests from NetBeans 5.5.1 Form Test Specification
056: * from Visual Development Test Specification
057: * @see <a href="http://qa.netbeans.org/modules/form/promo-f/testspecs/visualDevelopment.html">Test specification</a>
058: *
059: * @author Jiri Vagner
060: */
061: public class MenuAndPopupMenuTest extends ExtJellyTestCase {
062:
063: /** Constructor required by JUnit */
064: public MenuAndPopupMenuTest(String testName) {
065: super (testName);
066: }
067:
068: /* Method allowing to execute test directly from IDE. */
069: public static void main(java.lang.String[] args) {
070: junit.textui.TestRunner.run(suite());
071: }
072:
073: /** Creates suite from particular test cases. */
074: public static NbTestSuite suite() {
075:
076: NbTestSuite suite = new NbTestSuite();
077: suite.addTest(new MenuAndPopupMenuTest("testMenuCreation"));
078: suite
079: .addTest(new MenuAndPopupMenuTest(
080: "testPopupMenuCreation"));
081:
082: return suite;
083: }
084:
085: public void testMenuCreation() {
086: String menuPalettePath = "Add From Palette|";
087: String frameName = createJFrameFile();
088: ComponentInspectorOperator inspector = new ComponentInspectorOperator();
089: FormDesignerOperator designer = new FormDesignerOperator(
090: frameName);
091:
092: Node node = new Node(inspector.treeComponents(), "JFrame"); // NOI18N
093:
094: new Action(null, "Add From Palette|Swing Menus|Menu Bar")
095: .perform(node); // NOI18N
096: findInCode("jMenuBar1 = new javax.swing.JMenuBar();", designer); // NOI18N
097:
098: ArrayList<String> items = new ArrayList<String>();
099: items.add(menuPalettePath + "Menu Item"); // NOI18N
100: items.add(menuPalettePath + "Menu Item / CheckBox"); // NOI18N
101: items.add(menuPalettePath + "Menu Item / RadioButton"); // NOI18N
102: items.add(menuPalettePath + "Separator"); // NOI18N
103: items.add(menuPalettePath + "Menu"); // NOI18N
104:
105: Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(
106: true, false);
107:
108: node = new Node(inspector.treeComponents(),
109: "[JFrame]|jMenuBar1 [JMenuBar]|jMenu1 [JMenu]"); // NOI18N
110: runPopupOverNode(items, node, comparator);
111:
112: node = new Node(inspector.treeComponents(),
113: "[JFrame]|jMenuBar1 [JMenuBar]|jMenu1 [JMenu]|jMenu3 [JMenu]"); // NOI18N
114: runPopupOverNode(items, node, comparator);
115:
116: ArrayList<String> lines = new ArrayList<String>();
117: lines.add("jMenu3.add(jMenu4);"); // NOI18N
118: lines.add("jMenu1.add(jMenu3);"); // NOI18N
119: lines.add("jMenuBar1.add(jMenu1);"); // NOI18N
120: lines.add("setJMenuBar(jMenuBar1);"); // NOI18N
121: findInCode(lines, designer);
122:
123: removeFile(frameName);
124: }
125:
126: public void testPopupMenuCreation() {
127: String menuPalettePath = "Add From Palette|Swing Menus|";
128: String frameName = createJFrameFile();
129: ComponentInspectorOperator inspector = new ComponentInspectorOperator();
130: FormDesignerOperator designer = new FormDesignerOperator(
131: frameName);
132:
133: Node node = new Node(inspector.treeComponents(), "JFrame"); // NOI18N
134:
135: new Action(null, menuPalettePath + "Popup Menu").perform(node); // NOI18N
136: findInCode("jPopupMenu1 = new javax.swing.JPopupMenu();",
137: designer); // NOI18N
138:
139: ArrayList<String> items = new ArrayList<String>();
140: items.add(menuPalettePath + "Menu Item"); // NOI18N
141: items.add(menuPalettePath + "CheckBox Menu Item"); // NOI18N
142: items.add(menuPalettePath + "RadioButton Menu Item"); // NOI18N
143: items.add(menuPalettePath + "Separator"); // NOI18N
144: items.add(menuPalettePath + "Menu"); // NOI18N
145:
146: Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(
147: true, false);
148: node = new Node(inspector.treeComponents(),
149: "Other Components|jPopupMenu1 [JPopupMenu]"); // NOI18N
150:
151: // fails [Issue 116496] Unable to modify inserted PopupMenu
152: // runPopupOverNode(items, node, comparator);
153:
154: // TODO: tady to zkontrolovat, az ten test pojede
155: // ArrayList<String> lines = new ArrayList<String>();
156: // lines.add("jMenu3.add(jMenu4);"); // NOI18N
157: // lines.add("jMenu1.add(jMenu3);"); // NOI18N
158: // lines.add("jMenuBar1.add(jMenu1);"); // NOI18N
159: // lines.add("setJMenuBar(jMenuBar1);"); // NOI18N
160: // findInCode(lines, designer);
161:
162: removeFile(frameName);
163: }
164: }
|