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: /*
043: * CreateTestTest.java
044: *
045: * Created on August 2, 2006, 1:39 PM
046: */
047:
048: package org.netbeans.test.junit.testcreation;
049:
050: import org.netbeans.jellytools.Bundle;
051: import org.netbeans.jellytools.EditorOperator;
052: import org.netbeans.jellytools.NbDialogOperator;
053: import org.netbeans.jellytools.NewFileWizardOperator;
054: import org.netbeans.jellytools.nodes.Node;
055: import org.netbeans.jemmy.operators.JButtonOperator;
056: import org.netbeans.jemmy.operators.JCheckBoxOperator;
057: import org.netbeans.jemmy.operators.JPopupMenuOperator;
058: import org.netbeans.jemmy.operators.JTextFieldOperator;
059: import org.netbeans.junit.NbTestSuite;
060: import org.netbeans.test.junit.testcase.JunitTestCase;
061: import org.netbeans.test.junit.utils.Utilities;
062:
063: /**
064: *
065: * @author ms159439
066: */
067: public class CreateTestTest extends JunitTestCase {
068:
069: /** path to sample files */
070: private static final String TEST_PACKAGE_PATH = "org.netbeans.test.junit.testcreation";
071:
072: /** name of sample package */
073: private static final String TEST_PACKAGE_NAME = TEST_PACKAGE_PATH
074: + ".test";
075:
076: /**
077: * Creates a new instance of CreateTestTest
078: */
079: public CreateTestTest(String testName) {
080: super (testName);
081: }
082:
083: /**
084: * Adds tests to suite
085: * @return created suite
086: */
087: public static NbTestSuite suite() {
088: NbTestSuite suite = new NbTestSuite(CreateTestTest.class);
089: return suite;
090: }
091:
092: /**
093: * Test creation accessed from popup menu
094: * With default options (checkboxes)
095: */
096: public void testCreateTestByPopup() {
097: //open sample class
098: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
099: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
100:
101: Utilities.pushCreateTestsPopup(n);
102:
103: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
104: ndo.btOK().push(); //defaults checked
105: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
106:
107: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
108: + "Test.java").getText()));
109: compareReferenceFiles();
110: }
111:
112: /**
113: * Test creation accessed from popup menu
114: * Without public methods
115: */
116: public void testCreateTestByPopup2() {
117: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
118: + TEST_PACKAGE_NAME);
119:
120: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
121: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
122:
123: Utilities.pushCreateTestsPopup(n);
124:
125: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
126: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 0);//public methods
127: jbo.clickMouse();
128: ndo.btOK().push();
129: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
130:
131: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
132: + "Test.java").getText()));
133: compareReferenceFiles();
134: }
135:
136: /**
137: * Test creation accessed from popup menu
138: * Without public methods and w/o protected methods
139: */
140: public void testCreateTestByPopup3() {
141: //necessary to delete created tests from testCreateTestByPopup2
142: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
143: + TEST_PACKAGE_NAME);
144:
145: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
146: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
147:
148: Utilities.pushCreateTestsPopup(n);
149:
150: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
151: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 1);//protected methods
152: jbo.clickMouse();
153: ndo.btOK().push();
154: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
155:
156: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
157: + "Test.java").getText()));
158: compareReferenceFiles();
159: }
160:
161: /**
162: * Test creation accessed from popup menu
163: * Without public methods and w/o protected methods and w/o friendly
164: * should allow to create anything -- OK should be disabled
165: */
166: public void testCreateTestByPopup4() {
167: //necessary to delete created tests from testCreateTestByPopup3
168: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
169: + TEST_PACKAGE_NAME);
170:
171: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
172: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
173: Utilities.pushCreateTestsPopup(n);
174:
175: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
176: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 2);//friendly methods
177: jbo.clickMouse();
178: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
179: assertFalse(ndo.btOK().isEnabled()); // OK button should be disabled
180: ndo.btCancel().push(); //cancel the dialog
181: }
182:
183: /**
184: * Test creation w/o setUp()
185: */
186: public void testCreateWOsetUp() {
187: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
188: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
189: Utilities.pushCreateTestsPopup(n);
190:
191: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
192: Utilities.checkAllCheckboxes(ndo);
193: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 3);//setUp methods
194: jbo.clickMouse();
195: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
196: ndo.btOK().push();
197:
198: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
199: + "Test.java").getText()));
200: compareReferenceFiles();
201: }
202:
203: /**
204: * Test creation w/o tearDown()
205: */
206: public void testCreateWOtearDown() {
207: //necessary to delete created tests from testCreateTestWOsetUp
208: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
209: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
210: + TEST_PACKAGE_NAME);
211: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
212:
213: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
214: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
215: Utilities.pushCreateTestsPopup(n);
216:
217: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
218: Utilities.checkAllCheckboxes(ndo);
219: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 4);//tearDown methods
220: jbo.clickMouse();
221: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
222: ndo.btOK().push();
223:
224: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
225: + "Test.java").getText()));
226: compareReferenceFiles();
227: }
228:
229: /**
230: * Test creation w/o default method bodies
231: */
232: public void testCreateWODefMethodBodies() {
233: //necessary to delete created tests from testCreateTestWOsetUp
234: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
235: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
236: + TEST_PACKAGE_NAME);
237: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
238:
239: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
240: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
241: Utilities.pushCreateTestsPopup(n);
242:
243: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
244: Utilities.checkAllCheckboxes(ndo);
245: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 5);//methods bodies
246: jbo.clickMouse();
247: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
248: ndo.btOK().push();
249:
250: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
251: + "Test.java").getText()));
252: compareReferenceFiles();
253: }
254:
255: /**
256: * Test creation w/o javdoc comments
257: */
258: public void testCreateWOJavadoc() {
259: //necessary to delete created tests from testCreateTestWOsetUp
260: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
261: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
262: + TEST_PACKAGE_NAME);
263: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
264:
265: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
266: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
267: Utilities.pushCreateTestsPopup(n);
268:
269: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
270: Utilities.checkAllCheckboxes(ndo);
271: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 6);//javadoc
272:
273: jbo.clickMouse();
274: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
275: ndo.btOK().push();
276:
277: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
278: + "Test.java").getText()));
279: compareReferenceFiles();
280: }
281:
282: /**
283: * Test creation w/o source code hints()
284: */
285: public void testCreateWOHints() {
286: //necessary to delete created tests from testCreateTestWOsetUp
287: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
288: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
289: + TEST_PACKAGE_NAME);
290: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
291:
292: Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH + "|"
293: + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
294: Utilities.pushCreateTestsPopup(n);
295:
296: NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
297: Utilities.checkAllCheckboxes(ndo);
298: JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 7);//hints
299:
300: jbo.clickMouse();
301: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
302: ndo.btOK().push();
303:
304: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
305: + "Test.java").getText()));
306: compareReferenceFiles();
307: }
308:
309: /**
310: * Test creation accessed from wizard
311: */
312: public void testCreateTestByWizard() {
313: //necessary to delete created tests previous
314: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
315: Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH + "|"
316: + TEST_PACKAGE_NAME);
317: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
318:
319: NewFileWizardOperator op = NewFileWizardOperator.invoke();
320: op.selectCategory(Bundle.getString(Utilities.JUNIT_BUNDLE,
321: "Templates/JUnit"));
322: op.selectFileType(Bundle.getString(Utilities.JUNIT_BUNDLE,
323: "Templates/JUnit/SimpleJUnitTest.java"));
324: op.next();
325: new JTextFieldOperator(op, 0)
326: .setText("org.netbeans.test.junit.testcreation.test.TestClass");
327: op.finish();
328: Utilities.takeANap(Utilities.ACTION_TIMEOUT);
329:
330: ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME
331: + "Test.java").getText()));
332: compareReferenceFiles();
333:
334: //For some resaon, this couses test to fail
335: // Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
336: // "|" + TEST_PACKAGE_NAME);
337: }
338:
339: }
|