KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > junit > testcreation > CreateTestTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * CreateTestTest.java
22  *
23  * Created on August 2, 2006, 1:39 PM
24  */

25
26 package org.netbeans.test.junit.testcreation;
27
28 import org.netbeans.jellytools.Bundle;
29 import org.netbeans.jellytools.EditorOperator;
30 import org.netbeans.jellytools.NbDialogOperator;
31 import org.netbeans.jellytools.NewFileWizardOperator;
32 import org.netbeans.jellytools.nodes.Node;
33 import org.netbeans.jemmy.operators.JButtonOperator;
34 import org.netbeans.jemmy.operators.JCheckBoxOperator;
35 import org.netbeans.jemmy.operators.JPopupMenuOperator;
36 import org.netbeans.jemmy.operators.JTextFieldOperator;
37 import org.netbeans.junit.NbTestSuite;
38 import org.netbeans.test.junit.testcase.JunitTestCase;
39 import org.netbeans.test.junit.utils.Utilities;
40
41 /**
42  *
43  * @author ms159439
44  */

45 public class CreateTestTest extends JunitTestCase {
46     
47     /** path to sample files */
48     private static final String JavaDoc TEST_PACKAGE_PATH =
49             "org.netbeans.test.junit.testcreation";
50     
51     /** name of sample package */
52     private static final String JavaDoc TEST_PACKAGE_NAME = TEST_PACKAGE_PATH+".test";
53     
54     /**
55      * Creates a new instance of CreateTestTest
56      */

57     public CreateTestTest(String JavaDoc testName) {
58         super(testName);
59     }
60     
61     /**
62      * Adds tests to suite
63      * @return created suite
64      */

65     public static NbTestSuite suite() {
66         NbTestSuite suite = new NbTestSuite(CreateTestTest.class);
67         return suite;
68     }
69     
70     /**
71      * Test creation accessed from popup menu
72      * With default options (checkboxes)
73      */

74     public void testCreateTestByPopup() {
75         //open sample class
76
Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
77                 "|" + TEST_PACKAGE_NAME+ "|" + Utilities.TEST_CLASS_NAME);
78         
79         Utilities.pushCreateTestsPopup(n);
80         
81         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
82         ndo.btOK().push(); //defaults checked
83
Utilities.takeANap(Utilities.ACTION_TIMEOUT);
84         
85         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
86         compareReferenceFiles();
87     }
88     
89     /**
90      * Test creation accessed from popup menu
91      * Without public methods
92      */

93     public void testCreateTestByPopup2() {
94         Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
95                 "|" + TEST_PACKAGE_NAME);
96         
97         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
98                 "|" + TEST_PACKAGE_NAME+ "|" + Utilities.TEST_CLASS_NAME);
99         
100         Utilities.pushCreateTestsPopup(n);
101         
102         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
103         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 0);//public methods
104
jbo.clickMouse();
105         ndo.btOK().push();
106         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
107         
108         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME +
109                 "Test.java").getText()));
110         compareReferenceFiles();
111     }
112     
113     /**
114      * Test creation accessed from popup menu
115      * Without public methods and w/o protected methods
116      */

117     public void testCreateTestByPopup3() {
118         //necessary to delete created tests from testCreateTestByPopup2
119
Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
120                 "|" + TEST_PACKAGE_NAME);
121         
122         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
123                 "|" + TEST_PACKAGE_NAME+ "|" + Utilities.TEST_CLASS_NAME);
124         
125         Utilities.pushCreateTestsPopup(n);
126         
127         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
128         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 1);//protected methods
129
jbo.clickMouse();
130         ndo.btOK().push();
131         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
132         
133         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
134         compareReferenceFiles();
135     }
136     
137     /**
138      * Test creation accessed from popup menu
139      * Without public methods and w/o protected methods and w/o friendly
140      * should allow to create anything -- OK should be disabled
141      */

142     public void testCreateTestByPopup4() {
143         //necessary to delete created tests from testCreateTestByPopup3
144
Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
145                 "|" + TEST_PACKAGE_NAME);
146         
147         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
148                 "|" + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
149         Utilities.pushCreateTestsPopup(n);
150         
151         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
152         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 2);//friendly methods
153
jbo.clickMouse();
154         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
155         assertFalse(ndo.btOK().isEnabled()); // OK button should be disabled
156
ndo.btCancel().push(); //cancel the dialog
157
}
158     
159     /**
160      * Test creation w/o setUp()
161      */

162     public void testCreateWOsetUp() {
163         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
164                 "|" + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
165         Utilities.pushCreateTestsPopup(n);
166         
167         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
168         Utilities.checkAllCheckboxes(ndo);
169         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 3);//setUp methods
170
jbo.clickMouse();
171         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
172         ndo.btOK().push();
173         
174         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
175         compareReferenceFiles();
176     }
177     
178     /**
179      * Test creation w/o tearDown()
180      */

181     public void testCreateWOtearDown() {
182         //necessary to delete created tests from testCreateTestWOsetUp
183
Utilities.takeANap(Utilities.ACTION_TIMEOUT);
184         Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
185                 "|" + TEST_PACKAGE_NAME);
186         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
187         
188         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
189                 "|" + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
190         Utilities.pushCreateTestsPopup(n);
191         
192         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
193         Utilities.checkAllCheckboxes(ndo);
194         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 4);//tearDown methods
195
jbo.clickMouse();
196         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
197         ndo.btOK().push();
198         
199         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
200         compareReferenceFiles();
201     }
202     
203     /**
204      * Test creation w/o default method bodies
205      */

206     public void testCreateWODefMethodBodies() {
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, 5);//methods bodies
220
jbo.clickMouse();
221         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
222         ndo.btOK().push();
223         
224         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
225         compareReferenceFiles();
226     }
227     
228     /**
229      * Test creation w/o javdoc comments
230      */

231     public void testCreateWOJavadoc() {
232         //necessary to delete created tests from testCreateTestWOsetUp
233
Utilities.takeANap(Utilities.ACTION_TIMEOUT);
234         Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
235                 "|" + TEST_PACKAGE_NAME);
236         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
237         
238         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
239                 "|" + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
240         Utilities.pushCreateTestsPopup(n);
241         
242         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
243         Utilities.checkAllCheckboxes(ndo);
244         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 6);//javadoc
245

246         jbo.clickMouse();
247         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
248         ndo.btOK().push();
249         
250         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
251         compareReferenceFiles();
252     }
253     
254     /**
255      * Test creation w/o source code hints()
256      */

257     public void testCreateWOHints() {
258         //necessary to delete created tests from testCreateTestWOsetUp
259
Utilities.takeANap(Utilities.ACTION_TIMEOUT);
260         Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
261                 "|" + TEST_PACKAGE_NAME);
262         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
263         
264         Node n = Utilities.openFile(Utilities.SRC_PACKAGES_PATH +
265                 "|" + TEST_PACKAGE_NAME + "|" + Utilities.TEST_CLASS_NAME);
266         Utilities.pushCreateTestsPopup(n);
267         
268         NbDialogOperator ndo = new NbDialogOperator(CREATE_TESTS_DIALOG);
269         Utilities.checkAllCheckboxes(ndo);
270         JCheckBoxOperator jbo = new JCheckBoxOperator(ndo, 7);//hints
271

272         jbo.clickMouse();
273         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
274         ndo.btOK().push();
275         
276         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
277         compareReferenceFiles();
278     }
279     
280     /**
281      * Test creation accessed from wizard
282      */

283     public void testCreateTestByWizard() {
284         //necessary to delete created tests previous
285
Utilities.takeANap(Utilities.ACTION_TIMEOUT);
286         Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
287                 "|" + TEST_PACKAGE_NAME);
288         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
289         
290         NewFileWizardOperator op = NewFileWizardOperator.invoke();
291         op.selectCategory(Bundle.getString(Utilities.JUNIT_BUNDLE,
292                 "Templates/JUnit"));
293         op.selectFileType(Bundle.getString(Utilities.JUNIT_BUNDLE,
294                 "Templates/JUnit/SimpleJUnitTest.java"));
295         op.next();
296         new JTextFieldOperator(op,0).
297                 setText("org.netbeans.test.junit.testcreation.test.TestClass");
298         op.finish();
299         Utilities.takeANap(Utilities.ACTION_TIMEOUT);
300         
301         ref(filter.filter(new EditorOperator(Utilities.TEST_CLASS_NAME + "Test.java").getText()));
302         compareReferenceFiles();
303         
304         //For some resaon, this couses test to fail
305
// Utilities.deleteNode(Utilities.TEST_PACKAGES_PATH +
306
// "|" + TEST_PACKAGE_NAME);
307
}
308     
309 }
310
Popular Tags