diff options
author | Thanh Liem PHAN | 2017-09-28 12:53:52 +0000 |
---|---|---|
committer | vincent lorenzo | 2017-10-04 14:53:21 +0000 |
commit | 05b047f0cad0bdff062b87feff39e43ffa0fe8fe (patch) | |
tree | c804c6a2f45fc2af7c1af8a9cc99508dfd302e4e /tests/junit | |
parent | 11b1f30a0da3a6394b15719b1734298263df28b6 (diff) | |
download | org.eclipse.papyrus-05b047f0cad0bdff062b87feff39e43ffa0fe8fe.tar.gz org.eclipse.papyrus-05b047f0cad0bdff062b87feff39e43ffa0fe8fe.tar.xz org.eclipse.papyrus-05b047f0cad0bdff062b87feff39e43ffa0fe8fe.zip |
Bug 525245: [Table][Matrix] the wrapper used for rows sources and
columns sources are not destroyed when there wrapped element is
destroyed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=525245
- Remove the EObjectWrapper of the destroyed element
- JUnit test
Change-Id: I089e95df8d9d90f1b4994df18d4bfd0fbc0e39cf
Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
Diffstat (limited to 'tests/junit')
6 files changed, 248 insertions, 3 deletions
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/META-INF/MANIFEST.MF index c1d18c8db32..37bf4c735c2 100755 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/META-INF/MANIFEST.MF @@ -11,5 +11,7 @@ Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)", org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)", org.eclipse.papyrus.uml.expressions;bundle-version="[1.0.0,2.0.0)", org.eclipse.papyrus.infra.emf.expressions;bundle-version="[1.0.0,2.0.0)", - org.eclipse.gef;bundle-version="[3.11.0,4.0.0)" + org.eclipse.gef;bundle-version="[3.11.0,4.0.0)", + org.eclipse.papyrus.infra.services.edit;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.100,2.0.0)" Bundle-Activator: org.eclipse.papyrus.uml.nattable.matrix.tests.Activator diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.di new file mode 100644 index 00000000000..08128862c28 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.di @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<architecture:ArchitectureDescription xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:architecture="http://www.eclipse.org/papyrus/infra/core/architecture" contextId="org.eclipse.papyrus.infra.services.edit.TypeContext"/>
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.notation new file mode 100644 index 00000000000..4fe3b459ce5 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.notation @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<nattable:Table 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" xmlns:nattable="http://www.eclipse.org/papyrus/nattable/model" xmlns:nattableaxis="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxis" xmlns:nattableaxisconfiguration="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisconfiguration" xmlns:nattableaxisprovider="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider" xmlns:nattablecelleditor="http://www.eclipse.org/papyrus/nattable/model/table/nattablecelleditor" xmlns:nattableconfiguration="http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration" xmlns:nattablestyle="http://www.eclipse.org/papyrus/nattable/model/table/nattablestyle" xmlns:nattablewrapper="http://www.eclipse.org/papyrus/nattable/model/table/nattablewrapper" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxis http://www.eclipse.org/papyrus/nattable/model#//nattableaxis http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableaxisconfiguration http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model#//nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model/table/nattablecelleditor http://www.eclipse.org/papyrus/nattable/model#//nattablecelleditor http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableconfiguration http://www.eclipse.org/papyrus/nattable/model/table/nattablestyle http://www.eclipse.org/papyrus/nattable/model#//nattablestyle http://www.eclipse.org/papyrus/nattable/model/table/nattablewrapper http://www.eclipse.org/papyrus/nattable/model#//nattablewrapper" xmi:id="_iQyPQJoSEeeMicUUPua1Vw" name="RelationshipGenericMatrix" currentRowAxisProvider="_iQyPQ5oSEeeMicUUPua1Vw" currentColumnAxisProvider="_iQyPQpoSEeeMicUUPua1Vw" tableKindId="org.eclipse.papyrus.uml.table.matrix">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_iQy2UJoSEeeMicUUPua1Vw" source="http://www.eclipse.org/papyrus/infra/nattable/version">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_iQy2UZoSEeeMicUUPua1Vw" key="version" value="1.3.0"/>
+ </eAnnotations>
+ <styles xmi:type="nattablestyle:IntListValueStyle" xmi:id="_iQyPQZoSEeeMicUUPua1Vw" name="hiddenCategoriesByDepth">
+ <intListValue>1</intListValue>
+ </styles>
+ <context xmi:type="uml:Model" href="DeleteObjectWrapperForSourceElements.uml#_Mipu4JoSEeeMicUUPua1Vw"/>
+ <owner xmi:type="uml:Model" href="DeleteObjectWrapperForSourceElements.uml#_Mipu4JoSEeeMicUUPua1Vw"/>
+ <tableConfiguration xmi:type="nattableconfiguration:TableConfiguration" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.matrix/configs/generic_matrix_of_relationships.nattableconfiguration#/"/>
+ <columnAxisProvidersHistory xmi:type="nattableaxisprovider:MasterObjectAxisProvider" xmi:id="_iQyPQpoSEeeMicUUPua1Vw" description="This axis provider manages the columns, according to the wanted hierarchy" name="HierarchicalColumnsAxisManager" disconnectSlave="true">
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_oQ1tMJoSEeeMicUUPua1Vw">
+ <element xmi:type="uml:Package" href="DeleteObjectWrapperForSourceElements.uml#_TzF2oJoSEeeMicUUPua1Vw"/>
+ </sources>
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_oQ1tMZoSEeeMicUUPua1Vw">
+ <element xmi:type="uml:Package" href="DeleteObjectWrapperForSourceElements.uml#_YHPMYJoSEeeMicUUPua1Vw"/>
+ </sources>
+ </columnAxisProvidersHistory>
+ <rowAxisProvidersHistory xmi:type="nattableaxisprovider:MasterObjectAxisProvider" xmi:id="_iQyPQ5oSEeeMicUUPua1Vw" description="This axis provider manages the rows, according to the wanted hierarchy" name="HierarchicalRowAxisManager" disconnectSlave="true">
+ <axis xmi:type="nattableaxis:EObjectTreeItemAxis" xmi:id="_qUbVkpoSEeeMicUUPua1Vw">
+ <manager xmi:type="nattableaxisconfiguration:AxisManagerRepresentation" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.matrix/configs/generic_matrix_of_relationships.nattableconfiguration#//@rowHeaderAxisConfiguration/@axisManagers.0"/>
+ <element xmi:type="uml:Interface" href="DeleteObjectWrapperForSourceElements.uml#_d_8FIJoSEeeMicUUPua1Vw"/>
+ </axis>
+ <axis xmi:type="nattableaxis:EObjectTreeItemAxis" xmi:id="_qUbVk5oSEeeMicUUPua1Vw">
+ <manager xmi:type="nattableaxisconfiguration:AxisManagerRepresentation" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.matrix/configs/generic_matrix_of_relationships.nattableconfiguration#//@rowHeaderAxisConfiguration/@axisManagers.0"/>
+ <element xmi:type="uml:Interface" href="DeleteObjectWrapperForSourceElements.uml#_fCThEJoSEeeMicUUPua1Vw"/>
+ </axis>
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_qUbVkJoSEeeMicUUPua1Vw">
+ <element xmi:type="uml:Interface" href="DeleteObjectWrapperForSourceElements.uml#_d_8FIJoSEeeMicUUPua1Vw"/>
+ </sources>
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_qUbVkZoSEeeMicUUPua1Vw">
+ <element xmi:type="uml:Interface" href="DeleteObjectWrapperForSourceElements.uml#_fCThEJoSEeeMicUUPua1Vw"/>
+ </sources>
+ </rowAxisProvidersHistory>
+ <ownedCellEditorConfigurations xmi:type="nattablecelleditor:GenericRelationshipMatrixCellEditorConfiguration" xmi:id="_iQyPRJoSEeeMicUUPua1Vw" cellEditorId="GenericRelationshipMatrixEditorConfiguration"/>
+</nattable:Table>
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.uml new file mode 100644 index 00000000000..8f883ecf86f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.uml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Mipu4JoSEeeMicUUPua1Vw" name="Root">
+ <packageImport xmi:type="uml:PackageImport" xmi:id="_MpyRoJoSEeeMicUUPua1Vw">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
+ </packageImport>
+ <packagedElement xmi:type="uml:Package" xmi:id="_SbcHMJoSEeeMicUUPua1Vw" name="Package1">
+ <packagedElement xmi:type="uml:Package" xmi:id="_TzF2oJoSEeeMicUUPua1Vw" name="Package2">
+ <packagedElement xmi:type="uml:Class" xmi:id="_Ut8VUJoSEeeMicUUPua1Vw" name="Class1"/>
+ <packagedElement xmi:type="uml:Class" xmi:id="_VWXAMJoSEeeMicUUPua1Vw" name="Class2"/>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Package" xmi:id="_YHPMYJoSEeeMicUUPua1Vw" name="Package3">
+ <packagedElement xmi:type="uml:Component" xmi:id="_ZV_egJoSEeeMicUUPua1Vw" name="Component1"/>
+ <packagedElement xmi:type="uml:Component" xmi:id="_aByNgJoSEeeMicUUPua1Vw" name="Component2"/>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Package" xmi:id="_cHTvkJoSEeeMicUUPua1Vw" name="Package4">
+ <packagedElement xmi:type="uml:Interface" xmi:id="_d_8FIJoSEeeMicUUPua1Vw" name="Interface1"/>
+ <packagedElement xmi:type="uml:Interface" xmi:id="_fCThEJoSEeeMicUUPua1Vw" name="Interface2"/>
+ </packagedElement>
+ </packagedElement>
+</uml:Model>
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AllTests.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AllTests.java index 47dc8abc62e..9251277753f 100755 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AllTests.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AllTests.java @@ -8,7 +8,7 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) - vincent.lorenzo@cea.fr - Initial API and implementation - * + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 525245 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.matrix.tests.tests; @@ -22,7 +22,8 @@ import org.junit.runners.Suite.SuiteClasses; OpenDependencyMatrixTest.class, CreateMatrixTableTests.class, UpdateTableAfterEditingRowSourceTest.class, - UpdateTableContentsAfterExpressionChangeWithLocalHeaderPreconfiguredTests.class + UpdateTableContentsAfterExpressionChangeWithLocalHeaderPreconfiguredTests.class, + DeleteObjectWrapperForSourceElementsTest.class }) public class AllTests { // JUnit 4 test suite diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/DeleteObjectWrapperForSourceElementsTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/DeleteObjectWrapperForSourceElementsTest.java new file mode 100644 index 00000000000..62db59bd858 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/DeleteObjectWrapperForSourceElementsTest.java @@ -0,0 +1,183 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST, ALL4TEC and others. + * + * 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: + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 525245 + *****************************************************************************/ + +package org.eclipse.papyrus.uml.nattable.matrix.tests.tests; + +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.nattable.manager.table.IMatrixTableWidgetManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.IMasterAxisProvider; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.junit.utils.rules.ActiveTable; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.Package; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test the deletion of object wrappers when source elements are removed in Model Explorer as described in the bug 525245. + */ +@SuppressWarnings("nls") +@PluginResource("resources/deleteObjectWrapperForSourceElementsTest/DeleteObjectWrapperForSourceElements.di") +public class DeleteObjectWrapperForSourceElementsTest extends AbstractTableTest { + + /** The Package1 package. */ + private Package package1 = null; + + /** The Package2 as column source. */ + private Package package2ColumnSource = null; + + /** The Package3 as column source. */ + private Package package3ColumnSource = null; + + /** The Package4 as row source. */ + private Package package4RowSource = null; + + /** The initial number column sources. */ + private int initNumberColumnSources; + + /** The initial number row sources. */ + private int initNumberRowSources; + + /** The transactional editing domain. */ + private TransactionalEditingDomain editingDomain = null; + + /** The papyrus table. */ + private Table table = null; + + /** The current column axis provider. */ + private IMasterAxisProvider currentColumnAxisProvider = null; + + /** The current row axis provider. */ + private IMasterAxisProvider currentRowAxisProvider = null; + + /** + * Default constructor. + */ + public DeleteObjectWrapperForSourceElementsTest() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + public void initTest() { + super.initTest(); + + table = this.manager.getTable(); + Assert.assertNotNull(table); + + Assert.assertTrue("The manager must be a matrix nattable model manager", this.manager instanceof IMatrixTableWidgetManager); + editingDomain = fixture.getEditingDomain(); + Model rootModel = (Model) fixture.getModel(); + + // Package1 contains others packages + package1 = (Package) rootModel.getPackagedElement("Package1"); + Assert.assertNotNull(package1); + + // Package2 and Package3 (each has 2 elements) are used as column source axis + package2ColumnSource = package1.getNestedPackage("Package2"); + Assert.assertNotNull(package2ColumnSource); + package3ColumnSource = package1.getNestedPackage("Package3"); + Assert.assertNotNull(package3ColumnSource); + + // The number column sources must be 2 + currentColumnAxisProvider = (IMasterAxisProvider) table.getCurrentColumnAxisProvider(); + initNumberColumnSources = currentColumnAxisProvider.getSources().size(); + Assert.assertEquals(2, initNumberColumnSources); + + // Package4 with 2 elements is used as row source axis + package4RowSource = package1.getNestedPackage("Package4"); + Assert.assertNotNull(package4RowSource); + + // The number of row sources must be 2 + currentRowAxisProvider = (IMasterAxisProvider) table.getCurrentRowAxisProvider(); + initNumberRowSources = currentRowAxisProvider.getSources().size(); + Assert.assertEquals(2, initNumberRowSources); + } + + /** + * This tests the delete of one element in a row source package. + * The row object wrapper must be deleted too. + */ + @Test + @ActiveTable("RelationshipGenericMatrix") + public void testDeleteARowSourceElement() { + initTest(); + + final Interface interface1 = (Interface) package4RowSource.getPackagedElement("Interface1"); + Assert.assertNotNull(interface1); + + // Delete the Interface1 element inside the Package4 + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(interface1); + final ICommand cmd = provider.getEditCommand(new DestroyElementRequest(interface1, false)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd)); + + // The number row sources must be decreased by 1 because the corresponding row object wrapper is also deleted + Assert.assertEquals(1, currentRowAxisProvider.getSources().size()); + checkUndoRedo(0, -1); + } + + /** + * This tests the delete of one element as a column source package. + * The column object wrapper must be deleted too. + */ + @Test + @ActiveTable("RelationshipGenericMatrix") + public void testDeleteAColumnSourcePackage() { + initTest(); + + // Delete the Package3 which is selected as a column source object + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(package3ColumnSource); + final ICommand cmd = provider.getEditCommand(new DestroyElementRequest(package3ColumnSource, false)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd)); + + // The number column sources must be decreased by 1 because the corresponding column object wrapper is also deleted + Assert.assertEquals(1, currentColumnAxisProvider.getSources().size()); + checkUndoRedo(-1, 0); + } + + /** + * Check the undo/redo operation. + * + * @param numberColumnSourcesAffected The number of source columns is affected by the command, 0 for unchanged, >0 for increment, <0 for decrement + * @param numberRowSourcesAffected The number of source rows is affected by the command, 0 for unchanged, >0 for increment, <0 for decrement + */ + private void checkUndoRedo(final int numberColumnSourcesAffected, final int numberRowSourcesAffected) { + // Check the undo + editingDomain.getCommandStack().undo(); + Assert.assertEquals(initNumberColumnSources, currentColumnAxisProvider.getSources().size()); + Assert.assertEquals(initNumberRowSources, currentRowAxisProvider.getSources().size()); + + // Check the redo + editingDomain.getCommandStack().redo(); + Assert.assertEquals(initNumberColumnSources + numberColumnSourcesAffected, currentColumnAxisProvider.getSources().size()); + Assert.assertEquals(initNumberRowSources + numberRowSourcesAffected, currentRowAxisProvider.getSources().size()); + } + + /** + * {@inheritDoc} + */ + @Override + protected String getSourcePath() { + return "resources/deleteObjectWrapperForSourceElementsTest/"; + } +} |