KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > docscan > SourceTaskProviderTest


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 package org.netbeans.modules.tasklist.docscan;
21
22 import java.io.File JavaDoc;
23 import org.openide.loaders.DataObject;
24 import org.openide.filesystems.Repository;
25 import java.net.URL JavaDoc;
26 import java.util.List JavaDoc;
27 import junit.framework.TestCase;
28 import org.netbeans.junit.NbTestCase;
29 import org.netbeans.modules.tasklist.providers.SuggestionContexts;
30 import org.netbeans.modules.tasklist.suggestions.Types;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileSystem;
33 import org.openide.filesystems.LocalFileSystem;
34
35 /**
36  * Test the source scanner list functionality
37  *
38  * @author Tor Norbye
39  */

40 public class SourceTaskProviderTest extends TestCase {
41
42     public SourceTaskProviderTest (String JavaDoc name) {
43         super (name);
44     }
45     
46     /** NB filesytem initialized during setUp. */
47     private FileSystem dataFS;
48
49     protected void setUp () throws Exception JavaDoc {
50         URL JavaDoc url = this.getClass().getResource("data");
51         String JavaDoc resString = NbTestCase.convertNBFSURL(url);
52         LocalFileSystem fs = new LocalFileSystem();
53         fs.setRootDirectory(new File JavaDoc(resString));
54         Repository.getDefault().addFileSystem(fs);
55         dataFS = fs;
56
57         Types.installSuggestionTypes();
58     }
59
60     protected void tearDown () throws Exception JavaDoc {
61         Repository.getDefault().removeFileSystem(dataFS);
62     }
63
64     /** Test the source scanner
65      * @todo: try Windows format (\r\n) and Macintosh format (\r) as well
66      * @todo: Try varying the options (regexp, etc.)
67      * and make sure the result is as expected
68      * @todo: Do a document edit and make sure the copyright fixer is disabled,
69      * line positions updated, etc.
70      * @todo: Try passing in different filenames (.java, .html, etc.) and
71      * see if the source scanner handles comments correctly
72     */

73     public void testSourceScanner() throws Exception JavaDoc {
74         Settings settings = Settings.getDefault();
75         settings.setSkipComments(true);
76         assertTrue("Skip Comments bean doesn't work", settings.getSkipComments());
77
78         SourceTaskProvider scanner = new SourceTaskProvider();
79         FileObject fo = dataFS.findResource("Comments.java");
80         DataObject dobj = DataObject.find(fo);
81         List JavaDoc result = scanner.scan(SuggestionContexts.forDataObject(dobj));
82
83         assertTrue(result.size() == 7);
84
85         // Make sure that the scanned list is correct
86

87         // Check that the list we read in is indeed correct
88
// Task root = list.getRoot();
89
// List subtasks = root.getSubtasks();
90
// assertTrue("Not all tasks in the list found: found " + subtasks.size() +
91
// " elements",
92
// subtasks.size() == 3);
93
// ListIterator it = subtasks.listIterator();
94
// int count = 0;
95
// while (it.hasNext()) {
96
// DocTask task = (DocTask)it.next();
97
// switch (count) {
98
// case 0: {
99
// assertEquals("Wrong copyright description",
100
// "Update Copyright to 1999-2002; currently is 1999",
101
// task.getSummary());
102
// assertEquals("Wrong line number", 1, task.getLineNumber());
103
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
104
// assertTrue("Missing fixer", task.getAction() != null);
105
// break;
106
// }
107
// case 1: {
108
// assertEquals("Wrong scanned description",
109
// "TODO fix this",
110
// task.getSummary());
111
// assertEquals("Wrong line number", 3, task.getLineNumber());
112
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
113
// break;
114
// }
115
// case 2: {
116
// assertEquals("Wrong scanned description",
117
// "XXX another one",
118
// task.getSummary());
119
// assertEquals("Wrong line number", 5, task.getLineNumber());
120
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
121
// break;
122
// }
123
// }
124
// count++;
125
// }
126
//
127
// settings.setSkipComments(false);
128
// // The testsuite isn't listening to TaskEdSettings changes? So jiggle
129
// // it.
130
// scanner.commentsToggled(false);
131
//
132
// scanner.scan(doc, dobj, true, true);
133
//
134
// // Check that the list we read in is indeed correct
135
// root = list.getRoot();
136
// subtasks = root.getSubtasks();
137
// assertTrue("Not all tasks in the list found: found " + subtasks.size() +
138
// " elements",
139
// subtasks.size() == 4);
140
// it = subtasks.listIterator();
141
// count = 0;
142
// while (it.hasNext()) {
143
// DocTask task = (DocTask)it.next();
144
// switch (count) {
145
// // TODO Update the below so it doesn't have 2002 but current
146
// // year - that way the testcase won't fail next year!
147
// case 0: {
148
// assertEquals("Wrong copyright description",
149
// "Update Copyright to 1999-2002; currently is 1999",
150
// task.getSummary());
151
// assertEquals("Wrong line number", 1, task.getLineNumber());
152
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
153
// assertTrue("Missing fixer", task.getAction() != null);
154
// break;
155
// }
156
// case 1: {
157
// assertEquals("Wrong scanned description",
158
// "int x = 0; // TODO fix this",
159
// task.getSummary());
160
// assertEquals("Wrong line number", 3, task.getLineNumber());
161
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
162
// break;
163
// }
164
// case 2: {
165
// assertEquals("Wrong scanned description",
166
// "int y = 5; // XXX another one",
167
// task.getSummary());
168
// assertEquals("Wrong line number", 5, task.getLineNumber());
169
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
170
// break;
171
// }
172
// case 3: {
173
// assertEquals("Wrong scanned description",
174
// "int XXX = 5; // outside of comment ignored?",
175
// task.getSummary());
176
// assertEquals("Wrong line number", 7, task.getLineNumber());
177
// assertEquals("Wrong filename", "foo.c", task.getFileBaseName());
178
// break;
179
// }
180
// }
181
// count++;
182
// }
183
//
184
//
185
}
186
187
188    /**
189     * Make sure we handle duplicates in the source correctly; see
190     * http://www.netbeans.org/issues/show_bug.cgi?id=27459
191     */

192     public void testDuplicates27459() throws Exception JavaDoc {
193
194        Settings settings = Settings.getDefault();
195        settings.setSkipComments(true);
196        assertTrue("Skip Comments bean doesn't work", settings.getSkipComments());
197
198        SourceTaskProvider scanner = new SourceTaskProvider();
199        FileObject fo = dataFS.findResource("iz27459.java");
200        DataObject dobj = DataObject.find(fo);
201        List JavaDoc result = scanner.scan(SuggestionContexts.forDataObject(dobj));
202
203        assertTrue(result.size() == 3);
204
205         // Make sure that the scanned list is correct
206

207 // // Check that the list we read in is indeed correct
208
// Task root = list.getRoot();
209
// List subtasks = root.getSubtasks();
210
// assertTrue("Not all tasks in the list found: found " + subtasks.size() +
211
// " elements",
212
// subtasks.size() == 3);
213
// ListIterator it = subtasks.listIterator();
214
// int count = 0;
215
// while (it.hasNext()) {
216
// DocTask task = (DocTask)it.next();
217
// switch (count) {
218
// case 0: {
219
// assertEquals("Wrong scanned description",
220
// "TODO Fix me!",
221
// task.getSummary());
222
// assertEquals("Wrong line number", 4, task.getLineNumber());
223
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
224
// break;
225
// }
226
// case 1: {
227
// assertEquals("Wrong scanned description",
228
// "OTHER FIXME",
229
// task.getSummary());
230
// assertEquals("Wrong line number", 5, task.getLineNumber());
231
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
232
// break;
233
// }
234
// case 2: {
235
// assertEquals("Wrong scanned description",
236
// "TODO Fix me!",
237
// task.getSummary());
238
// assertEquals("Wrong line number", 6, task.getLineNumber());
239
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
240
// break;
241
// }
242
// }
243
// count++;
244
// }
245
//
246
//
247
// try {
248
// doc.insertString(0, "TODO Fix me!\n", null);
249
// } catch (BadLocationException e) {
250
// fail("BadLocationException");
251
// }
252
//
253
// // scanner.rescan(); Can't use rescan; lastDocument not set
254
// // since we skipped scan(Node, boolean)
255
// scanner.scan(doc, dobj, false, true);
256
//
257
// // Check that the list we read in is indeed correct
258
// root = list.getRoot();
259
// subtasks = root.getSubtasks();
260
// assertTrue("Not all tasks in the list found: found " + subtasks.size() +
261
// " elements",
262
// subtasks.size() == 4);
263
// it = subtasks.listIterator();
264
// count = 0;
265
// while (it.hasNext()) {
266
// DocTask task = (DocTask)it.next();
267
// switch (count) {
268
// case 0: {
269
// assertEquals("Wrong scanned description",
270
// "TODO Fix me!",
271
// task.getSummary());
272
// assertEquals("Wrong line number", 7, task.getLineNumber());
273
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
274
// break;
275
// }
276
// case 1: {
277
// assertEquals("Wrong scanned description",
278
// "TODO Fix me!",
279
// task.getSummary());
280
// assertEquals("Wrong line number", 1, task.getLineNumber());
281
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
282
// break;
283
// }
284
// case 2: {
285
// assertEquals("Wrong scanned description",
286
// "OTHER FIXME",
287
// task.getSummary());
288
// assertEquals("Wrong line number", 6, task.getLineNumber());
289
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
290
// break;
291
// }
292
// case 3: {
293
// assertEquals("Wrong scanned description",
294
// "TODO Fix me!",
295
// task.getSummary());
296
// assertEquals("Wrong line number", 5, task.getLineNumber());
297
// assertEquals("Wrong filename", "foo", task.getFileBaseName());
298
// break;
299
// }
300
// }
301
// count++;
302
// }
303
}
304
305    /**
306     * Make sure that scanning a directory works correctly
307     */

308     public void testDirectoryScan() throws Exception JavaDoc {
309     // XXX todo
310

311 // DataObject folder = null;
312
// try {
313
// // Create filesystem where my to-be-scanned files are
314
// File data = new File (getClass ().getResource ("data").getFile ());
315
// LocalFileSystem lfs = new LocalFileSystem ();
316
// lfs.setRootDirectory (data);
317
// Repository.getDefault().addFileSystem(lfs);
318
//
319
// folder = DataObject.find (lfs.findResource("scanfiles"));
320
// assertTrue(folder != null);
321
// } catch (Exception e) {
322
// e.printStackTrace();
323
// throw e;
324
// }
325
//
326
//
327
//
328
// TaskList list = new TaskList(new DocTask("RootScanTask", null, null, 0));
329
// SourceScanner scanner = new SourceScanner(list, true);
330
// ScanTasksAction.scan(scanner, (DataFolder)folder, true);
331
//
332
// //System.err.println("After scan:");
333
// //list.print();
334
//
335
// assertTrue("Didn't get the correct number of list elements",
336
// list.size() == 2);
337
// Task root = list.getRoot();
338
// List subtasks = root.getSubtasks();
339
// assertTrue("Not all tasks in the list found: found " + subtasks.size() +
340
// " elements",
341
// subtasks.size() == 2);
342
// ListIterator it = subtasks.listIterator();
343
// DocTask task = (DocTask)it.next();
344
// assertTrue("Wrong element found in scanned list",
345
// task.getSummary().equals("TODO This is ANOTHER test") ||
346
// task.getSummary().equals("XXX This is a test"));
347
// // TODO -- better/more complete check - check both elements, filename,
348
// // etc.?
349
// /* Expecting:
350
// EditorTask["TODO This is ANOTHER test", /snorre/nb40/tasklist/test/work/sys/tests/unit/src/org/netbeans/modules/tasklist/docscan/data/scanfiles/test3.html:4]
351
// EditorTask["XXX This is a test", /snorre/nb40/tasklist/test/work/sys/tests/unit/src/org/netbeans/modules/tasklist/docscan/data/scanfiles/test2.html:2]
352
// */
353
}
354 }
355
Popular Tags