### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java,v retrieving revision 1.18 diff -u -r1.18 MigrationPatchesTest.java --- src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java 29 May 2007 13:41:34 -0000 1.18 +++ src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java 4 Jun 2007 16:45:33 -0000 @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -36,15 +37,20 @@ import org.eclipse.gmf.gmfgraph.Canvas; import org.eclipse.gmf.gmfgraph.Compartment; import org.eclipse.gmf.gmfgraph.Connection; +import org.eclipse.gmf.gmfgraph.CustomFigure; import org.eclipse.gmf.gmfgraph.DiagramLabel; import org.eclipse.gmf.gmfgraph.Figure; import org.eclipse.gmf.gmfgraph.FigureDescriptor; import org.eclipse.gmf.gmfgraph.FigureGallery; import org.eclipse.gmf.gmfgraph.FlowLayout; +import org.eclipse.gmf.gmfgraph.GMFGraphPackage; import org.eclipse.gmf.gmfgraph.Label; import org.eclipse.gmf.gmfgraph.LabeledContainer; +import org.eclipse.gmf.gmfgraph.LineKind; import org.eclipse.gmf.gmfgraph.Node; import org.eclipse.gmf.gmfgraph.PolylineConnection; +import org.eclipse.gmf.gmfgraph.PolylineDecoration; +import org.eclipse.gmf.gmfgraph.RealFigure; import org.eclipse.gmf.gmfgraph.Rectangle; import org.eclipse.gmf.internal.common.ToolingResourceFactory; import org.eclipse.gmf.internal.common.migrate.MigrationResource; @@ -459,7 +465,7 @@ URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "basic", "gmfgraph"); changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition"); - //assertOnLoadModelMigrationDidNothing(newUri); + assertOnLoadModelMigrationDidNothing(newUri); checkAllFigureReferences(newUri); } @@ -479,9 +485,16 @@ FigureGallery fg = canvas.getFigures().get(0); assertEquals("GenericDiagramFigures", fg.getName()); - assertTrue(fg.getFigures().isEmpty()); + assertFalse(fg.getFigures().isEmpty()); + assertEquals(1, fg.getFigures().size()); + + Figure figure0 = fg.getFigures().get(0); + assertTrue(figure0 instanceof PolylineDecoration); + PolylineDecoration linked = (PolylineDecoration) figure0; + assertEquals("ArrowDecoration", linked.getName()); + assertFalse(fg.getDescriptors().isEmpty()); - assertEquals(5, fg.getDescriptors().size()); + assertEquals(6, fg.getDescriptors().size()); FigureDescriptor fg1 = fg.getDescriptors().get(0); assertTrue(fg1.getAccessors().isEmpty()); @@ -545,6 +558,16 @@ assertEquals(1, nnr.getDescriptor().getAccessors().size()); assertEquals(nnrLabel, nnr.getDescriptor().getAccessors().get(0).getFigure()); + Figure figure6 = fg.getDescriptors().get(5).getActualFigure(); + assertTrue(figure6 instanceof PolylineConnection); + PolylineConnection fcf = (PolylineConnection) figure6; + assertEquals("FigureConnectionFigure", fcf.getName()); + assertEquals(LineKind.LINE_DASHDOT_LITERAL, fcf.getLineKind()); + assertNotNull(fcf.getTargetDecoration()); + assertEquals(linked, fcf.getTargetDecoration()); + assertNotNull(fcf.getDescriptor()); + assertEquals(fcf, fcf.getDescriptor().getActualFigure()); + assertNotNull(canvas.getNodes()); assertFalse(canvas.getNodes().isEmpty()); assertEquals(2, canvas.getNodes().size()); @@ -583,4 +606,129 @@ assertEquals("LabelWOIcon", l3.getName()); } + public void testCustomFigures() throws Exception { + assertTrue(((EClass)GMFGraphPackage.eINSTANCE.getFigureAccessor_TypedFigure().getEType()).isAbstract()); + + URI gmfgraphFileName = createURI("customFigures.gmfgraph"); //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(gmfgraphFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(gmfgraphFileName); + checkCustomFiguresContent(gmfgraphFileName); + + URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "customFigures", "gmfgraph"); + changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition"); + + assertOnLoadModelMigrationDidNothing(newUri); + checkCustomFiguresContent(newUri); + } + + private void checkCustomFiguresContent(URI modelUri) { + ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), modelUri); + Resource resource = loadHelper.getLoadedResource(); + + assertEquals(1, resource.getContents().size()); + Object first = resource.getContents().get(0); + assertTrue(first instanceof Canvas); + Canvas canvas = (Canvas) first; + assertEquals(7, canvas.eContents().size()); + + assertNotNull(canvas.getFigures()); + assertEquals(1, canvas.getFigures().size()); + FigureGallery fg = canvas.getFigures().get(0); + + assertNotNull(fg.getFigures()); + assertEquals(3, fg.getFigures().size()); + + Figure figure1 = fg.getFigures().get(0); + assertTrue(figure1 instanceof CustomFigure); + assertEquals("org.eclipse.draw2d.ScalableFigure", ((CustomFigure)figure1).getQualifiedClassName()); + + assertNotNull(fg.getDescriptors()); + assertEquals(4, fg.getDescriptors().size()); + + Figure node1figure = fg.getDescriptors().get(0).getActualFigure(); + assertNotNull(node1figure); + assertTrue(node1figure instanceof CustomFigure); + assertEquals(1, ((CustomFigure) node1figure).getCustomChildren().size()); + RealFigure compartment2figure = ((CustomFigure) node1figure).getCustomChildren().get(0).getTypedFigure(); + assertNotNull(compartment2figure); + assertTrue(compartment2figure instanceof CustomFigure); + assertEquals("org.eclipse.draw2d.IFigure", ((CustomFigure)compartment2figure).getQualifiedClassName()); + + Figure node2figure = fg.getDescriptors().get(1).getActualFigure(); + assertNotNull(node2figure); + assertTrue(node2figure instanceof CustomFigure); + assertEquals(1, ((CustomFigure) node2figure).getCustomChildren().size()); + RealFigure compartment1figure = ((CustomFigure) node2figure).getCustomChildren().get(0).getTypedFigure(); + assertNotNull(compartment1figure); + + Figure node3figure = fg.getDescriptors().get(2).getActualFigure(); + assertNotNull(node3figure); + assertTrue(node3figure instanceof CustomFigure); + assertEquals(1, ((CustomFigure) node3figure).getCustomChildren().size()); + RealFigure compartment4figure = ((CustomFigure) node3figure).getCustomChildren().get(0).getTypedFigure(); + assertNotNull(compartment4figure); + assertTrue(compartment4figure instanceof CustomFigure); + assertEquals("org.eclipse.draw2d.ScalableFigure", ((CustomFigure)compartment4figure).getQualifiedClassName()); + assertNotNull(node3figure); + + Figure compartment3figure = fg.getDescriptors().get(3).getActualFigure(); + assertNotNull(compartment3figure); + + assertNotNull(canvas.getNodes()); + assertEquals(2, canvas.getNodes().size()); + + Node node1 = canvas.getNodes().get(0); + assertEquals("LocalPreconditionNode", node1.getName()); + assertNotNull(node1.getFigure()); + assertEquals(node1figure, node1.getFigure().getActualFigure()); + + Node node2 = canvas.getNodes().get(1); + assertEquals("LocalPostconditionNode", node2.getName()); + assertNotNull(node2.getFigure()); + assertEquals(node2figure, node2.getFigure().getActualFigure()); + + assertNotNull(canvas.getCompartments()); + assertEquals(4, canvas.getCompartments().size()); + + Compartment compartment1 = canvas.getCompartments().get(0); + assertEquals("postcondition", compartment1.getName()); + assertNotNull(compartment1.getFigure()); + assertNotNull(compartment1.getAccessor()); + assertEquals(compartment1figure, compartment1.getAccessor().getFigure()); + + Compartment compartment2 = canvas.getCompartments().get(1); + assertEquals("precondition", compartment2.getName()); + assertNotNull(compartment2.getFigure()); + assertNotNull(compartment2.getAccessor()); + assertEquals(compartment2figure, compartment2.getAccessor().getFigure()); + + Compartment compartment3 = canvas.getCompartments().get(2); + assertEquals("anotherPostcondition", compartment3.getName()); + assertNotNull(compartment3.getFigure()); + assertNull(compartment3.getAccessor()); + + Compartment compartment4 = canvas.getCompartments().get(3); + assertEquals("TargetCustomDecorCompartment", compartment4.getName()); + assertNotNull(compartment4.getFigure()); + assertNotNull(compartment4.getAccessor()); + assertEquals(compartment4figure, compartment4.getAccessor().getFigure()); + } + + public void testMultifiles() throws Exception { + URI gmfgraphFileName = createURI("multifile_main.gmfgraph"); //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(gmfgraphFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(gmfgraphFileName); + + URI newUri = temporarySaveMigratedModel(gmfgraphFileName, "multifile_main", "gmfgraph"); + changeNsUriToOldOne(newUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition"); + + assertOnLoadModelMigrationDidNothing(newUri); + } + } Index: src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java,v retrieving revision 1.10 diff -u -r1.10 GenericMigrationTest.java --- src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java 24 May 2007 09:34:38 -0000 1.10 +++ src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java 4 Jun 2007 16:45:33 -0000 @@ -484,8 +484,8 @@ } @Override - public void postProcess() { - super.postProcess(); + public void preResolve() { + super.preResolve(); for (EObject narrowed : myToBeChecked) { if (!narrowed.eIsSet(myAttrNarrowChild)) { EObject defaultTyped = narrowed.eClass().getEPackage().getEFactoryInstance().create((EClass) myWidenedRef1.getEType()); Index: src/org/eclipse/gmf/tests/migration/GMFGraphMigrationTest.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GMFGraphMigrationTest.java,v retrieving revision 1.2 diff -u -r1.2 GMFGraphMigrationTest.java --- src/org/eclipse/gmf/tests/migration/GMFGraphMigrationTest.java 28 May 2007 13:47:47 -0000 1.2 +++ src/org/eclipse/gmf/tests/migration/GMFGraphMigrationTest.java 4 Jun 2007 16:45:33 -0000 @@ -21,8 +21,8 @@ import junit.framework.Test; import junit.framework.TestCase; -import junit.framework.TestResult; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.EList; @@ -56,37 +56,35 @@ } public void testFile() throws Exception { - assertNoOrdinaryLoadModelProblems(myGMFGraphFileURI); - - //assertOrdinaryLoadModelProblems(gmfgraphFileURI); + assertPossibleProblemsOnOrdinaryLoad(myGMFGraphFileURI); - //assertOnLoadModelMigrationSuccess(gmfgraphFileURI); + assertSuccessOnMigrationLoad(myGMFGraphFileURI); URI newGenUri = temporarySaveMigratedModel(myGMFGraphFileURI, myGMFGraphFileURI.trimFileExtension().lastSegment(), myGMFGraphFileURI.fileExtension()); changeNsUriToOldOne(newGenUri, "gmfgraph", "http://www.eclipse.org/gmf/2005/GraphicalDefinition"); //$NON-NLS-1$ //$NON-NLS-2$ - //assertOnLoadModelMigrationDidNothing(newGenUri); - - assertNoOrdinaryLoadModelProblems(newGenUri); + assertOnSecondLoadModelMigrationDidNothing(newGenUri); } - static void assertOnLoadModelMigrationSuccess(URI uri) throws Exception { + static void assertSuccessOnMigrationLoad(URI uri) throws Exception { ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri); EList errors = loadHelper.getLoadedResource().getErrors(); assertTrue("Errors found after migration ("+uri+"): "+errors, errors.isEmpty()); //$NON-NLS-1$ //$NON-NLS-2$ - assertTrue("Migration warning load status expected for "+uri, loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$ EList warnings = loadHelper.getLoadedResource().getWarnings(); - assertEquals("Single Warning diagnostic expected for "+uri, 1, warnings.size()); //$NON-NLS-1$ - assertTrue("MigrationDiagnostic expected as warning for "+uri, warnings.get(0) instanceof MigrationResource.Diagnostic); //$NON-NLS-1$ + if (!warnings.isEmpty()) { + assertTrue("Migration warning load status expected for "+uri, loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$ + assertEquals("Single Warning diagnostic expected for "+uri, 1, warnings.size()); //$NON-NLS-1$ + assertTrue("MigrationDiagnostic expected as warning for "+uri, warnings.get(0) instanceof MigrationResource.Diagnostic); //$NON-NLS-1$ + } assertTrue(loadHelper.getLoadedResource() instanceof XMLResource); XMLResource xmlResource = (XMLResource) loadHelper.getLoadedResource(); assertEquals("Unknown elements were recorded after migration of "+uri, 0, xmlResource.getEObjectToExtensionMap().size()); //$NON-NLS-1$ } - static void assertOnLoadModelMigrationDidNothing(URI uri) throws Exception { + static void assertOnSecondLoadModelMigrationDidNothing(URI uri) throws Exception { ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri); EList errors = loadHelper.getLoadedResource().getErrors(); @@ -117,7 +115,7 @@ } - static Exception assertOrdinaryLoadModelProblems(URI uri) throws Exception { + static boolean assertPossibleProblemsOnOrdinaryLoad(URI uri) throws Exception { Resource resource = new ToolingResourceFactory().createResource(uri); ResourceSet rset = new ResourceSetImpl(); rset.getResources().add(resource); @@ -128,9 +126,8 @@ } catch (RuntimeException e) { caughtException = e; } - assertTrue("Expected model loading problems for "+uri, //$NON-NLS-1$ - caughtException != null || !resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()); - return caughtException; + boolean hadProblems = caughtException != null || !resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty(); + return hadProblems; } private static URI temporarySaveMigratedModel(URI uri, String tempFilename, String tempFileExtension) throws IOException { @@ -143,7 +140,7 @@ try { resource.save(null); } catch (IOException ex) { - fail(ex.toString()); + fail("["+uri+"] Migrated resource save failed: "+ex.toString()); } return newUri; } @@ -164,9 +161,6 @@ private static Collection collectAllGMFGraphFiles(String rootFolder) { Collection result = new ArrayList(); File root = new File(rootFolder); - if (!root.isDirectory()) { - root = root.getParentFile(); - } collectFilesRecursive(root, result, new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".gmfgraph"); //$NON-NLS-1$ @@ -190,7 +184,12 @@ public static Collection createAllTests() { Collection result = new ArrayList(100); - for (URI gmfgraphFileURI : collectAllGMFGraphFiles(File.listRoots()[0].getAbsolutePath())) { //$NON-NLS-1$ + File workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile(); + String rootPath = workspaceRoot.getAbsolutePath(); + if (workspaceRoot.getParentFile() != null) { + rootPath = workspaceRoot.getParentFile().getAbsolutePath(); + } + for (URI gmfgraphFileURI : collectAllGMFGraphFiles(rootPath)) { GMFGraphFileTest test = new GMFGraphFileTest(gmfgraphFileURI); result.add(test); } Index: src/org/eclipse/gmf/tests/migration/AllMigrationTests.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/AllMigrationTests.java,v retrieving revision 1.3 diff -u -r1.3 AllMigrationTests.java --- src/org/eclipse/gmf/tests/migration/AllMigrationTests.java 28 May 2007 13:43:42 -0000 1.3 +++ src/org/eclipse/gmf/tests/migration/AllMigrationTests.java 4 Jun 2007 16:45:33 -0000 @@ -22,7 +22,7 @@ suite.addTestSuite(GenericMigrationTest.class); suite.addTestSuite(MigrationPatchesTest.class); for (TestCase fileTest : GMFGraphMigrationTest.createAllTests()) { - //suite.addTest(fileTest); + suite.addTest(fileTest); } //$JUnit-END$ return suite; Index: models/migration/basic.gmfgraph =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests/models/migration/basic.gmfgraph,v retrieving revision 1.1 diff -u -r1.1 basic.gmfgraph --- models/migration/basic.gmfgraph 28 May 2007 13:43:42 -0000 1.1 +++ models/migration/basic.gmfgraph 4 Jun 2007 16:45:33 -0000 @@ -49,6 +49,23 @@ referencingElements="NamedNode_Name" name="NamedNode_NameLabelFigure"/> + + +