Source Code Cross Referenced for ContentProviderTests.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » tests » model » 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 Eclipse » jdt » org.eclipse.jdt.ui.tests.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.ui.tests.model;
011:
012:        import java.io.ByteArrayInputStream;
013:
014:        import junit.framework.TestCase;
015:
016:        import org.eclipse.core.runtime.CoreException;
017:
018:        import org.eclipse.core.resources.IFile;
019:        import org.eclipse.core.resources.IFolder;
020:        import org.eclipse.core.resources.IProject;
021:        import org.eclipse.core.resources.IWorkspace;
022:        import org.eclipse.core.resources.IWorkspaceDescription;
023:        import org.eclipse.core.resources.ResourcesPlugin;
024:
025:        import org.eclipse.jface.viewers.ITreeContentProvider;
026:
027:        import org.eclipse.ui.IViewPart;
028:        import org.eclipse.ui.IWorkbench;
029:        import org.eclipse.ui.IWorkbenchPage;
030:        import org.eclipse.ui.PlatformUI;
031:
032:        import org.eclipse.jdt.core.IJavaElement;
033:        import org.eclipse.jdt.core.IJavaProject;
034:        import org.eclipse.jdt.core.JavaCore;
035:
036:        import org.eclipse.jdt.testplugin.JavaProjectHelper;
037:
038:        public class ContentProviderTests extends TestCase {
039:
040:            private IWorkspace fWorkspace;
041:            private IJavaProject fJProject1;
042:            private boolean fEnableAutoBuildAfterTesting;
043:            private IWorkbench fWorkbench;
044:            private IWorkbenchPage fPage;
045:            private MockPluginView fMyPart;
046:            private ITreeContentProvider fProvider;
047:            private IJavaElement fPackageFragment1;
048:            private IJavaElement fPackageFragment2;
049:            private IFile fFile1;
050:
051:            protected void setUp() throws Exception {
052:                super .setUp();
053:
054:                fWorkspace = ResourcesPlugin.getWorkspace();
055:                assertNotNull(fWorkspace);
056:                IWorkspaceDescription workspaceDesc = fWorkspace
057:                        .getDescription();
058:                fEnableAutoBuildAfterTesting = workspaceDesc.isAutoBuilding();
059:                if (fEnableAutoBuildAfterTesting)
060:                    JavaProjectHelper.setAutoBuilding(false);
061:
062:                assertNotNull(fWorkspace);
063:
064:                fJProject1 = JavaProjectHelper.createJavaProject(
065:                        "TestProject1", "bin");//$NON-NLS-1$//$NON-NLS-2$
066:                assertNotNull("project1 null", fJProject1);//$NON-NLS-1$
067:                // Use the project root as the classpath
068:                fJProject1.setRawClasspath(null, null);
069:
070:                // Create some packages
071:                IProject project = (IProject) fJProject1.getResource();
072:                project.getFolder("f1").create(false, true, null);
073:                fPackageFragment1 = JavaCore.create(project.getFolder("f1"));
074:                project.getFolder("f2").create(false, true, null);
075:                fPackageFragment2 = JavaCore.create(project.getFolder("f2"));
076:
077:                //Create a non-Java file in one of the packges
078:                fFile1 = project.getFile("f1/b");
079:                fFile1.create(new ByteArrayInputStream("".getBytes()), false,
080:                        null);
081:
082:                setUpMockView();
083:            }
084:
085:            protected void tearDown() throws Exception {
086:                JavaProjectHelper.delete(fJProject1);
087:                if (fEnableAutoBuildAfterTesting)
088:                    JavaProjectHelper.setAutoBuilding(true);
089:                tearDownMockView();
090:                super .tearDown();
091:            }
092:
093:            private void setUpMockView() throws CoreException {
094:                fWorkbench = PlatformUI.getWorkbench();
095:                assertNotNull(fWorkbench);
096:
097:                fPage = fWorkbench.getActiveWorkbenchWindow().getActivePage();
098:                assertNotNull(fPage);
099:
100:                //just testing to make sure my part can be created
101:                IViewPart myPart = new MockPluginView();
102:                assertNotNull(myPart);
103:
104:                myPart = fPage
105:                        .showView("org.eclipse.jdt.ui.tests.model.MockPluginView");//$NON-NLS-1$
106:                if (myPart instanceof  MockPluginView) {
107:                    fMyPart = (MockPluginView) myPart;
108:                    fProvider = fMyPart.getContentProvider();
109:                    fMyPart.setProject(fJProject1);
110:                } else
111:                    assertTrue("Unable to get view", false);//$NON-NLS-1$
112:
113:                assertNotNull(fProvider);
114:            }
115:
116:            private void tearDownMockView() {
117:                fPage.hideView(fMyPart);
118:            }
119:
120:            private boolean compareArrays(Object[] children,
121:                    Object[] expectedChildren) {
122:                if (children.length != expectedChildren.length)
123:                    return false;
124:                for (int i = 0; i < children.length; i++) {
125:                    Object child = children[i];
126:                    if (!contains(child, expectedChildren))
127:                        return false;
128:                }
129:                return true;
130:            }
131:
132:            private boolean contains(Object expected, Object[] expectedChildren) {
133:                for (int i = 0; i < expectedChildren.length; i++) {
134:                    Object object = expectedChildren[i];
135:                    if (object.equals(expected))
136:                        return true;
137:                }
138:                return false;
139:            }
140:
141:            public void testOutgoingDeletion148118() throws CoreException {
142:                IProject project = (IProject) fJProject1.getResource();
143:                fMyPart.addOutgoingDeletion(project, "f1/a");
144:                fMyPart.addOutgoingDeletion(project, "f2/a");
145:                fMyPart.addOutgoingDeletion(project, "f3/");
146:
147:                // Children of project
148:                Object[] expectedChildren = new Object[] { fPackageFragment1,
149:                        fPackageFragment2, project.getFolder("f3/") };
150:                Object[] children = fProvider.getChildren(fJProject1);
151:                assertTrue(
152:                        "Expected children of project does not match actual children",
153:                        compareArrays(children, expectedChildren));
154:
155:                // Children of fragment 1
156:                expectedChildren = new Object[] {
157:                        fFile1,
158:                        ((IFolder) fPackageFragment1.getResource())
159:                                .getFile("a") };
160:                children = fProvider.getChildren(fPackageFragment1);
161:
162:                // Children of fragment 2
163:                expectedChildren = new Object[] { ((IFolder) fPackageFragment2
164:                        .getResource()).getFile("a") };
165:                children = fProvider.getChildren(fPackageFragment2);
166:            }
167:
168:            public void testIncomingAddition159884() throws CoreException {
169:                IProject project = (IProject) fJProject1.getResource();
170:                fMyPart.addIncomingAddition(project, "f1/newFolder/");
171:                fMyPart.addIncomingAddition(project, "f1/newFolder/a");
172:
173:                // Children of project
174:                IFolder f1 = project.getFolder("f1");
175:                Object[] expectedChildren = new Object[] { f1 };
176:                Object[] children = fProvider.getChildren(fJProject1);
177:                assertTrue(
178:                        "Expected children of project does not match actual children",
179:                        compareArrays(children, expectedChildren));
180:
181:                IFolder addedFolder = project.getFolder("f1/newFolder");
182:
183:                // Children of f1
184:                expectedChildren = new Object[] { addedFolder };
185:                children = fProvider.getChildren(f1);
186:                assertTrue(
187:                        "Expected children of f1 does not match actual children",
188:                        compareArrays(children, expectedChildren));
189:
190:                // Children of newFolder
191:
192:                expectedChildren = new Object[] { addedFolder.getFile("a") };
193:                children = fProvider.getChildren(addedFolder);
194:                assertTrue(
195:                        "Expected children of new folder does not match actual children",
196:                        compareArrays(children, expectedChildren));
197:            }
198:
199:            public void testIncomingAddition159884Part2() throws CoreException {
200:                IProject project = (IProject) fJProject1.getResource();
201:                fMyPart.addIncomingAddition(project, "f1/newFolder/a");
202:
203:                // Children of project
204:                IFolder f1 = project.getFolder("f1");
205:                Object[] expectedChildren = new Object[] { f1 };
206:                Object[] children = fProvider.getChildren(fJProject1);
207:                assertTrue(
208:                        "Expected children of project does not match actual children",
209:                        compareArrays(children, expectedChildren));
210:
211:                IFolder addedFolder = project.getFolder("f1/newFolder");
212:
213:                // Children of f1
214:                expectedChildren = new Object[] { addedFolder };
215:                children = fProvider.getChildren(f1);
216:                assertTrue(
217:                        "Expected children of f1 does not match actual children",
218:                        compareArrays(children, expectedChildren));
219:
220:                // Children of newFolder
221:
222:                expectedChildren = new Object[] { addedFolder.getFile("a") };
223:                children = fProvider.getChildren(addedFolder);
224:                assertTrue(
225:                        "Expected children of new folder does not match actual children",
226:                        compareArrays(children, expectedChildren));
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.