diff options
| author | Laurent Fasani | 2015-12-21 18:00:26 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2016-01-28 13:19:04 +0000 |
| commit | 5cd915d9e91c8d17245c85be933259df2a1cfbbc (patch) | |
| tree | b31838e8ff3a896089c341912044cef4b313db12 | |
| parent | 4b9a851c65dc3782693c9a11786c5d87844f6ae6 (diff) | |
| download | org.eclipse.sirius-5cd915d9e91c8d17245c85be933259df2a1cfbbc.tar.gz org.eclipse.sirius-5cd915d9e91c8d17245c85be933259df2a1cfbbc.tar.xz org.eclipse.sirius-5cd915d9e91c8d17245c85be933259df2a1cfbbc.zip | |
[486654] Add migration participant
Add migration participant for VSM and aird file.
Add tests
Bug: 486654
Change-Id: I9859b43a940c0c39000574f5810dfb166a028980
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
8 files changed, 437 insertions, 1 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/plugin.xml b/plugins/org.eclipse.sirius.diagram/plugin.xml index 82c4d3fef4..6b7ade8c53 100644 --- a/plugins/org.eclipse.sirius.diagram/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram/plugin.xml @@ -744,6 +744,14 @@ class="org.eclipse.sirius.diagram.business.internal.migration.GMFLabelStyleMigrationParticipant" kind="RepresentationsFile"> </participant> + <participant + class="org.eclipse.sirius.diagram.business.internal.migration.FilterVariableValueMigrationParticipant" + kind="RepresentationsFile"> + </participant> + <participant + class="org.eclipse.sirius.diagram.business.internal.migration.VariableMigrationParticipant" + kind="VSM"> + </participant> </extension> <extension point="org.eclipse.sirius.mmdescriptor"> @@ -751,5 +759,8 @@ class="org.eclipse.sirius.diagram.business.internal.dialect.DiagramMetamodelsProvider"> </descriptorprovider> </extension> + <extension + point="org.eclipse.sirius.migrationParticipant"> + </extension> </plugin> diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/FilterVariableValueMigrationParticipant.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/FilterVariableValueMigrationParticipant.java new file mode 100644 index 0000000000..d90b98d8b2 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/FilterVariableValueMigrationParticipant.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.business.internal.migration; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.sirius.business.api.migration.AbstractRepresentationsFileMigrationParticipant; +import org.eclipse.sirius.diagram.DiagramPackage; +import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; +import org.osgi.framework.Version; + +/** + * Replace all instance of FilterVariableValue by {@link EObjectVariableValue}. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class FilterVariableValueMigrationParticipant extends AbstractRepresentationsFileMigrationParticipant { + + /** + * The version for which this migration is added. + */ + public static final Version MIGRATION_VERSION = new Version("11.0.0.201601261200"); //$NON-NLS-1$ + + @Override + public Version getMigrationVersion() { + return MIGRATION_VERSION; + } + + @Override + public EClassifier getType(EPackage ePackage, String name, String loadedVersion) { + EClassifier eClass = null; + if (Version.parseVersion(loadedVersion).compareTo(MIGRATION_VERSION) < 0) { + if ("FilterVariableValue".equals(name)) { //$NON-NLS-1$ + eClass = DiagramPackage.eINSTANCE.getEObjectVariableValue(); + } + if ("FilterVariable".equals(name)) { //$NON-NLS-1$ + eClass = ToolPackage.eINSTANCE.getSelectModelElementVariable(); + } + } + return eClass; + } + + @Override + public EStructuralFeature getLocalElement(EClass eClass, String name, String loadedVersion) { + EStructuralFeature feature = null; + if (Version.parseVersion(loadedVersion).compareTo(MIGRATION_VERSION) < 0) { + if (DiagramPackage.eINSTANCE.getEObjectVariableValue().equals(eClass)) { + if (name.equals("variableDefinition")) { //$NON-NLS-1$ + feature = DiagramPackage.eINSTANCE.getEObjectVariableValue_VariableDefinition(); + } else if (name.equals("modelElement")) { //$NON-NLS-1$ + feature = DiagramPackage.eINSTANCE.getEObjectVariableValue_ModelElement(); + } + } + } + return feature; + } +} diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/VariableMigrationParticipant.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/VariableMigrationParticipant.java new file mode 100644 index 0000000000..118857791b --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/VariableMigrationParticipant.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.business.internal.migration; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.sirius.business.api.migration.AbstractVSMMigrationParticipant; +import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; +import org.osgi.framework.Version; + +/** + * Replace the old instance of FilterVariable by an instance of + * SelectModelElementVariable. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class VariableMigrationParticipant extends AbstractVSMMigrationParticipant { + /** + * The version for which this migration is added. + */ + public static final Version MIGRATION_VERSION = new Version("11.0.0.201601261200"); //$NON-NLS-1$ + + @Override + public Version getMigrationVersion() { + return MIGRATION_VERSION; + } + + @Override + public EClassifier getType(EPackage ePackage, String name, String loadedVersion) { + if (Version.parseVersion(loadedVersion).compareTo(MIGRATION_VERSION) < 0) { + // ownedVariables was of concrete type FilterVariable, so xsi::type + // was not serialized. Thus, the required type of the class is asked + // with the name of the new feature type and not with + // "VariableFilter" + if ("InteractiveVariableDescription".equals(name)) { //$NON-NLS-1$ + return ToolPackage.eINSTANCE.getSelectModelElementVariable(); + } + } + return null; + } + + @Override + public EStructuralFeature getLocalElement(EClass eClass, String name, String loadedVersion) { + if (Version.parseVersion(loadedVersion).compareTo(MIGRATION_VERSION) < 0) { + if (org.eclipse.sirius.diagram.description.filter.FilterPackage.eINSTANCE.getVariableFilter().equals(eClass) && name.equals("ownedVariables")) { //$NON-NLS-1$ + return org.eclipse.sirius.diagram.description.filter.FilterPackage.eINSTANCE.getVariableFilter_OwnedVariables(); + } + } + return null; + } +} diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.aird new file mode 100644 index 0000000000..dba3c86191 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.aird @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/filter/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/filter http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style" xmi:id="_LzkCAKMpEeWhmpHp1N50Xg" selectedViews="_v0iCMK7XEeWCKa5bQ33Yhg" version="10.1.0.201509162000"> + <semanticResources>filterMigration.ecore</semanticResources> + <ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_v0iCMK7XEeWCKa5bQ33Yhg"> + <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_1kaWIK7XEeWCKa5bQ33Yhg" name="new ClassDiagram"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_1kaWIa7XEeWCKa5bQ33Yhg" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_1kaWIq7XEeWCKa5bQ33Yhg"/> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_1k9IsK7XEeWCKa5bQ33Yhg" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="_1k9Isa7XEeWCKa5bQ33Yhg" type="Sirius" element="_1kaWIK7XEeWCKa5bQ33Yhg" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_5lQVYK7XEeWCKa5bQ33Yhg" type="2002" element="_5kuw8K7XEeWCKa5bQ33Yhg"> + <children xmi:type="notation:Node" xmi:id="_5lXqIK7XEeWCKa5bQ33Yhg" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_5laGYK7XEeWCKa5bQ33Yhg" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_5latcK7XEeWCKa5bQ33Yhg"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_5latca7XEeWCKa5bQ33Yhg"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_5lQVYa7XEeWCKa5bQ33Yhg" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_5lQVYq7XEeWCKa5bQ33Yhg"/> + </children> + <children xmi:type="notation:Node" xmi:id="_5lbUgK7XEeWCKa5bQ33Yhg" visible="false" type="2002" element="_5lBE0K7XEeWCKa5bQ33Yhg"> + <children xmi:type="notation:Node" xmi:id="_5lcioK7XEeWCKa5bQ33Yhg" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_5lcioa7XEeWCKa5bQ33Yhg" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_5lcioq7XEeWCKa5bQ33Yhg"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_5lcio67XEeWCKa5bQ33Yhg"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_5lbUga7XEeWCKa5bQ33Yhg" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_5lbUgq7XEeWCKa5bQ33Yhg" x="210"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="_1k9Isq7XEeWCKa5bQ33Yhg"/> + </data> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_5kuw8K7XEeWCKa5bQ33Yhg" name="class1"> + <target xmi:type="ecore:EClass" href="filterMigration.ecore#//class1"/> + <semanticElements xmi:type="ecore:EClass" href="filterMigration.ecore#//class1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_5k9acK7XEeWCKa5bQ33Yhg" borderSize="1" borderSizeComputationExpression="1"> + <description xmi:type="style:FlatContainerStyleDescription" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@defaultLayer/@containerMappings[name='EClass']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@defaultLayer/@containerMappings[name='EClass']"/> + </ownedDiagramElements> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_5lBE0K7XEeWCKa5bQ33Yhg" name="class2" visible="false"> + <target xmi:type="ecore:EClass" href="filterMigration.ecore#//class2"/> + <semanticElements xmi:type="ecore:EClass" href="filterMigration.ecore#//class2"/> + <graphicalFilters xmi:type="diagram:AppliedCompositeFilters" xmi:id="_nZujoK7YEeWCKa5bQ33Yhg"> + <compositeFilterDescriptions xmi:type="filter:CompositeFilterDescription" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@filters[name='ClassFilter']"/> + </graphicalFilters> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_5lBr4K7XEeWCKa5bQ33Yhg" borderSize="1" borderSizeComputationExpression="1"> + <description xmi:type="style:FlatContainerStyleDescription" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@defaultLayer/@containerMappings[name='EClass']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@defaultLayer/@containerMappings[name='EClass']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']"/> + <activatedFilters xmi:type="filter:CompositeFilterDescription" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@filters[name='ClassFilter']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_1kaWI67XEeWCKa5bQ33Yhg"> + <ownedValues xmi:type="diagram:FilterVariableValue" xmi:id="_nZsHYK7YEeWCKa5bQ33Yhg"> + <variableDefinition xmi:type="filter:FilterVariable" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@filters[name='ClassFilter']/@filters.0/@ownedVariables.0"/> + <modelElement xmi:type="ecore:EClass" href="filterMigration.ecore#//class1"/> + </ownedValues> + </filterVariableHistory> + <activatedLayers xmi:type="description_1:Layer" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']/@ownedRepresentations[name='ClassDiagram']/@defaultLayer"/> + <target xmi:type="ecore:EPackage" href="filterMigration.ecore#/"/> + </ownedRepresentations> + <viewpoint xmi:type="description:Viewpoint" href="filterMigration.odesign#//@ownedViewpoints[name='vpFilter']"/> + </ownedViews> +</viewpoint:DAnalysis> diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.ecore b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.ecore new file mode 100644 index 0000000000..68ea2f1178 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.ecore @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="P0" nsPrefix=""> + <eClassifiers xsi:type="ecore:EClass" name="class1"/> + <eClassifiers xsi:type="ecore:EClass" name="class2"/> +</ecore:EPackage> diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.odesign new file mode 100644 index 0000000000..b6d59aa67b --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/variableFilter/filterMigration.odesign @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" version="10.1.3.201511131800"> + <ownedViewpoints name="vpFilter"> + <ownedRepresentations xsi:type="description_1:DiagramDescription" name="ClassDiagram" domainClass="EPackage"> + <filters xsi:type="filter:CompositeFilterDescription" name="ClassFilter"> + <filters xsi:type="filter:VariableFilter" semanticConditionExpression="aql:MyVariable->includes(self)"> + <ownedVariables candidatesExpression="aql:self.eContents()" multiple="true" message="message" name="MyVariable"/> + </filters> + </filters> + <defaultLayer name="Default"> + <containerMappings name="EClass" domainClass="EClass"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </containerMappings> + <containerMappings name="EEnum" domainClass="EEnum"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </containerMappings> + <containerMappings name="EPackage" domainClass="EPackage"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </containerMappings> + </defaultLayer> + </ownedRepresentations> + </ownedViewpoints> +</description:Group> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java index c2758d9d70..af9af6f4b5 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES. * 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 @@ -103,6 +103,7 @@ import org.eclipse.sirius.tests.unit.common.migration.GeneralMigrationMechanismT import org.eclipse.sirius.tests.unit.common.migration.MigrationFromSirius0_9Test; import org.eclipse.sirius.tests.unit.common.migration.MigrationFromSirius1_0_0_M5Test; import org.eclipse.sirius.tests.unit.common.migration.ModelsToSemanticResourcesMigrationTest; +import org.eclipse.sirius.tests.unit.common.migration.VariableMigrationTest; import org.eclipse.sirius.tests.unit.diagram.filter.EObjectSelectionFilterTest; import org.eclipse.sirius.tests.unit.diagram.migration.BorderSizeMigrationTest; import org.eclipse.sirius.tests.unit.diagram.migration.ComputedStyleDescriptionCachePackingFileMigrationParticipantTests; @@ -210,6 +211,7 @@ public class AllCommonPluginTests extends TestCase { suite.addTestSuite(ConvertViewpointModelingProjectToSiriusModelingProjectTest.class); suite.addTestSuite(FontFormatMigrationTest.class); suite.addTestSuite(BorderSizeMigrationTest.class); + suite.addTestSuite(VariableMigrationTest.class); suite.addTest(new JUnit4TestAdapter(CommonPreferencesTest.class)); suite.addTest(new JUnit4TestAdapter(GroupingContentProviderTest.class)); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/migration/VariableMigrationTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/migration/VariableMigrationTest.java new file mode 100644 index 0000000000..496b970199 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/migration/VariableMigrationTest.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2016 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.common.migration; + +import java.io.IOException; +import java.util.Collections; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +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.sirius.business.internal.migration.RepresentationsFileMigrationService; +import org.eclipse.sirius.business.internal.migration.description.VSMMigrationService; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.EObjectVariableValue; +import org.eclipse.sirius.diagram.FilterVariableHistory; +import org.eclipse.sirius.diagram.VariableValue; +import org.eclipse.sirius.diagram.business.internal.migration.FilterVariableValueMigrationParticipant; +import org.eclipse.sirius.diagram.business.internal.migration.VariableMigrationParticipant; +import org.eclipse.sirius.diagram.description.DiagramDescription; +import org.eclipse.sirius.diagram.description.filter.CompositeFilterDescription; +import org.eclipse.sirius.diagram.description.filter.VariableFilter; +import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory; +import org.eclipse.sirius.tests.SiriusTestsPlugin; +import org.eclipse.sirius.tests.support.api.SiriusTestCase; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.description.Group; +import org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription; +import org.eclipse.sirius.viewpoint.description.RepresentationDescription; +import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; +import org.osgi.framework.Version; + +/** + * Ensures correct migration from FilterVariable to SelectModelElementVariable + * and from FilterVariableValue to EObjectVariableValue. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class VariableMigrationTest extends SiriusTestCase { + + private static final String REPRESENTATIONS_FILE_PATH = "/data/unit/migration/variableFilter/"; + + private static final String REPRESENTATIONS_FILE_NAME = "filterMigration.aird"; + + private static final String MODEL_FILE_NAME = "filterMigration.ecore"; + + private static final String MODELER_FILE_NAME = "filterMigration.odesign"; + + @Override + protected IDiagramCommandFactory getCommandFactory() { + return null; + } + + /** + * Test that the data were not migrated. It allows to check the effect of + * the migration in the other test. + */ + public void testRepMigrationIsNeededOnData() { + Version loadedVersion = checkRepresentationFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + REPRESENTATIONS_FILE_NAME, true), true); + + // Check that the migration is needed. + Version migration = FilterVariableValueMigrationParticipant.MIGRATION_VERSION; + assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); + } + + /** + * Test that the data were not migrated. It allows to check the effect of + * the migration in the other test. + */ + public void testVSMMigrationIsNeededOnData() { + Version loadedVersion = checkVsmFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + MODELER_FILE_NAME, true), true); + + // Check that the migration is needed. + Version migration = VariableMigrationParticipant.MIGRATION_VERSION; + assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); + } + + /** + * Check that the instances of FilterVariableHistory.ownedValues are + * correctly converted into EObjectVariableValue + * + * @throws IOException + */ + public void testFilterVariableValueToEObjectVariableValueMigration() throws IOException { + copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, REPRESENTATIONS_FILE_PATH, REPRESENTATIONS_FILE_NAME, MODEL_FILE_NAME, MODELER_FILE_NAME); + + ResourceSet set = new ResourceSetImpl(); + DAnalysis analysis = null; + Resource resourceAird = set.getResource(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_FILE_NAME, true), true); + analysis = (DAnalysis) resourceAird.getContents().get(0); + + assertNotNull("Analysis is not retrieved.", analysis); + + // The version will change on save, so migration service will still + // indicates that the migration is needed. + String version = analysis.getVersion(); + assertTrue("Before save, the migration framework will return true even if the migration has been done during load.", + RepresentationsFileMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + + resourceAird.save(Collections.emptyMap()); + + // save should update the version. + version = analysis.getVersion(); + assertFalse("The version tag should now be set telling that the migration was done.", RepresentationsFileMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + + // We can now check the migration effect to be sure that the migration + // is effective. + checkRepMigrationEffect(analysis); + + } + + private void checkRepMigrationEffect(DAnalysis analysis) { + DRepresentation dView = analysis.getOwnedViews().get(0).getOwnedRepresentations().get(0); + assertTrue("DRepresentation " + dView.getName() + " is not a DDiagram", dView instanceof DDiagram); + FilterVariableHistory filterVariableHistory = ((DDiagram) dView).getFilterVariableHistory(); + EList<VariableValue> ownedValues = filterVariableHistory.getOwnedValues(); + VariableValue variableValue = ownedValues.get(0); + + assertTrue("FilterVariableHistory.ownedValues should be of type EObjectVariableValue", variableValue instanceof EObjectVariableValue); + EObjectVariableValue objectValue = (EObjectVariableValue) variableValue; + EObject modelElement = objectValue.getModelElement(); + assertNotNull("EObjectVariableValue.modelElement is not set", modelElement); + SelectModelElementVariable variableDefinition = objectValue.getVariableDefinition(); + assertNotNull("EObjectVariableValue.variableDefinition is not set", variableDefinition); + } + + /** + * Check that the instances of FilterVariableHistory.ownedValues are + * correctly converted into EObjectVariableValue + * + * @throws IOException + */ + public void testFilterVariableToSelectModelElementVariableMigration() throws IOException { + copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, REPRESENTATIONS_FILE_PATH, MODELER_FILE_NAME); + + ResourceSet set = new ResourceSetImpl(); + Group group = null; + Resource resourceVSM = set.getResource(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + MODELER_FILE_NAME, true), true); + group = (Group) resourceVSM.getContents().get(0); + + assertNotNull("Group is not retrieved.", group); + + // The version will change on save, so migration service will still + // indicates that the migration is needed. + String version = group.getVersion(); + assertTrue("Before save, the migration framework will return true even if the migration has been done during load.", + VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + + resourceVSM.save(Collections.emptyMap()); + + // save should update the version. + version = group.getVersion(); + assertFalse("The version tag should now be set telling that the migration was done.", VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + + // We can now check the migration effect to be sure that the migration + // is effective. + checkVSMMigrationEffect(group); + + } + + private void checkVSMMigrationEffect(Group group) { + RepresentationDescription representationDescription = group.getOwnedViewpoints().get(0).getOwnedRepresentations().get(0); + assertTrue("RepresentationDescription " + representationDescription.getName() + " is not a DiagramDescription", representationDescription instanceof DiagramDescription); + DiagramDescription diagramDesc = (DiagramDescription) representationDescription; + InteractiveVariableDescription interactiveVariableDescription = ((VariableFilter) ((CompositeFilterDescription) diagramDesc.getFilters().get(0)).getFilters().get(0)).getOwnedVariables() + .get(0); + + assertTrue("VariableFilter.ownedVariables should be of type SelectModelElementVariable", interactiveVariableDescription instanceof SelectModelElementVariable); + + SelectModelElementVariable variable = (SelectModelElementVariable) interactiveVariableDescription; + assertEquals("Bad SelectModelElementVariable.candidatesExpression", "aql:self.eContents()", variable.getCandidatesExpression()); + + assertEquals("Bad SelectModelElementVariable.name", "MyVariable", variable.getName()); + assertEquals("Bad SelectModelElementVariable.message", "message", variable.getMessage()); + } +} |
