Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormfeldman2007-05-20 08:54:35 -0400
committermfeldman2007-05-20 08:54:35 -0400
commit0094715b074687c5905d32b89ec22493e8888176 (patch)
tree26cb92762762f1e44db3874329edf20053ce0310
parent0455c1e9a618bc64d40641efdad1f0865dc2adfe (diff)
downloadorg.eclipse.gmf-tooling-0094715b074687c5905d32b89ec22493e8888176.tar.gz
org.eclipse.gmf-tooling-0094715b074687c5905d32b89ec22493e8888176.tar.xz
org.eclipse.gmf-tooling-0094715b074687c5905d32b89ec22493e8888176.zip
Anna Karyakina's migration fix
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java155
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java140
2 files changed, 274 insertions, 21 deletions
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java
index 50e2e4453..653c24bbc 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java
@@ -18,6 +18,8 @@ import java.util.Collections;
import junit.framework.TestCase;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
@@ -43,6 +45,7 @@ public class GenericMigrationTest extends TestCase {
private EAttribute myAttrToRename;
private EReference myWidenedRef;
private EAttribute myAttrNarrow;
+ private EAttribute myAttrNarrowChild;
public GenericMigrationTest(String name) {
super(name);
@@ -61,27 +64,36 @@ public class GenericMigrationTest extends TestCase {
myAttrToRename = EcoreFactory.eINSTANCE.createEAttribute();
myWidenedRef = EcoreFactory.eINSTANCE.createEReference();
myAttrNarrow = EcoreFactory.eINSTANCE.createEAttribute();
+ myAttrNarrowChild = EcoreFactory.eINSTANCE.createEAttribute();
EClass mNarrowClass = EcoreFactory.eINSTANCE.createEClass();
+ EClass mNarrowClassChild = EcoreFactory.eINSTANCE.createEClass();
+ mNarrowClassChild.getESuperTypes().add(mNarrowClass);
mmPackage.getEClassifiers().add(mClass);
mmPackage.getEClassifiers().add(mNarrowClass);
+ mmPackage.getEClassifiers().add(mNarrowClassChild);
mClass.getEStructuralFeatures().add(myAttrToRemove);
mClass.getEStructuralFeatures().add(myAttrToRename);
mClass.getEStructuralFeatures().add(myWidenedRef);
mNarrowClass.getEStructuralFeatures().add(myAttrNarrow);
+ mNarrowClassChild.getEStructuralFeatures().add(myAttrNarrowChild);
mmPackage.setName("MM1");
mmPackage.setNsPrefix("mm");
mmPackage.setNsURI("uri:/mm/1");
mClass.setName("MClass");
mNarrowClass.setName("NarrowClass");
+ mNarrowClassChild.setName("NarrowClassChild");
myAttrToRemove.setName("myRemovedAttr");
myAttrToRemove.setEType(EcorePackage.eINSTANCE.getEString());
myAttrToRename.setName("myRenamedAttr");
myAttrToRename.setEType(EcorePackage.eINSTANCE.getEString());
myWidenedRef.setName("myWidenedRef");
+ myWidenedRef.setUpperBound(-1);
myWidenedRef.setContainment(true);
myWidenedRef.setEType(mNarrowClass);
myAttrNarrow.setName("myNarrowAttr");
myAttrNarrow.setEType(EcorePackage.eINSTANCE.getEString());
+ myAttrNarrowChild.setName("myNarrowChildAttr");
+ myAttrNarrowChild.setEType(EcorePackage.eINSTANCE.getEString());
}
private EObject newInstance() {
@@ -92,6 +104,10 @@ public class GenericMigrationTest extends TestCase {
return getMetaModel().getEFactoryInstance().create(myWidenedRef.getEReferenceType());
}
+ private EObject newNarrowChildInstance() {
+ return getMetaModel().getEFactoryInstance().create(myAttrNarrowChild.getEContainingClass());
+ }
+
private EPackage getMetaModel() {
return myAttrToRemove.getEContainingClass().getEPackage();
}
@@ -243,7 +259,9 @@ public class GenericMigrationTest extends TestCase {
String attrValue = "narrow value";
narrowValue.eSet(myAttrNarrow, attrValue);
- testObject.eSet(myWidenedRef, narrowValue);
+ EList narrowValues = new BasicEList();
+ narrowValues.add(narrowValue);
+ testObject.eSet(myWidenedRef, narrowValues);
EPackage metamodel = getMetaModel();
@@ -326,8 +344,13 @@ public class GenericMigrationTest extends TestCase {
assertTrue(migratedObj.eIsSet(myWidenedRef));
Object narrowRef = migratedObj.eGet(myWidenedRef, true);
- assertTrue(narrowRef instanceof EObject);
- EObject narrowInstance = (EObject) narrowRef;
+ assertTrue(narrowRef instanceof EList);
+ EList narrowRefs = (EList) narrowRef;
+ assertFalse(narrowRefs.isEmpty());
+ assertEquals(1, narrowRefs.size());
+ Object narrowRefsFirst = narrowRefs.get(0);
+ assertTrue(narrowRefsFirst instanceof EObject);
+ EObject narrowInstance = (EObject) narrowRefsFirst;
assertFalse(narrowInstance.eClass().isAbstract());
assertFalse(narrowInstance.eClass().equals(myWidenedRef.getEType()));
assertEquals(narrowInstance.eClass(), myAttrNarrow.getEContainingClass());
@@ -341,6 +364,132 @@ public class GenericMigrationTest extends TestCase {
}
}
+ public void testWidenedReferenceWith2Types() {
+ final EObject testObject = newInstance();
+ EObject narrowValue = newNarrowInstance();
+ String attrValue = "narrow value";
+ EObject narrowChildValue = newNarrowChildInstance();
+ String attrChildValue = "narrow child value";
+
+ narrowValue.eSet(myAttrNarrow, attrValue);
+ narrowChildValue.eSet(myAttrNarrowChild, attrChildValue);
+ EList narrowValues = new BasicEList();
+ narrowValues.add(narrowValue);
+ narrowValues.add(narrowChildValue);
+ testObject.eSet(myWidenedRef, narrowValues);
+
+ EPackage metamodel = getMetaModel();
+
+ final String oldNsURI = metamodel.getNsURI();
+ EPackage.Registry.INSTANCE.put(oldNsURI, metamodel);
+ final String newNsURI = oldNsURI + "/2";
+ EPackage.Registry.INSTANCE.put(newNsURI, metamodel);
+
+ try {
+ URI uri = null;
+ try {
+ uri = URI.createFileURI(File.createTempFile("widened2Types", ".tests").getAbsolutePath());
+ final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
+ final Resource res = resourceSetImpl.createResource(uri);
+ res.getContents().add(testObject);
+ res.save(null);
+ resourceSetImpl.getResources().remove(testObject);
+ } catch (IOException ex) {
+ fail(ex.toString());
+ }
+
+ // widen reference in metamodel
+
+ EClass mWideClass = EcoreFactory.eINSTANCE.createEClass();
+ myWidenedRef.getEContainingClass().getEPackage().getEClassifiers().add(mWideClass);
+ mWideClass.setName("WideClass");
+ mWideClass.setAbstract(true);
+ myWidenedRef.setEType(mWideClass);
+ myAttrNarrow.getEContainingClass().getESuperTypes().add(mWideClass);
+
+ // try to load mm
+ try {
+ new ResourceSetImpl().createResource(uri).load(null);
+ fail("Load should fail because of unknown meta-model attribute");
+ } catch (RuntimeException ex) {
+ // expected
+ assertNotNull(ex.getMessage());
+ } catch (IOException ex) {
+ // expected
+ assertNotNull(ex.getMessage());
+ }
+
+ EPackage.Registry.INSTANCE.put(oldNsURI, null);
+
+ Resource.Factory factory = new ToolingResourceFactory() {
+
+ @Override
+ public Resource createResource(URI uri) {
+ return new MigrationResource(uri) {
+ protected MigrationHelperDelegate createDelegate() {
+ MigrationHelperDelegate delegate = new MigrationHelperDelegateImpl() {
+ {
+ registerNarrowReferenceType(myWidenedRef, myAttrNarrow.getEContainingClass());
+ }
+ };
+ return delegate;
+ }
+
+ protected Collection<String> getBackwardSupportedURIs() {
+ return Collections.<String>singleton(oldNsURI);
+ }
+
+ @Override
+ protected String getMetamodelNsURI() {
+ return newNsURI;
+ }
+ };
+ }
+
+ };
+
+ // try to load mm
+ Resource migrated = createLoadHelper(factory, uri).getLoadedResource();
+ assertNotNull(migrated);
+ assertTrue(migrated.getErrors().isEmpty());
+ assertFalse(migrated.getWarnings().isEmpty());
+ assertEquals(1, migrated.getContents().size());
+ EObject migratedObj = migrated.getContents().get(0);
+ assertEquals(testObject.eClass(), migratedObj.eClass());
+
+ assertTrue(migratedObj.eIsSet(myWidenedRef));
+ Object narrowRefList = migratedObj.eGet(myWidenedRef, true);
+ assertTrue(narrowRefList instanceof EList);
+ EList narrowInstancesList = (EList) narrowRefList;
+ assertFalse(narrowInstancesList.isEmpty());
+ assertEquals(2, narrowInstancesList.size());
+
+ Object narrowRefsFirst = narrowInstancesList.get(0);
+ assertTrue(narrowRefsFirst instanceof EObject);
+ EObject narrowInstance1 = (EObject) narrowRefsFirst;
+ assertFalse(narrowInstance1.eClass().isAbstract());
+ assertFalse(narrowInstance1.eClass().equals(myWidenedRef.getEType()));
+ assertEquals(narrowInstance1.eClass(), myAttrNarrow.getEContainingClass());
+ assertTrue(narrowInstance1.eIsSet(myAttrNarrow));
+ Object haveValue = narrowInstance1.eGet(myAttrNarrow, true);
+ assertEquals(attrValue, haveValue);
+
+ Object narrowRefsSecond = narrowInstancesList.get(1);
+ assertTrue(narrowRefsSecond instanceof EObject);
+ EObject narrowInstance2 = (EObject) narrowRefsSecond;
+ assertFalse(narrowInstance2.eClass().isAbstract());
+ assertFalse(narrowInstance2.eClass().equals(myWidenedRef.getEType()));
+ assertEquals(narrowInstance2.eClass(), myAttrNarrowChild.getEContainingClass());
+ assertTrue(narrowInstance2.eIsSet(myAttrNarrowChild));
+ Object haveChildValue = narrowInstance2.eGet(myAttrNarrowChild, true);
+ assertEquals(attrChildValue, haveChildValue);
+ } finally {
+ // clean-up, avoid any chances to affect other tests
+ EPackage.Registry.INSTANCE.put(oldNsURI, null);
+ EPackage.Registry.INSTANCE.put(newNsURI, null);
+ }
+ }
+
private static ModelLoadHelper createLoadHelper(final Resource.Factory factory, URI modelResourceURI) {
if(modelResourceURI == null) {
throw new IllegalArgumentException("null resource uri"); //$NON-NLS-1$
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java
index e5abdb7ab..bff6f2cd3 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java
@@ -10,12 +10,16 @@
*/
package org.eclipse.gmf.tests.migration;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import junit.framework.TestCase;
import org.eclipse.core.runtime.IStatus;
+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.EObject;
@@ -23,7 +27,9 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer;
+import org.eclipse.gmf.codegen.gmfgen.GenAuditRoot;
import org.eclipse.gmf.codegen.gmfgen.GenAuditRule;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
import org.eclipse.gmf.internal.common.migrate.MigrationResource;
import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper;
@@ -39,34 +45,54 @@ public class MigrationPatchesTest extends TestCase {
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=138440
*/
public void testPatch_138440() throws Exception {
- String genmodelFileName = "patch_138440.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("patch_138440.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected IllegalArgumentException from metamodel EFactory", caughtGenException instanceof IllegalArgumentException); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
- String gmfmapmodelFileName = "patch_138440.gmfmap"; //$NON-NLS-1$
+ URI newGenUri = temporarySaveMigratedModel(genmodelFileName, "patch_138440", "gmfgen");
+ changeNsUriToOldOne(newGenUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newGenUri);
+
+ URI gmfmapmodelFileName = createURI("patch_138440.gmfmap"); //$NON-NLS-1$
Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
assertTrue("expected IllegalArgumentException from metamodel EFactory", caughtMapException instanceof IllegalArgumentException); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(gmfmapmodelFileName);
+
+ URI newMapUri = temporarySaveMigratedModel(gmfmapmodelFileName, "patch_138440", "gmfmap");
+ changeNsUriToOldOne(newMapUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0");
+
+ assertOnLoadModelMigrationSuccess(newMapUri);
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=161380
*/
public void testPatch_161380() throws Exception {
- String genmodelFileName = "patch_161380.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("patch_161380.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
- String gmfmapmodelFileName = "patch_161380.gmfmap"; //$NON-NLS-1$
+ URI newGenUri = temporarySaveMigratedModel(genmodelFileName, "patch_138440", "gmfgen");
+ changeNsUriToOldOne(newGenUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newGenUri);
+
+ URI gmfmapmodelFileName = createURI("patch_161380.gmfmap"); //$NON-NLS-1$
Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
assertTrue("expected diagnostic exception", caughtMapException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(gmfmapmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(gmfmapmodelFileName, "patch_161380", "gmfmap");
+ changeNsUriToOldOne(newUri, "gmfmap", "http://www.eclipse.org/gmf/2005/mappings/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
}
private static URI createURI(String testModelFileName) {
@@ -79,8 +105,7 @@ public class MigrationPatchesTest extends TestCase {
return null;
}
- void assertOnLoadModelMigrationSuccess(String modelFileName) throws Exception {
- URI uri = createURI(modelFileName);
+ void assertOnLoadModelMigrationSuccess(URI uri) throws Exception {
ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
assertTrue("Migration warning load status expected", loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$
@@ -88,11 +113,11 @@ public class MigrationPatchesTest extends TestCase {
assertEquals("Single Warning diagnostic expected", 1, warnings.size()); //$NON-NLS-1$
assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationResource.Diagnostic); //$NON-NLS-1$
- assertTrue(loadHelper.getLoadedResource().getErrors().isEmpty());
+ EList<Resource.Diagnostic> errors = loadHelper.getLoadedResource().getErrors();
+ assertTrue(errors.isEmpty());
}
- Exception assertOrdinaryLoadModelProblems(String modelFileName) throws Exception {
- URI uri = createURI(modelFileName);
+ Exception assertOrdinaryLoadModelProblems(URI uri) throws Exception {
Resource resource = new ToolingResourceFactory().createResource(uri);
ResourceSet rset = new ResourceSetImpl();
rset.getResources().add(resource);
@@ -121,12 +146,17 @@ public class MigrationPatchesTest extends TestCase {
attr String preferenceInitializerClassName;
*/
public void testGenDiagram() throws Exception {
- String genmodelFileName = "testGenDiagram.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testGenDiagram.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenDiagram", "gmfgen");
+ changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
}
/*
@@ -135,12 +165,17 @@ public class MigrationPatchesTest extends TestCase {
ref genmodel.GenFeature[1] metaFeature;
*/
public void testFeatureLabelModelFacet() throws Exception {
- String genmodelFileName = "testFeatureLabelModelFacet.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testFeatureLabelModelFacet.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(genmodelFileName, "testFeatureLabelModelFacet", "gmfgen");
+ changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
}
// /*
@@ -158,16 +193,21 @@ public class MigrationPatchesTest extends TestCase {
// }
public void testGenAuditRootDefaultAndNested() throws Exception {
- String genmodelFileName = "testGenAuditRootDefaultAndNested.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testGenAuditRootDefaultAndNested.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAuditRootDefaultAndNested", "gmfgen");
+ changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
}
public void testGenAuditRootNoDefaultButNested() throws Exception {
- String genmodelFileName = "testGenAuditRootNoDefaultButNested.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testGenAuditRootNoDefaultButNested.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
@@ -176,41 +216,105 @@ public class MigrationPatchesTest extends TestCase {
}
public void testGenAudits() throws Exception {
- String genmodelFileName = "testGenAudits.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testGenAudits.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAudits", "gmfgen");
+ changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
}
public void testGenEditorAuditRootNoDefaultButNested() throws Exception {
- String genmodelFileName = "testGenEditorAuditRootNoDefaultButNested.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testGenEditorAuditRootNoDefaultButNested.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenEditorAuditRootNoDefaultButNested", "gmfgen");
+ changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
}
public void testGenAuditsCorrectCategories() throws Exception {
- String genmodelFileName = "testGenAuditsCorrectCategories.gmfgen"; //$NON-NLS-1$
+ URI genmodelFileName = createURI("testGenAuditsCorrectCategories.gmfgen"); //$NON-NLS-1$
Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
assertOnLoadModelMigrationSuccess(genmodelFileName);
+
+ checkModelAndCorrectCategories(genmodelFileName);
+
+ URI newUri = temporarySaveMigratedModel(genmodelFileName, "testGenAuditsCorrectCategories", "gmfgen");
+ changeNsUriToOldOne(newUri, "gmfgen", "http://www.eclipse.org/gmf/2005/GenModel/2.0");
+
+ assertOnLoadModelMigrationSuccess(newUri);
+
+ checkModelAndCorrectCategories(newUri);
+ }
+
+ private URI temporarySaveMigratedModel(URI uri, String tempFilename, String tempFileExtension) throws IOException {
+ ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
+ Resource resource = loadHelper.getLoadedResource();
+ File newGenmodelFile = File.createTempFile(tempFilename, tempFileExtension.startsWith(".") ? tempFileExtension : "."+tempFileExtension);
+ URI newUri = URI.createFileURI(newGenmodelFile.getAbsolutePath());
+ resource.setURI(newUri);
+ try {
+ resource.save(null);
+ } catch (IOException ex) {
+ fail(ex.toString());
+ }
+ return newUri;
+ }
+
+ private void changeNsUriToOldOne(URI newUri, String nsPrefix, String nsUri) throws IOException {
+ Path path = new Path(newUri.toFileString());
+ File file = path.toFile();
+ FileReader reader = new FileReader(file);
+ char[] chars = new char[100000];
+ int length = reader.read(chars);
+ String content = new String(chars, 0, length).replaceFirst("xmlns:"+nsPrefix+"=\"[^\"]+\"", "xmlns:"+nsPrefix+"=\""+nsUri+"\"");
+ FileWriter writer = new FileWriter(file);
+ writer.write(content.toCharArray());
+ writer.flush();
+ }
- URI uri = createURI(genmodelFileName);
+ private void checkModelAndCorrectCategories(URI uri) {
ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
Resource resource = loadHelper.getLoadedResource();
+ int allContentsSize = 0;
for (Iterator<EObject> it = resource.getAllContents(); it.hasNext();) {
EObject next = it.next();
- if (next instanceof GenAuditRule) {
+ allContentsSize++;
+ if (next instanceof GenEditorGenerator) {
+ GenEditorGenerator genEditor = (GenEditorGenerator) next;
+ assertNotNull(genEditor.getAudits());
+ } else if (next instanceof GenAuditRoot) {
+ GenAuditRoot root = (GenAuditRoot) next;
+ assertFalse(root.getCategories().isEmpty());
+ assertFalse(root.getRules().isEmpty());
+ assertEquals(3, root.getCategories().size());
+ assertEquals(3, root.getRules().size());
+ } else if (next instanceof GenAuditContainer) {
+ GenAuditContainer nextContainer = (GenAuditContainer) next;
+ assertFalse(nextContainer.getAudits().isEmpty());
+ assertEquals(nextContainer.getAudits().size(), 1);
+ } else if (next instanceof GenAuditRule) {
GenAuditRule nextRule = (GenAuditRule) next;
GenAuditContainer nextCategory = nextRule.getCategory();
+ assertNotNull(nextCategory);
assertEquals("Audit rule expected to be placed to correct audit category after migration", "rule:"+nextCategory.getId(), nextRule.getId()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+ assertEquals(8, allContentsSize);
}
+
}

Back to the top