Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2007-05-18 16:39:12 -0400
committeratikhomirov2007-05-18 16:39:12 -0400
commit730ba8ff77835ba8c1549cd0e4ee8bb8fe9be9e3 (patch)
treee56bcbfa9bb63f843f6dc648252a4ca2b6a50627
parent96c6ec2f259417f8c9cb9127aef1d021f7f7163f (diff)
downloadorg.eclipse.gmf-tooling-730ba8ff77835ba8c1549cd0e4ee8bb8fe9be9e3.tar.gz
org.eclipse.gmf-tooling-730ba8ff77835ba8c1549cd0e4ee8bb8fe9be9e3.tar.xz
org.eclipse.gmf-tooling-730ba8ff77835ba8c1549cd0e4ee8bb8fe9be9e3.zip
[187811] akarjakina - Migration support refactored
-rw-r--r--tests/org.eclipse.gmf.tests/models/migration/testFeatureLabelModelFacet.gmfgen7
-rw-r--r--tests/org.eclipse.gmf.tests/models/migration/testTypeLinkModelFacet.gmfgen8
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/AllMigrationTests.java1
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/FeatureKeyTest.java93
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/GenericMigrationTest.java134
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java64
6 files changed, 177 insertions, 130 deletions
diff --git a/tests/org.eclipse.gmf.tests/models/migration/testFeatureLabelModelFacet.gmfgen b/tests/org.eclipse.gmf.tests/models/migration/testFeatureLabelModelFacet.gmfgen
new file mode 100644
index 000000000..16f599f84
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/models/migration/testFeatureLabelModelFacet.gmfgen
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gmfgen:FeatureLabelModelFacet xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:gmfgen="http://www.eclipse.org/gmf/2005/GenModel">
+ <metaFeature name="DeletedFeature">
+ </metaFeature>
+</gmfgen:FeatureLabelModelFacet>
diff --git a/tests/org.eclipse.gmf.tests/models/migration/testTypeLinkModelFacet.gmfgen b/tests/org.eclipse.gmf.tests/models/migration/testTypeLinkModelFacet.gmfgen
new file mode 100644
index 000000000..060686093
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/models/migration/testTypeLinkModelFacet.gmfgen
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gmfgen:TypeLinkModelFacet xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:gmfgen="http://www.eclipse.org/gmf/2005/GenModel"
+ createCommandClassName="CreateCommandClassName"/>
+ <modelElementSelector body="GenConstraintBody">
+ </modelElementSelector>
+</gmfgen:TypeLinkModelFacet>
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/AllMigrationTests.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/AllMigrationTests.java
index c3f92685c..95d81cd8d 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/AllMigrationTests.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/AllMigrationTests.java
@@ -19,7 +19,6 @@ public class AllMigrationTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.gmf.tests.migration"); //$NON-NLS-1$
//$JUnit-BEGIN$
- suite.addTestSuite(FeatureKeyTest.class);
suite.addTestSuite(GenericMigrationTest.class);
suite.addTestSuite(MigrationPatchesTest.class);
//$JUnit-END$
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/FeatureKeyTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/FeatureKeyTest.java
deleted file mode 100644
index 2723902bd..000000000
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/FeatureKeyTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2006 Eclipse.org
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: dvorak - initial API and implementation
- */
-package org.eclipse.gmf.tests.migration;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gmf.internal.common.migrate.FeatureKey;
-
-@SuppressWarnings("unchecked")
-public class FeatureKeyTest extends TestCase {
- EPackage ePackage1;
- EClass eClassA1;
- EPackage ePackage2;
- EClass eClassA2;
-
- public FeatureKeyTest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- ePackage1 = EcoreFactory.eINSTANCE.createEPackage();
- ePackage1.setNsURI("ePackage1"); //$NON-NLS-1$
- eClassA1 = EcoreFactory.eINSTANCE.createEClass();
- eClassA1.setName("A"); //$NON-NLS-1$
-
- ePackage2 = EcoreFactory.eINSTANCE.createEPackage();
- ePackage2.setNsURI("ePackage2"); //$NON-NLS-1$
- eClassA2 = EcoreFactory.eINSTANCE.createEClass();
- eClassA2.setName("A"); //$NON-NLS-1$
- }
-
- public void testUninitialized() throws Exception {
- FeatureKey unInitFeatureKey = new FeatureKey();
- assertEquals(unInitFeatureKey, new FeatureKey());
-
- unInitFeatureKey.setFeature(EcorePackage.eINSTANCE.getENamedElement_Name());
- assertFalse(unInitFeatureKey.equals(new FeatureKey()));
- }
-
- public void testEquals() throws Exception {
- FeatureKey featureKey = FeatureKey.create(EcorePackage.eINSTANCE.getENamedElement_Name());
- assertEquals(featureKey, featureKey);
- assertEquals(featureKey, FeatureKey.create(EcorePackage.eINSTANCE.getENamedElement_Name()));
-
- FeatureKey differentFeatureKey = FeatureKey.create(EcorePackage.eINSTANCE.getEClass_Abstract());
- assertFalse(featureKey.equals(differentFeatureKey));
-
- differentFeatureKey.setFeature(EcorePackage.eINSTANCE.getENamedElement_Name());
- assertEquals(featureKey, differentFeatureKey);
- }
-
- public void testAdvancedEquals() throws Exception {
- EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute();
- assertEquals(FeatureKey.create(attribute), FeatureKey.create(attribute));
-
- attribute.setName("x"); //$NON-NLS-1$
- EAttribute attribute2 = (EAttribute)EcoreUtil.copy(attribute);
- assertEquals(FeatureKey.create(attribute), FeatureKey.create(attribute2));
- attribute2.setName("y"); //$NON-NLS-1$
- assertFalse(FeatureKey.create(attribute).equals(FeatureKey.create(attribute2)));
-
- attribute2 = (EAttribute)EcoreUtil.copy(attribute);
- eClassA1.getEStructuralFeatures().add(attribute);
- eClassA2.getEStructuralFeatures().add(attribute2);
- assertEquals(FeatureKey.create(attribute), FeatureKey.create(attribute2));
-
- ePackage1.getEClassifiers().add(eClassA1);
- ePackage2.getEClassifiers().add(eClassA2);
- assertFalse(FeatureKey.create(attribute).equals(FeatureKey.create(attribute2)));
- }
-
- private void assertEquals(FeatureKey expected, FeatureKey actual) {
- Assert.assertEquals(expected, actual);
- assertEquals("Expect the same hashcode for equals", expected.hashCode(), actual.hashCode()); //$NON-NLS-1$
- }
-}
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 9f21e3a44..e213aa003 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
@@ -13,6 +13,8 @@ package org.eclipse.gmf.tests.migration;
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
import junit.framework.TestCase;
@@ -24,9 +26,14 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Factory;
+import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.gmf.internal.common.migrate.MigrationConfig;
-import org.eclipse.gmf.internal.common.migrate.MigrationUtil;
+import org.eclipse.gmf.internal.common.ToolingResourceFactory;
+import org.eclipse.gmf.internal.common.migrate.MigrationHelper;
+import org.eclipse.gmf.internal.common.migrate.MigrationHelperDelegate;
+import org.eclipse.gmf.internal.common.migrate.MigrationResource;
+import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper;
/**
* @author artem
@@ -66,8 +73,7 @@ public class GenericMigrationTest extends TestCase {
return myAttrToRemove.getEContainingClass().getEPackage();
}
- @SuppressWarnings("unchecked")
- public void testRemovedAttribute() {
+ public void oldTestRemovedAttribute() {
final EObject testObject = newInstance();
testObject.eSet(myAttrToRemove, "value");
@@ -103,24 +109,100 @@ public class GenericMigrationTest extends TestCase {
EPackage.Registry.INSTANCE.put(oldNsURI, null);
- MigrationConfig.Registry.INSTANCE.register(new MigrationConfig.Descriptor() {
- private final MigrationConfig cfg = new MigrationConfig(newNsURI, new String[] { oldNsURI });
- {
- cfg.registerDeletedAttribute(testObject.eClass(), myAttrToRemove.getName());
- }
+// MigrationConfig.Registry.INSTANCE.register(new MigrationConfig.Descriptor() {
+// private final MigrationConfig cfg = new MigrationConfig(newNsURI, new String[] { oldNsURI });
+// {
+// cfg.registerDeletedAttribute(testObject.eClass(), myAttrToRemove.getName());
+// }
+//
+// public MigrationConfig getConfig() {
+// return cfg;
+// }
+//
+// public String getExtension() {
+// return "tests";
+// }
+//
+// });
+// Resource migrated = MigrationUtil.migrateModel(uri).getLoadedResource();
+// assertNotNull(migrated);
+// assertTrue(migrated.getErrors().isEmpty() && migrated.getWarnings().isEmpty());
+// assertEquals(1, migrated.getContents().size());
+// EObject migratedObj = migrated.getContents().get(0);
+// assertEquals(testObject.eClass(), migratedObj.eClass());
+ } finally {
+ // clean-up, avoid any chances to affect other tests
+ // XXX MigrationConfig should be cleaned as well.
+ EPackage.Registry.INSTANCE.put(oldNsURI, null);
+ EPackage.Registry.INSTANCE.put(newNsURI, null);
+ }
+ }
- public MigrationConfig getConfig() {
- return cfg;
- }
+ public void testRemovedAttribute() {
+ final EObject testObject = newInstance();
+ testObject.eSet(myAttrToRemove, "value");
- public String getExtension() {
- return "tests";
- }
+ final String oldNsURI = getMetaModel().getNsURI();
+ EPackage.Registry.INSTANCE.put(oldNsURI, getMetaModel());
+ final String newNsURI = oldNsURI + "/2";
+ EPackage.Registry.INSTANCE.put(newNsURI, getMetaModel());
- });
- Resource migrated = MigrationUtil.migrateModel(uri).getLoadedResource();
+ try {
+ URI uri = null;
+ try {
+ uri = URI.createFileURI(File.createTempFile("removed", ".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());
+ }
+ // remove attr from metamodel
+ myAttrToRemove.getEContainingClass().getEStructuralFeatures().remove(myAttrToRemove);
+
+ // try to load mm
+ try {
+ new ResourceSetImpl().createResource(uri).load(null);
+ fail("Load should fail because of missing meta-model attribute");
+ } catch (IOException ex) {
+ // expected
+ assertNotNull(ex.getMessage());
+ assertTrue(ex.getMessage().contains(myAttrToRemove.getName()));
+ }
+
+ 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 MigrationHelper.MigrationHelperDelegateImpl() {
+ {
+ registerDeletedAttributes(testObject.eClass(), myAttrToRemove.getName());
+ }
+ };
+ return delegate;
+ }
+
+ protected Collection<String> getBackwardSupportedURIs() {
+ return Collections.singleton(oldNsURI);
+ }
+
+ protected String getMetamodelNsURI() {
+ return newNsURI;
+ }
+ };
+ }
+
+ };
+ Resource migrated = migrateModel(factory, uri).getLoadedResource();
assertNotNull(migrated);
- assertTrue(migrated.getErrors().isEmpty() && migrated.getWarnings().isEmpty());
+ assertTrue(migrated.getErrors().isEmpty());
+ assertFalse(migrated.getWarnings().isEmpty());
assertEquals(1, migrated.getContents().size());
EObject migratedObj = migrated.getContents().get(0);
assertEquals(testObject.eClass(), migratedObj.eClass());
@@ -131,4 +213,20 @@ public class GenericMigrationTest extends TestCase {
EPackage.Registry.INSTANCE.put(newNsURI, null);
}
}
+
+ private static ModelLoadHelper migrateModel(final Resource.Factory factory, URI modelResourceURI) {
+ if(modelResourceURI == null) {
+ throw new IllegalArgumentException("null resource uri"); //$NON-NLS-1$
+ }
+ ResourceSetImpl rset = new ResourceSetImpl();
+ rset.setResourceFactoryRegistry(new ResourceFactoryRegistryImpl() {
+ public Factory getFactory(URI uri) {
+ return factory;
+ }
+ });
+
+ ModelLoadHelper loadHelper = new ModelLoadHelper(rset, modelResourceURI);
+ return loadHelper;
+ }
+
} \ No newline at end of file
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 6f5da14d7..e5abdb7ab 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
@@ -1,5 +1,5 @@
-/**
- * Copyright (c) 2006 Eclipse.org
+/*
+ * Copyright (c) 2006, 2007 Eclipse.org
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
@@ -25,7 +25,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer;
import org.eclipse.gmf.codegen.gmfgen.GenAuditRule;
import org.eclipse.gmf.internal.common.ToolingResourceFactory;
-import org.eclipse.gmf.internal.common.migrate.MigrationUtil;
+import org.eclipse.gmf.internal.common.migrate.MigrationResource;
import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper;
import org.eclipse.gmf.tests.Plugin;
@@ -45,7 +45,7 @@ public class MigrationPatchesTest extends TestCase {
assertOnLoadModelMigrationSuccess(genmodelFileName);
- String gmfmapmodelFileName = "patch_138440.gmfmap"; //$NON-NLS-1$
+ String gmfmapmodelFileName = "patch_138440.gmfmap"; //$NON-NLS-1$
Exception caughtMapException = assertOrdinaryLoadModelProblems(gmfmapmodelFileName);
assertTrue("expected IllegalArgumentException from metamodel EFactory", caughtMapException instanceof IllegalArgumentException); //$NON-NLS-1$
@@ -82,15 +82,15 @@ public class MigrationPatchesTest extends TestCase {
void assertOnLoadModelMigrationSuccess(String modelFileName) throws Exception {
URI uri = createURI(modelFileName);
ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri);
+
assertTrue("Migration warning load status expected", loadHelper.getStatus().matches(IStatus.WARNING)); //$NON-NLS-1$
-
EList<Resource.Diagnostic> warnings = loadHelper.getLoadedResource().getWarnings();
assertEquals("Single Warning diagnostic expected", 1, warnings.size()); //$NON-NLS-1$
- assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationUtil.MigrationDiagnostic); //$NON-NLS-1$
+ assertTrue("MigrationDiagnostic expected as warning", warnings.get(0) instanceof MigrationResource.Diagnostic); //$NON-NLS-1$
+
assertTrue(loadHelper.getLoadedResource().getErrors().isEmpty());
}
- @SuppressWarnings("unchecked")
Exception assertOrdinaryLoadModelProblems(String modelFileName) throws Exception {
URI uri = createURI(modelFileName);
Resource resource = new ToolingResourceFactory().createResource(uri);
@@ -108,17 +108,17 @@ public class MigrationPatchesTest extends TestCase {
return caughtException;
}
-/*
-GenDiagram
-Removed attrs:
-attr String paletteProviderClassName;
-attr ProviderPriority paletteProviderPriority;
-attr String propertyProviderClassName;
-attr ProviderPriority propertyProviderPriority;
-attr String referenceConnectionEditPolicyClassName;
-attr String externalNodeLabelHostLayoutEditPolicyClassName;
-attr String diagramFileCreatorClassName;
-attr String preferenceInitializerClassName;
+ /*
+ GenDiagram
+ Removed attrs:
+ attr String paletteProviderClassName;
+ attr ProviderPriority paletteProviderPriority;
+ attr String propertyProviderClassName;
+ attr ProviderPriority propertyProviderPriority;
+ attr String referenceConnectionEditPolicyClassName;
+ attr String externalNodeLabelHostLayoutEditPolicyClassName;
+ attr String diagramFileCreatorClassName;
+ attr String preferenceInitializerClassName;
*/
public void testGenDiagram() throws Exception {
String genmodelFileName = "testGenDiagram.gmfgen"; //$NON-NLS-1$
@@ -129,6 +129,34 @@ attr String preferenceInitializerClassName;
assertOnLoadModelMigrationSuccess(genmodelFileName);
}
+ /*
+ FeatureLabelModelFacet
+ Removed refs:
+ ref genmodel.GenFeature[1] metaFeature;
+ */
+ public void testFeatureLabelModelFacet() throws Exception {
+ String genmodelFileName = "testFeatureLabelModelFacet.gmfgen"; //$NON-NLS-1$
+
+ Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
+ assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
+
+ assertOnLoadModelMigrationSuccess(genmodelFileName);
+ }
+
+// /*
+// TypeLinkModelFacet
+// Removed attrs:
+// attr String createCommandClassName;
+// */
+// public void testTypeLinkModelFacet() throws Exception {
+// String genmodelFileName = "testTypeLinkModelFacet.gmfgen"; //$NON-NLS-1$
+//
+// Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName);
+// assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$
+//
+// assertOnLoadModelMigrationSuccess(genmodelFileName);
+// }
+
public void testGenAuditRootDefaultAndNested() throws Exception {
String genmodelFileName = "testGenAuditRootDefaultAndNested.gmfgen"; //$NON-NLS-1$

Back to the top