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: package org.netbeans.test.java.editor.codegeneration;
042:
043: import junit.textui.TestRunner;
044: import org.netbeans.jellytools.EditorOperator;
045: import org.netbeans.jellytools.MainWindowOperator;
046: import org.netbeans.jellytools.actions.Action;
047: import org.netbeans.jemmy.operators.JTreeOperator;
048: import org.netbeans.test.java.editor.jelly.GenerateCodeOperator;
049: import org.netbeans.test.java.editor.jelly.GenerateConstructorOperator;
050:
051: /**
052: *
053: * @author Jiri Prox Jiri.Prox@Sun.COM
054: */
055: public class CreateConstructor extends GenerateCode {
056:
057: /** Creates a new instance of CreateConstructor */
058: public CreateConstructor(String name) {
059: super (name);
060: }
061:
062: public void testSuperConstructor() {
063: openSourceFile("org.netbeans.test.java.editor.codegeneration",
064: "testSimpleCase");
065: editor = new EditorOperator("testSimpleCase");
066: txtOper = editor.txtEditorPane();
067: try {
068: editor.requestFocus();
069: editor.setCaretPosition(12, 1);
070: GenerateCodeOperator.openDialog(
071: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
072: GenerateConstructorOperator gco = new GenerateConstructorOperator();
073: JTreeOperator jto = gco.treeTreeView$ExplorerTree();
074: jto.selectRow(2);
075: gco.btOK().push();
076: String expected = ""
077: + " public testSimpleCase(ThreadGroup group, Runnable target) {\n"
078: + " super(group, target);\n" + " }\n";
079: waitAndCompare(expected);
080: } finally {
081: editor.close(false);
082: }
083: }
084:
085: public void testInitFields() {
086: openSourceFile("org.netbeans.test.java.editor.codegeneration",
087: "testSimpleCase");
088: editor = new EditorOperator("testSimpleCase");
089: txtOper = editor.txtEditorPane();
090: try {
091: editor.requestFocus();
092: editor.setCaretPosition(12, 1);
093: GenerateCodeOperator.openDialog(
094: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
095: GenerateConstructorOperator gco = new GenerateConstructorOperator();
096: JTreeOperator jto = gco.treeTreeView$ExplorerTree2();
097: jto.selectRow(1);
098: gco.btOK().push();
099: String expected = ""
100: + " public testSimpleCase(int b) {\n"
101: + " this.b = b;\n" + " }\n";
102: waitAndCompare(expected);
103: } finally {
104: editor.close(false);
105: }
106: }
107:
108: public void testInitFieldAndSuper() {
109: openSourceFile("org.netbeans.test.java.editor.codegeneration",
110: "testSimpleCase");
111: editor = new EditorOperator("testSimpleCase");
112: txtOper = editor.txtEditorPane();
113: try {
114: editor.requestFocus();
115: editor.setCaretPosition(12, 1);
116: GenerateCodeOperator.openDialog(
117: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
118: GenerateConstructorOperator gco = new GenerateConstructorOperator();
119: JTreeOperator jto = gco.treeTreeView$ExplorerTree();
120: jto.selectRow(7);
121: jto = gco.treeTreeView$ExplorerTree2();
122: jto.selectRow(2);
123: gco.btOK().push();
124: String expected = ""
125: + " public testSimpleCase(ThreadGroup group, Runnable target, String name, long stackSize, double c) {\n"
126: + " super(group, target, name, stackSize);\n"
127: + " this.c = c;\n" + " }\n";
128: waitAndCompare(expected);
129: } finally {
130: editor.close(false);
131: }
132: }
133:
134: public void testMultipleSuperSelection() {
135: openSourceFile("org.netbeans.test.java.editor.codegeneration",
136: "testSimpleCase");
137: editor = new EditorOperator("testSimpleCase");
138: txtOper = editor.txtEditorPane();
139: try {
140: editor.requestFocus();
141: editor.setCaretPosition(12, 1);
142: GenerateCodeOperator.openDialog(
143: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
144: GenerateConstructorOperator gco = new GenerateConstructorOperator();
145: JTreeOperator jto = gco.treeTreeView$ExplorerTree();
146: jto.selectRow(2);
147: jto.selectRow(3);
148: jto.selectRow(4);
149: jto.selectRow(7);
150: gco.btOK().push();
151: String expected = ""
152: + " public testSimpleCase(ThreadGroup group, Runnable target, String name, long stackSize) {\n"
153: + " super(group, target, name, stackSize);\n"
154: + " }\n";
155: waitAndCompare(expected);
156: } finally {
157: editor.close(false);
158: }
159: }
160:
161: public void testMultipleFiledSelection() {
162: openSourceFile("org.netbeans.test.java.editor.codegeneration",
163: "testSimpleCase");
164: editor = new EditorOperator("testSimpleCase");
165: txtOper = editor.txtEditorPane();
166: try {
167: editor.requestFocus();
168: editor.setCaretPosition(12, 1);
169: GenerateCodeOperator.openDialog(
170: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
171: GenerateConstructorOperator gco = new GenerateConstructorOperator();
172: JTreeOperator jto = gco.treeTreeView$ExplorerTree2();
173: jto.selectRow(0);
174: jto.selectRow(1);
175: jto.selectRow(2);
176: jto.selectRow(0);
177: gco.btOK().push();
178: String expected = ""
179: + " public testSimpleCase(int b, double c) {\n"
180: + " this.b = b;\n" + " this.c = c;\n"
181: + " }";
182: waitAndCompare(expected);
183: } finally {
184: editor.close(false);
185: }
186: }
187:
188: public void testCancel() {
189: openSourceFile("org.netbeans.test.java.editor.codegeneration",
190: "testSimpleCase");
191: editor = new EditorOperator("testSimpleCase");
192: txtOper = editor.txtEditorPane();
193: try {
194: editor.requestFocus();
195: editor.setCaretPosition(12, 1);
196: GenerateCodeOperator.openDialog(
197: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
198: GenerateConstructorOperator gco = new GenerateConstructorOperator();
199: JTreeOperator jto = gco.treeTreeView$ExplorerTree2();
200: jto.selectRow(1);
201: gco.btCancel().push();
202: String expected = ""
203: + "public class testSimpleCase extends Thread {\n"
204: + " \n"
205: + " private String a;\n"
206: + " \n"
207: + " int b;\n"
208: + " \n"
209: + " public double c;\n"
210: + " \n"
211: + " \n"
212: + " \n"
213: + " /** Creates a new instance of testSimpleCase */\n"
214: + " public testSimpleCase() {\n" + " }\n"
215: + " \n" + "}\n";
216: waitAndCompare(expected);
217: } finally {
218: editor.close(false);
219: }
220: }
221:
222: public void testUndoRedo() {
223: openSourceFile("org.netbeans.test.java.editor.codegeneration",
224: "testSimpleCase");
225: editor = new EditorOperator("testSimpleCase");
226: txtOper = editor.txtEditorPane();
227: try {
228: editor.requestFocus();
229: editor.setCaretPosition(12, 1);
230: GenerateCodeOperator.openDialog(
231: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
232: GenerateConstructorOperator gco = new GenerateConstructorOperator();
233: JTreeOperator jto = gco.treeTreeView$ExplorerTree2();
234: jto.selectRow(0);
235: gco.btOK().push();
236: String expected = ""
237: + " public testSimpleCase(String a) {\n"
238: + " this.a = a;\n" + " }";
239: waitAndCompare(expected);
240: new Action("Edit|Undo", null).perform();
241: assertFalse("Constuctor not removed", contains(editor
242: .getText(), expected));
243: MainWindowOperator.getDefault().menuBar().pushMenu("Edit");
244: MainWindowOperator.getDefault().menuBar().closeSubmenus();
245: new Action("Edit|Redo", null).perform();
246: assertTrue("Constuctor not re-inserted", contains(editor
247: .getText(), expected));
248: } finally {
249: editor.close(false);
250: }
251: }
252:
253: public void testInnerClass() {
254: openSourceFile("org.netbeans.test.java.editor.codegeneration",
255: "TestInnerClass");
256: editor = new EditorOperator("TestInnerClass");
257: txtOper = editor.txtEditorPane();
258: try {
259: editor.requestFocus();
260: editor.setCaretPosition(20, 1);
261: GenerateCodeOperator.openDialog(
262: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
263: GenerateConstructorOperator gco = new GenerateConstructorOperator();
264: JTreeOperator jto = gco.treeTreeView$ExplorerTree();
265: jto.selectRow(0);
266: gco.btOK().push();
267: String expected = ""
268: + " public Inner(String afield) {\n"
269: + " this.afield = afield;\n"
270: + " }\n";
271: waitAndCompare(expected);
272: } finally {
273: editor.close(false);
274: }
275: }
276:
277: public void testIssue100341() {
278: openSourceFile("org.netbeans.test.java.editor.codegeneration",
279: "test100341b");
280: editor = new EditorOperator("test100341b");
281: txtOper = editor.txtEditorPane();
282: try {
283: editor.requestFocus();
284: editor.setCaretPosition(13, 1);
285: GenerateCodeOperator.openDialog(
286: GenerateCodeOperator.GENERATE_CONSTRUCTOR, editor);
287: String expected = ""
288: + " public test100341b(String data) {\n"
289: + " super(data);\n" + " }\n";
290: waitAndCompare(expected);
291: } finally {
292: editor.close(false);
293: }
294: }
295:
296: public static void main(String[] args) {
297: TestRunner.run(CreateConstructor.class);
298: }
299: }
|