[Pydev-cvs] org.python.pydev/tests_navigator/org/python/pydev/navigator PythonModelProviderTest.ja
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-05-10 16:29:33
|
Update of /cvsroot/pydev/org.python.pydev/tests_navigator/org/python/pydev/navigator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16453/tests_navigator/org/python/pydev/navigator Modified Files: PythonModelProviderTest.java ProjectStub.java Log Message: Pydev model provider for project explorer: Better handling of null objects when intercepting them / interaction with other models. Index: ProjectStub.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests_navigator/org/python/pydev/navigator/ProjectStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ProjectStub.java 8 Sep 2007 16:36:12 -0000 1.4 --- ProjectStub.java 10 May 2008 16:29:24 -0000 1.5 *************** *** 5,8 **** --- 5,9 ---- import java.util.ArrayList; import java.util.HashMap; + import java.util.List; import java.util.Map; *************** *** 43,51 **** --- 44,66 ---- private IContainer parent; + + private boolean addNullChild; + + private List<Object> additionalChildren; public ProjectStub(File file, IPythonNature nature) { + this(file, nature, false); + } + + public ProjectStub(File file, IPythonNature nature, boolean addNullChild) { + this(file, nature, addNullChild, new ArrayList<Object>()); + } + + public ProjectStub(File file, IPythonNature nature, boolean addNullChild, List<Object> additionalChildren) { Assert.isTrue(file.exists() && file.isDirectory()); this.projectRoot = file; this.nature = nature; + this.addNullChild = addNullChild; + this.additionalChildren = additionalChildren; } *************** *** 605,609 **** throw new RuntimeException("Shouldn't happen"); } ! ArrayList<IResource> ret = new ArrayList<IResource>(); for(File file:folder.listFiles()){ if(file.getName().toLowerCase().equals("cvs")){ --- 620,624 ---- throw new RuntimeException("Shouldn't happen"); } ! ArrayList<Object> ret = new ArrayList<Object>(); for(File file:folder.listFiles()){ if(file.getName().toLowerCase().equals("cvs")){ *************** *** 616,619 **** --- 631,638 ---- } } + if(addNullChild){ + ret.add(null); + } + ret.addAll(this.additionalChildren); return ret.toArray(); } Index: PythonModelProviderTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests_navigator/org/python/pydev/navigator/PythonModelProviderTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PythonModelProviderTest.java 9 May 2008 01:10:13 -0000 1.9 --- PythonModelProviderTest.java 10 May 2008 16:29:24 -0000 1.10 *************** *** 28,32 **** PythonModelProviderTest test = new PythonModelProviderTest(); test.setUp(); ! test.testCreateChildrenInWrappedResource(); test.tearDown(); --- 28,32 ---- PythonModelProviderTest test = new PythonModelProviderTest(); test.setUp(); ! test.testProjectIsRoot2(); test.tearDown(); *************** *** 56,63 **** HashSet<Object> files = new HashSet<Object>(); files.add(file); provider.interceptAdd(new PipelinedShapeModification(file.getParent(), files)); ! assertEquals(1, files.size()); ! Object wrappedResource = files.iterator().next(); ! assertTrue(wrappedResource instanceof IWrappedResource); } --- 56,68 ---- HashSet<Object> files = new HashSet<Object>(); files.add(file); + files.add(null); + files.add("string"); provider.interceptAdd(new PipelinedShapeModification(file.getParent(), files)); ! assertEquals(2, files.size()); ! for(Object wrappedResource:files){ ! assertTrue((wrappedResource instanceof IWrappedResource && ! ((IWrappedResource)wrappedResource).getActualObject() == file)|| ! wrappedResource.equals("string")); ! } } *************** *** 73,81 **** PipelinedViewerUpdate update = new PipelinedViewerUpdate(); ! Set<IResource> refreshTargets = update.getRefreshTargets(); refreshTargets.add(project); provider.interceptRefresh(update); ! IResource wrappedResource = refreshTargets.iterator().next(); ! assertTrue(wrappedResource == project); } --- 78,90 ---- PipelinedViewerUpdate update = new PipelinedViewerUpdate(); ! Set<Object> refreshTargets = update.getRefreshTargets(); refreshTargets.add(project); + refreshTargets.add(null); + refreshTargets.add("string"); provider.interceptRefresh(update); ! assertEquals(2, refreshTargets.size()); ! for (Object wrappedResource:refreshTargets){ ! assertTrue(wrappedResource == project || wrappedResource.equals("string")); ! } } *************** *** 83,86 **** --- 92,125 ---- * Test if setting the project root as a source folder will return an object from the python model. */ + public void testProjectIsRoot2() throws Exception { + String pythonpathLoc = TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"; + final HashSet<String> pythonPathSet = new HashSet<String>(); + pythonPathSet.add(pythonpathLoc); + + PythonNature nature = createNature(pythonPathSet); + + WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub(); + project = new ProjectStub(new File(pythonpathLoc), nature); + provider = new PythonModelProvider(); + FolderStub folder = new FolderStub(project, new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot/source")); + + workspaceRootStub.addChild(project); + project.setParent(workspaceRootStub); + + HashSet<Object> folders = new HashSet<Object>(); + folders.add(folder); + PipelinedShapeModification addModification = new PipelinedShapeModification(project, folders); + addModification.setParent(project); + provider.interceptAdd(addModification); + + assertEquals(1, addModification.getChildren().size()); + //it should've been wrapped + assertTrue(addModification.getChildren().iterator().next() instanceof IWrappedResource); + } + + + /** + * Test if setting the project root as a source folder will return an object from the python model. + */ public void testProjectIsRoot() throws Exception { String pythonpathLoc = TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"; *************** *** 95,103 **** workspaceRootStub.addChild(project); project.setParent(workspaceRootStub); Object[] children1 = provider.getChildren(workspaceRootStub); ! assertEquals(1, children1.length); ! assertTrue("Expecting source folder. Received: "+children1[0].getClass().getName(), children1[0] instanceof PythonSourceFolder); //now, let's go and change the pythonpath location to a folder within the project and see if it changes... --- 134,162 ---- workspaceRootStub.addChild(project); + workspaceRootStub.addChild(null); + workspaceRootStub.addChild("other"); project.setParent(workspaceRootStub); + Object[] children1 = provider.getChildren(workspaceRootStub); ! assertEquals(2, children1.length); ! int stringsFound=0; ! int projectSourceFoldersFound=0; ! for (Object c : children1) { ! if(c instanceof String){ ! stringsFound+=1; ! ! }else if(c instanceof PythonProjectSourceFolder){ ! projectSourceFoldersFound+=1; ! ! }else{ ! fail("Expecting source folder or string. Received: "+c.getClass().getName()); ! } ! } ! assertEquals(1, stringsFound); ! assertEquals(1, projectSourceFoldersFound); ! ! ! //now, let's go and change the pythonpath location to a folder within the project and see if it changes... *************** *** 108,114 **** children1 = provider.getChildren(workspaceRootStub); ! assertEquals(1, children1.length); ! assertTrue("Expecting IProject. Received: "+children1[0].getClass().getName(), children1[0] instanceof IProject); ! //set to be the root again pythonPathSet.clear(); --- 167,188 ---- children1 = provider.getChildren(workspaceRootStub); ! assertEquals(2, children1.length); ! stringsFound=0; ! int projectsFound=0; ! for (Object c : children1) { ! if(c instanceof String){ ! stringsFound+=1; ! ! }else if(c instanceof IProject){ ! projectsFound+=1; ! ! }else{ ! fail("Expecting source folder or string. Received: "+c.getClass().getName()); ! } ! } ! assertEquals(1, stringsFound); ! assertEquals(1, projectsFound); ! ! //set to be the root again pythonPathSet.clear(); *************** *** 149,155 **** final HashSet<String> pythonPathSet = new HashSet<String>(); pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot/source"); PythonNature nature = createNature(pythonPathSet); ! project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"), nature); provider = new PythonModelProvider(); Object[] children1 = provider.getChildren(project); --- 223,230 ---- final HashSet<String> pythonPathSet = new HashSet<String>(); pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot/source"); + pythonPathSet.add("invalid"); PythonNature nature = createNature(pythonPathSet); ! project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"), nature, true); provider = new PythonModelProvider(); Object[] children1 = provider.getChildren(project); *************** *** 221,225 **** WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub(); ! project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"), nature); workspaceRootStub.addChild(project); project.setParent(workspaceRootStub); --- 296,302 ---- WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub(); ! ArrayList<Object> additionalChildren = new ArrayList<Object>(); ! additionalChildren.add("string"); ! project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"), nature, true, additionalChildren); workspaceRootStub.addChild(project); project.setParent(workspaceRootStub); *************** *** 230,233 **** --- 307,311 ---- HashSet<Object> currentChildren = new HashSet<Object>(); currentChildren.add(project); + currentChildren.add(null); provider.getPipelinedChildren(workspaceRootStub, currentChildren); *************** *** 236,241 **** --- 314,350 ---- currentChildren = new HashSet<Object>(); + currentChildren.add(null); provider.getPipelinedChildren(projectSourceFolder, currentChildren); + assertEquals(2, currentChildren.size()); + } + + public void testNullElements() throws Exception { + final HashSet<String> pythonPathSet = new HashSet<String>(); + pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"); //root is the source + PythonNature nature = createNature(pythonPathSet); + + + WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub(); + project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC+"projroot"), nature); + workspaceRootStub.addChild(project); + project.setParent(workspaceRootStub); + + + provider = new PythonModelProvider(); + + HashSet<Object> currentChildren = new HashSet<Object>(); + currentChildren.add(project); + currentChildren.add(null); + provider.getPipelinedChildren(workspaceRootStub, currentChildren); + + assertEquals(1, currentChildren.size()); + PythonProjectSourceFolder projectSourceFolder = (PythonProjectSourceFolder) currentChildren.iterator().next(); + + currentChildren = new HashSet<Object>(); + currentChildren.add(null); + currentChildren.add(null); + provider.getPipelinedChildren(projectSourceFolder, currentChildren); + assertEquals(1, currentChildren.size()); } |