diff options
| author | Pierre Guilet | 2018-08-03 08:06:44 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2018-08-27 08:01:01 +0000 |
| commit | cfc8bb37541388d8e72810176476442c7f081b01 (patch) | |
| tree | b4b3b3915a9a4199bfd49062a584d0f2ad168da8 | |
| parent | 1360fcf3eb45d0f9b1b4eb6bc8d47f0a5128642c (diff) | |
| download | org.eclipse.sirius-cfc8bb37541388d8e72810176476442c7f081b01.tar.gz org.eclipse.sirius-cfc8bb37541388d8e72810176476442c7f081b01.tar.xz org.eclipse.sirius-cfc8bb37541388d8e72810176476442c7f081b01.zip | |
[536995] Add tests
Bug: 536995
Change-Id: Ie3628dad56770a579cbcc85b1297bfdfd286cdca
Signed-off-by: Pierre Guilet <pierre.guilet@obeo.fr>
8 files changed, 474 insertions, 11 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 32b8ff8541..92415afe24 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -316,6 +316,24 @@ <code>org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures</code> package. </li> </ul> + <h4 id="Changesinorg.eclipse.sirius.common">Changes in + <code>org.eclipse.sirius.common</code> + </h4> + <ul> + <li><span class="label label-success">Added</span> The new preference + <code>PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION</code> has been added in + <code>CommonPreferencesConstants</code>. If true users will be asked to save the VSM or aird if it has been automatically migrated after a user action. + </li> + </ul> + <h4 id="Changesinorg.eclipse.sirius.tests.swtbot.support">Changes in + <code>org.eclipse.sirius.tests.swtbot.support</code> + </h4> + <ul> + <li><span class="label label-success">Added</span> The new method + <code>AbstractSiriusSwtBotGefTestCase.changeSiriusCommonPreference(String, Boolean)</code> has been added. It allows to change a preference defined in + <code>oes.common</code> plugin. + </li> + </ul> <h2 id="sirius6.0.0">Changes in Sirius 6.0.0</h2> <h3 id="UserVisibleChanges2">User-Visible Changes</h3> <ul> @@ -403,7 +421,7 @@ <code>SemanticBasedDecoration</code>. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.common">Changes in + <h4 id="Changesinorg.eclipse.sirius.common2">Changes in <code>org.eclipse.sirius.common</code> </h4> <ul> @@ -552,7 +570,7 @@ <code>org.eclipse.sirius.tests.swtbot.Activator.PLUGIN_ID</code>). It avoids to build a wrong target platform containing each Sirius plug-ins twice. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.tests.swtbot.support">Changes in + <h4 id="Changesinorg.eclipse.sirius.tests.swtbot.support2">Changes in <code>org.eclipse.sirius.tests.swtbot.support</code> </h4> <ul> @@ -842,7 +860,7 @@ <code>DialectManagerImpl</code>. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.common2">Changes in + <h4 id="Changesinorg.eclipse.sirius.common3">Changes in <code>org.eclipse.sirius.common</code> </h4> <ul> @@ -1067,7 +1085,7 @@ <p>See <a href="i18n_changes.html#sirius50">this document</a> for the complete list of message keys added or removed in Sirius 5.0. </p> - <h4 id="Changesinorg.eclipse.sirius.common3">Changes in + <h4 id="Changesinorg.eclipse.sirius.common4">Changes in <code>org.eclipse.sirius.common</code> </h4> <ul> @@ -1519,7 +1537,7 @@ <code>org.eclipse.sirius.tests.support.api.OpenedSessionsCondition</code> has been extracted from a junit test to be used by multiple junit tests. It allows to wait until a session is in opened state. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.tests.swtbot.support2">Changes in + <h4 id="Changesinorg.eclipse.sirius.tests.swtbot.support3">Changes in <code>org.eclipse.sirius.tests.swtbot.support</code> </h4> <ul> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index d0062ee48f..4b095312c2 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -79,6 +79,14 @@ h4. Changes in @org.eclipse.sirius.diagram.sequence.ui@ * <span class="label label-info">Modified</span> The class @org.eclipse.sirius.diagram.sequence.ui.tool.internal.figure.CombinedFragmentInvisibleResizableCompartmentFigure@ has been moved to @org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures@ package. * <span class="label label-info">Modified</span> The class @org.eclipse.sirius.diagram.sequence.ui.tool.internal.figure.SequenceSlidableAnchor@ has been moved to @org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures@ package. +h4. Changes in @org.eclipse.sirius.common@ + +* <span class="label label-success">Added</span> The new preference @PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION@ has been added in @CommonPreferencesConstants@. If true users will be asked to save the VSM or aird if it has been automatically migrated after a user action. + +h4. Changes in @org.eclipse.sirius.tests.swtbot.support@ + +* <span class="label label-success">Added</span> The new method @AbstractSiriusSwtBotGefTestCase.changeSiriusCommonPreference(String, Boolean)@ has been added. It allows to change a preference defined in @oes.common@ plugin. + h2(#sirius6.0.0). Changes in Sirius 6.0.0 h3. User-Visible Changes diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/AbstractSiriusSwtBotGefTestCase.java b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/AbstractSiriusSwtBotGefTestCase.java index a22a3ed906..ba3c17feb2 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/AbstractSiriusSwtBotGefTestCase.java +++ b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/api/AbstractSiriusSwtBotGefTestCase.java @@ -54,6 +54,7 @@ import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.common.tools.api.util.StringUtil; import org.eclipse.sirius.common.tools.internal.resource.ResourceSyncClientNotifier; +import org.eclipse.sirius.common.ui.SiriusTransPlugin; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DiagramPackage; import org.eclipse.sirius.diagram.DiagramPlugin; @@ -234,6 +235,8 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase private final HashMap<String, Object> oldValueSiriusPreferences = new HashMap<String, Object>(); + private final HashMap<String, Object> oldValueCommonPreferences = new HashMap<String, Object>(); + private final HashMap<String, Object> oldValueSiriusUIPreferences = new HashMap<String, Object>(); private final HashMap<String, Object> oldPlatformUIPreferences = new HashMap<String, Object>(); @@ -299,7 +302,8 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase defaultEnableAnimatedLayout = preferenceStore.getBoolean(IPreferenceConstants.PREF_ENABLE_ANIMATED_LAYOUT); preferenceStore.setValue(IPreferenceConstants.PREF_ENABLE_ANIMATED_LAYOUT, false); - // Set the auto-refresh to false because it's historically the default value + // Set the auto-refresh to false because it's historically + // the default value DefaultScope.INSTANCE.getNode(SiriusPlugin.ID).putBoolean(SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), true); InstanceScope.INSTANCE.getNode(SiriusPlugin.ID).putBoolean(SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), getAutoRefreshMode()); } @@ -629,7 +633,7 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase protected void launchCancelCustomStyle() { bot.buttonWithTooltip("Cancel custom style").click(); } - + /** * Change a preference and store the old value. It will be automatically * reset during tear down. @@ -731,7 +735,7 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase } }); } - + /** * Change an int preference and store the old value. It will be * automatically reset during tear down. @@ -755,7 +759,7 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase } }); } - + /** * Change a double preference and store the old value. It will be * automatically reset during tear down. @@ -843,6 +847,28 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase * @param newValue * The new value. */ + protected void changeSiriusCommonPreference(String preferenceKey, Boolean newValue) { + boolean oldValue = Platform.getPreferencesService().getBoolean(SiriusPlugin.ID, preferenceKey, false, null); + oldValueCommonPreferences.put(preferenceKey, oldValue); + + IEclipsePreferences corePreferences = InstanceScope.INSTANCE.getNode(SiriusTransPlugin.PLUGIN_ID); + corePreferences.putBoolean(preferenceKey, newValue); + + boolean valueToCheck = Platform.getPreferencesService().getBoolean(SiriusTransPlugin.PLUGIN_ID, preferenceKey, false, null); + TestCase.assertEquals(getErrorMessage(preferenceKey, SiriusTransPlugin.PLUGIN_ID), newValue.booleanValue(), valueToCheck); + } + + /** + * Change a boolean preference and store the old value. It will be + * automatically reset during tear down. + * + * TO CALL ONLY ONCE PER TEST (set up + test) + * + * @param preferenceKey + * The key of the preference. + * @param newValue + * The new value. + */ protected void changeSiriusUIPreference(String preferenceKey, Boolean newValue) { assertNoSiriusCorePreferenceChangedinSiriusUIStore(preferenceKey); @@ -1692,7 +1718,6 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase CrossReferenceAdapterDetector crossRefDetector = new CrossReferenceAdapterDetector(); try { SWTBotUtils.waitAllUiEvents(); - // Close an eventual popup if the test failed and a popup remain // opened if (bot != null) { @@ -1772,12 +1797,14 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase SWTBotUtils.waitAllUiEvents(); UIThreadRunnable.syncExec(new VoidResult() { + @Override public void run() { IPreferenceStore preferenceStore = DiagramUIPlugin.getPlugin().getPreferenceStore(); preferenceStore.setValue(IPreferenceConstants.PREF_ENABLE_ANIMATED_ZOOM, defaultEnableAnimatedZoom); preferenceStore.setValue(IPreferenceConstants.PREF_ENABLE_ANIMATED_LAYOUT, defaultEnableAnimatedLayout); } + }); setErrorCatchActive(false); setWarningCatchActive(false); @@ -1821,6 +1848,12 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase for (Entry<String, Object> pref : oldValueSiriusPreferences.entrySet()) { corePreferences.putBoolean(pref.getKey(), (Boolean) pref.getValue()); } + + IEclipsePreferences commonPrefs = InstanceScope.INSTANCE.getNode(SiriusTransPlugin.PLUGIN_ID); + for (Entry<String, Object> pref : oldValueCommonPreferences.entrySet()) { + commonPrefs.putBoolean(pref.getKey(), (Boolean) pref.getValue()); + } + } /** @@ -1985,7 +2018,9 @@ public abstract class AbstractSiriusSwtBotGefTestCase extends SWTBotGefTestCase super.tearDown(); setErrorCatchActive(false); setWarningCatchActive(false); - // Avoid NPE in org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry.<init> on close. + // Avoid NPE in + // org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry.<init> + // on close. ResourcesPlugin.getWorkspace().save(true, null); } diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.aird new file mode 100644 index 0000000000..d75773f0f7 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.aird @@ -0,0 +1,81 @@ +<?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: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/1.1.0#//diagram/description http://www.eclipse.org/sirius/diagram/1.1.0 http://www.eclipse.org/sirius/1.1.0#//diagram http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/1.1.0#//diagram/description/style" xmi:id="_8BGnkX0KEeKifZQ-ejpKMg" selectedViews="_8pOXgH0KEeKifZQ-ejpKMg" version="8.0.0"> + <models xmi:type="ecore:EPackage" href="My.ecore#/"/> + <ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_8pOXgH0KEeKifZQ-ejpKMg" initialized="true"> + <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="__Al3gH0KEeKifZQ-ejpKMg" name="new desc"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="__A6noH0KEeKifZQ-ejpKMg" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="__A6noX0KEeKifZQ-ejpKMg" type="Sirius" element="__Al3gH0KEeKifZQ-ejpKMg" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_oZ_28H_wEeK6AN3DQ8tlQA" type="2002" element="_oZ0QwH_wEeK6AN3DQ8tlQA"> + <children xmi:type="notation:Node" xmi:id="_oaBFEH_wEeK6AN3DQ8tlQA" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_oaBFEX_wEeK6AN3DQ8tlQA" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_oaBFEn_wEeK6AN3DQ8tlQA"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_oaBFE3_wEeK6AN3DQ8tlQA"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_oZ_28X_wEeK6AN3DQ8tlQA" fontName="Comic Sans MS" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_oZ_28n_wEeK6AN3DQ8tlQA"/> + </children> + <children xmi:type="notation:Node" xmi:id="_oaBsIH_wEeK6AN3DQ8tlQA" type="2002" element="_oZ1e4H_wEeK6AN3DQ8tlQA"> + <children xmi:type="notation:Node" xmi:id="_oaCTMH_wEeK6AN3DQ8tlQA" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_oaCTMX_wEeK6AN3DQ8tlQA" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_oaCTMn_wEeK6AN3DQ8tlQA"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_oaCTM3_wEeK6AN3DQ8tlQA"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_oaBsIX_wEeK6AN3DQ8tlQA" fontName="Comic Sans MS" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_oaBsIn_wEeK6AN3DQ8tlQA" x="216"/> + </children> + <children xmi:type="notation:Node" xmi:id="_oaC6QH_wEeK6AN3DQ8tlQA" type="2002" element="_oZ2F8H_wEeK6AN3DQ8tlQA"> + <children xmi:type="notation:Node" xmi:id="_oaDhUH_wEeK6AN3DQ8tlQA" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_oaDhUX_wEeK6AN3DQ8tlQA" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_oaDhUn_wEeK6AN3DQ8tlQA"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_oaDhU3_wEeK6AN3DQ8tlQA"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_oaC6QX_wEeK6AN3DQ8tlQA" fontName="Comic Sans MS" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_oaC6Qn_wEeK6AN3DQ8tlQA" x="420"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="__A6non0KEeKifZQ-ejpKMg"/> + </data> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_oZ0QwH_wEeK6AN3DQ8tlQA" name="Test1"> + <target xmi:type="ecore:EClass" href="My.ecore#//Test1"/> + <semanticElements xmi:type="ecore:EClass" href="My.ecore#//Test1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_oZ030H_wEeK6AN3DQ8tlQA"> + <labelColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ030X_wEeK6AN3DQ8tlQA"/> + <description xmi:type="style:FlatContainerStyleDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']/@style"/> + <borderColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ030n_wEeK6AN3DQ8tlQA"/> + <backgroundColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ0303_wEeK6AN3DQ8tlQA" red="255" green="255" blue="255"/> + <foregroundColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ031H_wEeK6AN3DQ8tlQA" red="209" green="209" blue="209"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']"/> + </ownedDiagramElements> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_oZ1e4H_wEeK6AN3DQ8tlQA" name="Test2"> + <target xmi:type="ecore:EClass" href="My.ecore#//Test2"/> + <semanticElements xmi:type="ecore:EClass" href="My.ecore#//Test2"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_oZ1e4X_wEeK6AN3DQ8tlQA"> + <labelColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ1e4n_wEeK6AN3DQ8tlQA"/> + <description xmi:type="style:FlatContainerStyleDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']/@style"/> + <borderColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ1e43_wEeK6AN3DQ8tlQA"/> + <backgroundColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ1e5H_wEeK6AN3DQ8tlQA" red="255" green="255" blue="255"/> + <foregroundColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ1e5X_wEeK6AN3DQ8tlQA" red="209" green="209" blue="209"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']"/> + </ownedDiagramElements> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_oZ2F8H_wEeK6AN3DQ8tlQA" name="Test3"> + <target xmi:type="ecore:EClass" href="My.ecore#//Test3"/> + <semanticElements xmi:type="ecore:EClass" href="My.ecore#//Test3"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_oZ2F8X_wEeK6AN3DQ8tlQA"> + <labelColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ2F8n_wEeK6AN3DQ8tlQA"/> + <description xmi:type="style:FlatContainerStyleDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']/@style"/> + <borderColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ2F83_wEeK6AN3DQ8tlQA"/> + <backgroundColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ2tAH_wEeK6AN3DQ8tlQA" red="255" green="255" blue="255"/> + <foregroundColor xmi:type="viewpoint:RGBValues" xmi:id="_oZ2tAX_wEeK6AN3DQ8tlQA" red="209" green="209" blue="209"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="__Al3gX0KEeKifZQ-ejpKMg"/> + <activatedLayers xmi:type="description_1:Layer" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer"/> + <target xmi:type="ecore:EPackage" href="My.ecore#/"/> + </ownedRepresentations> + <viewpoint xmi:type="description:Viewpoint" href="My.odesign#//@ownedViewpoints[name='vp3507']"/> + </ownedViews> +</viewpoint:DAnalysis> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.ecore b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.ecore new file mode 100644 index 0000000000..94611ce2a9 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.ecore @@ -0,0 +1,7 @@ +<?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="p"> + <eClassifiers xsi:type="ecore:EClass" name="Test1"/> + <eClassifiers xsi:type="ecore:EClass" name="Test2"/> + <eClassifiers xsi:type="ecore:EClass" name="Test3"/> +</ecore:EPackage> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.odesign new file mode 100644 index 0000000000..c70163950d --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/migration/userSave/My.odesign @@ -0,0 +1,17 @@ +<?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:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" name="My" version="8.0.0"> + <ownedViewpoints name="vp3507"> + <ownedRepresentations xsi:type="description_1:DiagramDescription" name="desc" domainClass="EPackage"> + <defaultLayer name="Default"> + <containerMappings name="EClassMapping" domainClass="EClass"> + <style xsi:type="style:FlatContainerStyleDescription"> + <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.swtbot/src/org/eclipse/sirius/tests/swtbot/MigrationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/MigrationTest.java new file mode 100644 index 0000000000..1f31dab736 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/MigrationTest.java @@ -0,0 +1,295 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 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.swtbot; + +import static org.junit.Assert.assertNotEquals; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.business.api.session.SessionManager; +import org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants; +import org.eclipse.sirius.editor.tools.internal.presentation.CustomSiriusEditor; +import org.eclipse.sirius.tests.support.api.ICondition; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; +import org.eclipse.sirius.ui.editor.SessionEditor; +import org.eclipse.sirius.ui.tools.api.project.ModelingProjectManager; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.description.Group; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.ui.actions.WorkspaceModifyOperation; + +/** + * This class tests various functionalities of the {@link SessionEditor}. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class MigrationTest extends AbstractSiriusSwtBotGefTestCase { + + private static final String PATH = "/data/unit/migration/userSave/"; + + private static final String SEMANTIC_MODEL_FILENAME = "My.ecore"; + + private static final String MODELER_MODEL_FILENAME = "My.odesign"; + + private static final String SESSION_FILE_NAME = "My.aird"; + + private SessionEditor sessionEditor; + + @Override + protected void onSetUpBeforeClosingWelcomePage() throws Exception { + changeSiriusCommonPreference(CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION, true); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + copyFileToTestProject(Activator.PLUGIN_ID, PATH, SEMANTIC_MODEL_FILENAME, MODELER_MODEL_FILENAME, SESSION_FILE_NAME); + + } + + @Override + protected void tearDown() throws Exception { + if (sessionEditor != null) { + sessionEditor.close(false); + sessionEditor = null; + } + super.tearDown(); + + } + + private enum Saving { + OK, NO + } + + private void testMigrationFromDoubleClick(Saving airdSaving, Saving VSMSaving) { + SWTBotView modelExplorerView = bot.viewById("org.eclipse.sirius.ui.tools.views.model.explorer"); + SWTBotTreeItem project = modelExplorerView.bot().tree().getTreeItem("DesignerTestProject"); + project.expand(); + SWTBotTreeItem node = project.getNode("My.aird").expand(); + TestsUtil.waitUntil(new ICondition() { + + @Override + public boolean test() throws Exception { + try { + + node.select().doubleClick(); + bot.shell("Save"); + return true; + } catch (WidgetNotFoundException e) { + } + return false; + } + + @Override + public String getFailureMessage() { + return "The dialog asking user to save has not opened."; + } + }); + SWTBotShell shell = bot.shell("Save"); + + if (Saving.OK == airdSaving) { + shell.bot().button("Yes").click(); + } else { + if (Saving.NO == airdSaving) { + shell.bot().button("No").click(); + } else { + shell.bot().button("Cancel").click(); + } + } + TestsUtil.waitUntil(new ICondition() { + + @Override + public boolean test() throws Exception { + return bot.editors().size() > 0; + } + + @Override + public String getFailureMessage() { + return "Session editor did not opened."; + } + }); + SWTBotEditor editorBot; + DAnalysis dAnalysis = getDAnalysis(); + + if (Saving.OK == airdSaving) { + assertNotEquals("Aird Migration should have been done.", "8.0.0", dAnalysis.getVersion()); + } else { + assertEquals("Aird Migration should have not been done.", "8.0.0", dAnalysis.getVersion()); + } + SWTBotTreeItem nodeDesign = project.getNode("My.odesign"); + TestsUtil.waitUntil(new ICondition() { + + @Override + public boolean test() throws Exception { + try { + nodeDesign.select().doubleClick(); + bot.shell("Save"); + return true; + } catch (WidgetNotFoundException e) { + } + return false; + } + + @Override + public String getFailureMessage() { + return "The dialog asking user to save has not opened."; + } + }); + shell = bot.shell("Save"); + + if (Saving.OK == airdSaving) { + shell.bot().button("Yes").click(); + } else { + if (Saving.NO == airdSaving) { + shell.bot().button("No").click(); + } else { + shell.bot().button("Cancel").click(); + } + } + TestsUtil.waitUntil(new ICondition() { + + @Override + public boolean test() throws Exception { + return bot.editors().size() > 1; + } + + @Override + public String getFailureMessage() { + return "VSM editor did not opened."; + } + }); + editorBot = bot.editors().get(1); + CustomSiriusEditor customSiriusEditor = (CustomSiriusEditor) editorBot.getReference().getEditor(false); + Resource resource = customSiriusEditor.getEditingDomain().getResourceSet().getResources().get(0); + Group group = (Group) resource.getContents().get(0); + + if (Saving.OK == airdSaving) { + assertNotEquals("VSM migration should have been done.", "8.0.0", group.getVersion()); + } else { + assertEquals("VSM migration should have not been done.", "8.0.0", group.getVersion()); + } + + } + + private DAnalysis getDAnalysis() { + SWTBotEditor editorBot = bot.editors().get(0); + sessionEditor = (SessionEditor) editorBot.getReference().getEditor(false); + Session session = sessionEditor.getSession(); + Resource sessionResource = session.getSessionResource(); + DAnalysis dAnalysis = (DAnalysis) sessionResource.getContents().get(0); + return dAnalysis; + } + + private void testMigrationFromModelingProjectConversion(Saving airdSaving, Saving VSMSaving) { + Display.getDefault().asyncExec(() -> { + WorkspaceModifyOperation op = new WorkspaceModifyOperation() { + @Override + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + ModelingProjectManager.INSTANCE.convertToModelingProject(ResourcesPlugin.getWorkspace().getRoot().getProject(TEMP_PROJECT_NAME), new NullProgressMonitor()); + } + }; + try { + op.run(new NullProgressMonitor()); + } catch (InvocationTargetException | InterruptedException e1) { + } + }); + + TestsUtil.waitUntil(new ICondition() { + + @Override + public boolean test() throws Exception { + try { + bot.shell("Save"); + return true; + } catch (WidgetNotFoundException e) { + } + return false; + } + + @Override + public String getFailureMessage() { + return "The dialog asking user to save has not opened."; + } + }); + SWTBotShell shell = bot.shell("Save"); + + if (Saving.OK == airdSaving) { + shell.bot().button("Yes").click(); + } else { + if (Saving.NO == airdSaving) { + shell.bot().button("No").click(); + } else { + shell.bot().button("Cancel").click(); + } + } + Session session = SessionManager.INSTANCE.getSession(URI.createPlatformResourceURI(TEMP_PROJECT_NAME + "/My.aird", true), new NullProgressMonitor()); + Resource sessionResource = session.getSessionResource(); + DAnalysis dAnalysis = (DAnalysis) sessionResource.getContents().get(0); + + if (Saving.OK == airdSaving) { + assertNotEquals("VSM migration should have been done.", "8.0.0", dAnalysis.getVersion()); + } else { + assertEquals("VSM migration should have not been done.", "8.0.0", dAnalysis.getVersion()); + } + + } + + /** + * Test that when the preference {@link CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION} is + * used then a dialog asks user to save aird and VSM after their migration when a double click is done on the files. + * Also test than when the user choose the yes option, then the saving is done. + */ + public void testMigrationSavingFromAirdAndVSMDoubleClick() { + testMigrationFromDoubleClick(Saving.OK, Saving.OK); + } + + /** + * Test that when the preference {@link CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION} is + * used then a dialog asks user to save aird and VSM after their migration when a double click is done on the files. + * Also test than when the user choose the No option, then the saving is not done. + */ + public void testMigrationNoSavingFromAirdAndVSMDoubleClick() { + testMigrationFromDoubleClick(Saving.NO, Saving.NO); + } + + /** + * Test that when the preference {@link CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION} is + * used then a dialog asks user to save aird after their migration when the project is turned into a modeling one. + * Also test than when the user choose the yes option, then the saving is done. + */ + public void testMigrationSavingFromAirdAndVSMOpenProject() { + testMigrationFromModelingProjectConversion(Saving.OK, Saving.OK); + } + + /** + * Test that when the preference {@link CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION} is + * used then a dialog ask user to save aird after their migration when the project is turned into a modeling one. + * Also test than when the user choose the No option, then the saving is not done. + */ + public void testMigrationNoSavingFromAirdAndVSMOpenProject() { + testMigrationFromModelingProjectConversion(Saving.NO, Saving.NO); + } + +} diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java index d68a8094ce..1c9bf3f339 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java @@ -168,6 +168,8 @@ public class AllTestSuite extends TestCase { suite.addTestSuite(NodeWithDecoratorSelectionTest.class); suite.addTestSuite(ManualAirdModificationTest.class); suite.addTestSuite(SpecificClosedOrNotClosedEditorTest.class); + suite.addTestSuite(MigrationTest.class); + } /** |
