Source Code Cross Referenced for ToDoTest.java in  » IDE-Netbeans » tasklist.projectint » org » netbeans » modules » tasklist » todo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » tasklist.projectint » org.netbeans.modules.tasklist.todo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.netbeans.modules.tasklist.todo;
002:
003:        /*
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
005:         *
006:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
007:         *
008:         * The contents of this file are subject to the terms of either the GNU
009:         * General Public License Version 2 only ("GPL") or the Common
010:         * Development and Distribution License("CDDL") (collectively, the
011:         * "License"). You may not use this file except in compliance with the
012:         * License. You can obtain a copy of the License at
013:         * http://www.netbeans.org/cddl-gplv2.html
014:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
015:         * specific language governing permissions and limitations under the
016:         * License.  When distributing the software, include this License Header
017:         * Notice in each file and include the License file at
018:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
019:         * particular file as subject to the "Classpath" exception as provided
020:         * by Sun in the GPL Version 2 section of the License file that
021:         * accompanied this code. If applicable, add the following below the
022:         * License Header, with the fields enclosed by brackets [] replaced by
023:         * your own identifying information:
024:         * "Portions Copyrighted [year] [name of copyright owner]"
025:         *
026:         * Contributor(s):
027:         *
028:         * The Original Software is NetBeans. The Initial Developer of the Original
029:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
030:         * Microsystems, Inc. All Rights Reserved.
031:         *
032:         * If you wish your version of this file to be governed by only the CDDL
033:         * or only the GPL Version 2, indicate your decision by adding
034:         * "[Contributor] elects to include this software in this distribution
035:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
036:         * single choice of license, a recipient has the option to distribute
037:         * your version of this file under either the CDDL, the GPL Version 2 or
038:         * to extend the choice of license to its licensees as provided above.
039:         * However, if you add GPL Version 2 code and therefore, elected the GPL
040:         * Version 2 license, then the option applies only if the new code is
041:         * made subject to such option by the copyright holder.
042:         */
043:
044:        import java.io.IOException;
045:        import java.io.OutputStreamWriter;
046:        import java.io.Writer;
047:        import java.util.ArrayList;
048:        import java.util.Collections;
049:        import java.util.List;
050:        import org.netbeans.api.project.Project;
051:        import org.netbeans.api.project.ui.OpenProjects;
052:        import org.netbeans.junit.MockServices;
053:        import org.netbeans.modules.apisupport.project.DialogDisplayerImpl;
054:        import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl;
055:        import org.netbeans.modules.apisupport.project.NbModuleProject;
056:        import org.netbeans.modules.apisupport.project.ProjectXMLManagerTest;
057:        import org.netbeans.modules.apisupport.project.TestBase;
058:        import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
059:        import org.netbeans.modules.apisupport.project.suite.SuiteProject;
060:        import org.netbeans.modules.tasklist.impl.CurrentEditorScanningScope;
061:        import org.netbeans.modules.tasklist.impl.TaskList;
062:        import org.netbeans.modules.tasklist.impl.TaskManagerImpl;
063:        import org.netbeans.modules.tasklist.impl.TaskManagerImplTest;
064:        import org.netbeans.modules.tasklist.projectint.MainProjectScanningScope;
065:        import org.netbeans.modules.tasklist.projectint.OpenedProjectsScanningScope;
066:        import org.netbeans.spi.tasklist.Task;
067:        import org.netbeans.spi.tasklist.TaskScanningScope;
068:        import org.openide.DialogDescriptor;
069:        import org.openide.filesystems.FileObject;
070:        import org.openide.loaders.DataObject;
071:        import org.openide.loaders.DataObjectNotFoundException;
072:        import org.openide.util.Lookup;
073:        import org.openide.util.lookup.Lookups;
074:        import org.openide.windows.TopComponent;
075:        import org.openide.windows.WindowManager;
076:
077:        /**
078:         * Tests ToDo scanner.
079:         *
080:         * @author Petr Zajac
081:         */
082:        public class ToDoTest extends TestBase {
083:
084:            static {
085:                // #65461: do not try to load ModuleInfo instances from ant module
086:                System.setProperty(
087:                        "org.netbeans.core.startup.ModuleSystem.CULPRIT",
088:                        "true");
089:                LayerTestBase.Lkp
090:                        .setLookup(new Object[] { new WindowManagerMock(),
091:                                new TopComponentRegistryMock() });
092:                DialogDisplayerImpl
093:                        .returnFromNotify(DialogDescriptor.NO_OPTION);
094:            }
095:
096:            public ToDoTest(String testName) {
097:                super (testName);
098:            }
099:
100:            protected void setUp() throws Exception {
101:                MockServices.setServices(TopComponentRegistryMock.class,
102:                        WindowManagerMock.class);
103:                clearWorkDir();
104:                noDataDir = true;
105:
106:                super .setUp();
107:                InstalledFileLocatorImpl.registerDestDir(destDirF);
108:            }
109:
110:            private static final String javaFile = "public class Main1 {\n"
111:                    + "/** TODO \n" + " * TODO \n" + "*/\n" + "}";
112:
113:            private static final String noToDoFile = "public class NoTodo {\n"
114:                    + "}";
115:
116:            static FileObject createSrcFile(NbModuleProject prj, String path,
117:                    String content) throws IOException {
118:                FileObject fo = prj.getSourceDirectory().createData(path);
119:                Writer writer = new OutputStreamWriter(fo.getOutputStream());
120:                writer.write(content);
121:                writer.close();
122:                return fo;
123:            }
124:
125:            private List<Task> scanOpenProjectsTasks() {
126:                return scanTasks(OpenedProjectsScanningScope.create());
127:            }
128:
129:            private List<Task> scanTasks(TaskScanningScope scope) {
130:                List<Task> tasks = new ArrayList<Task>();
131:                TodoTaskScanner tts = TodoTaskScanner.create();
132:                for (FileObject jfo : scope) {
133:                    List<? extends Task> filTasks = tts.scan(jfo);
134:                    if (filTasks != null) {
135:                        tasks.addAll(filTasks);
136:                    }
137:                }
138:                return tasks;
139:            }
140:
141:            private List<Task> scanMainProjectTasks() {
142:                return scanTasks(MainProjectScanningScope.create());
143:            }
144:
145:            private List<Task> scanCurrentEditorTasks() {
146:                CurrentEditorScanningScope scanScope = CurrentEditorScanningScope
147:                        .create();
148:                scanScope.run();
149:                return scanTasks(scanScope);
150:            }
151:
152:            public void testProject1() throws IOException {
153:                NbModuleProject prj1 = generateStandaloneModule(getWorkDir(),
154:                        "prj1");
155:                NbModuleProject prj2 = generateStandaloneModule(getWorkDir(),
156:                        "prj2");
157:                FileObject fo = createSrcFile(prj1, "Main.java", javaFile);
158:                FileObject fo2 = createSrcFile(prj1, "Main2.java", javaFile);
159:                FileObject fo3 = createSrcFile(prj2, "Main.java", javaFile);
160:                OpenProjects.getDefault().open(new Project[] { prj1, prj2 },
161:                        false);
162:
163:                List<Task> tasks = scanOpenProjectsTasks();
164:                assertEquals("Number of tasks", 6, tasks.size());
165:
166:                OpenProjects.getDefault().close(new Project[] { prj1 });
167:                tasks = scanOpenProjectsTasks();
168:                logTasks(tasks);
169:                assertEquals("Number of tasks", 2, tasks.size());
170:            }
171:
172:            public void testMainProject() throws Exception {
173:                NbModuleProject prj1 = generateStandaloneModule(getWorkDir(),
174:                        "prj1");
175:                NbModuleProject prj2 = generateStandaloneModule(getWorkDir(),
176:                        "prj2");
177:                FileObject fo = createSrcFile(prj1, "Main.java", javaFile);
178:                FileObject fo2 = createSrcFile(prj1, "Main2.java", javaFile);
179:                FileObject fo3 = createSrcFile(prj2, "Main.java", javaFile);
180:                OpenProjects.getDefault().open(new Project[] { prj1, prj2 },
181:                        false);
182:                OpenProjects.getDefault().setMainProject(prj1);
183:                List<Task> tasks = scanMainProjectTasks();
184:                assertEquals("Number of tasks", 4, tasks.size());
185:                OpenProjects.getDefault().close(new Project[] { prj1 });
186:                tasks = scanMainProjectTasks();
187:                assertEquals("Number of tasks", 0, tasks.size());
188:
189:                // test subproject
190:
191:                SuiteProject suite = generateSuite("suiteproject");
192:                NbModuleProject prj3 = generateSuiteComponent(suite,
193:                        getWorkDir(), "prjInSuite1");
194:                NbModuleProject prj4 = generateSuiteComponent(suite,
195:                        getWorkDir(), "prjInSuite2");
196:
197:                FileObject fo4 = createSrcFile(prj3, "Main.java", javaFile);
198:                FileObject fo5 = createSrcFile(prj4, "Main.java", javaFile);
199:                ProjectXMLManagerTest.addDependecy(prj3, prj4);
200:                OpenProjects.getDefault().open(
201:                        new Project[] { suite, prj3, prj4 }, false);
202:                OpenProjects.getDefault().setMainProject(prj4);
203:
204:                tasks = scanMainProjectTasks();
205:                assertEquals("Number of tasks", 4, tasks.size());
206:            }
207:
208:            public void testCurrentEditorScanningScope() throws IOException,
209:                    InterruptedException {
210:                MockServices.setServices(TopComponentRegistryMock.class,
211:                        WindowManagerMock.class);
212:                assertTrue(
213:                        "TopComponentRegistryMock ",
214:                        Lookup.getDefault().lookup(TopComponent.Registry.class) instanceof  TopComponentRegistryMock);
215:                assertTrue("WindowManagerMock ", Lookup.getDefault().lookup(
216:                        WindowManager.class) instanceof  WindowManagerMock);
217:                NbModuleProject prj1 = generateStandaloneModule(getWorkDir(),
218:                        "prj1");
219:                FileObject fo = createSrcFile(prj1, "Main.java", javaFile);
220:                FileObject fo2 = createSrcFile(prj1, "NoTo.java", noToDoFile);
221:
222:                List<Task> tasks = scanCurrentEditorTasks();
223:                assertEquals("No document opened", 0, tasks.size());
224:
225:                TopComponent tc = createTopComponent(fo);
226:                TopComponentRegistryMock registry = (TopComponentRegistryMock) org.openide.windows.TopComponent
227:                        .getRegistry();
228:                registry.setActivated(tc);
229:
230:                registry.setOpened(Collections.singleton(tc));
231:                WindowManagerMock wm = (WindowManagerMock) Lookup.getDefault()
232:                        .lookup(WindowManager.class);
233:                wm.setOpenedEditorTopComponent(tc);
234:                tasks = scanCurrentEditorTasks();
235:                assertEquals("Document with todo", 2, tasks.size());
236:
237:                tc = createTopComponent(fo2);
238:                registry.setActivated(tc);
239:
240:                registry.setOpened(Collections.singleton(tc));
241:                wm.setOpenedEditorTopComponent(tc);
242:                tasks = scanCurrentEditorTasks();
243:
244:                assertEquals("Document with no todo", 0, tasks.size());
245:            }
246:
247:            //    public void testTodoAndTaskManager() throws IOException, InterruptedException {
248:            //        NbModuleProject prj1 = generateStandaloneModule(getWorkDir(), "prj1");
249:            //        NbModuleProject prj2 = generateStandaloneModule(getWorkDir(), "prj2");
250:            //        FileObject fo = createSrcFile(prj1,"Main.java",javaFile);
251:            //        FileObject fo2 = createSrcFile(prj1,"Main2.java",javaFile);
252:            //        FileObject fo3 = createSrcFile(prj2,"Main.java",javaFile);
253:            //        OpenProjects.getDefault().open(new Project[]{prj1,prj2}, false);
254:            //
255:            //        TaskManagerImpl manager = TaskManagerImpl.getInstance();
256:            //        manager.observe(OpenedProjectsScanningScope.create(), null);
257:            //        TaskManagerImplTest.waitFinished(manager);
258:            //        TaskList tasks =  manager.getTasks();
259:            //        Thread.sleep(2000);
260:            //        assertEquals("Number of tasks",2,tasks.size());
261:            //        
262:            //    }
263:            private void logTasks(List<Task> tasks) {
264:                for (Task t : tasks) {
265:                    System.out.println(t);
266:                }
267:            }
268:
269:            private TopComponent createTopComponent(FileObject fo)
270:                    throws DataObjectNotFoundException {
271:                DataObject dobj = DataObject.find(fo);
272:                Lookup lookup = Lookups.fixed(dobj);
273:                return new TopComponent(lookup) {
274:                    public boolean isShowing() {
275:                        return true;
276:                    }
277:                };
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.