diff options
author | Thanh Liem PHAN | 2017-09-18 12:21:28 +0000 |
---|---|---|
committer | vincent lorenzo | 2017-10-13 11:37:12 +0000 |
commit | 4c93d5e4b17c4f1f18f957ad76a854fa1d739dcc (patch) | |
tree | a70ca088b6ac4663ad08f4f36a3060d0bf8b1055 /tests/junit | |
parent | 41bdcbc85529c0a0e9d4c456c98493d09101146e (diff) | |
download | org.eclipse.papyrus-4c93d5e4b17c4f1f18f957ad76a854fa1d739dcc.tar.gz org.eclipse.papyrus-4c93d5e4b17c4f1f18f957ad76a854fa1d739dcc.tar.xz org.eclipse.papyrus-4c93d5e4b17c4f1f18f957ad76a854fa1d739dcc.zip |
Bug 520602: [Matrix][Table] Columns are not deleted when the semantic
element is destroyed from the ModelExplorer
https://bugs.eclipse.org/bugs/show_bug.cgi?id=520602
- Update column axis when related elements are added, removed or moved
- TU to check the update of axis columns
Change-Id: Ifd65f809ad6f1d1f72d774e7ca20019802b1ac0f
Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
Diffstat (limited to 'tests/junit')
7 files changed, 327 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 37bf4c735c2..ac9f11d8a0e 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 @@ -13,5 +13,6 @@ Require-Bundle: org.junit;bundle-version="[4.12.0,5.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.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)" + org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.100,2.0.0)", + org.eclipse.papyrus.uml.service.types;bundle-version="[3.1.0,4.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/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.di new file mode 100644 index 00000000000..08128862c28 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.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/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.notation new file mode 100644 index 00000000000..9758be5c890 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.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="__dqcoKnKEeeZP8TFsrH34Q" name="Relationship Generic Matrix" currentRowAxisProvider="__dqco6nKEeeZP8TFsrH34Q" currentColumnAxisProvider="__dqcoqnKEeeZP8TFsrH34Q" tableKindId="org.eclipse.papyrus.uml.table.matrix">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__eRgoKnKEeeZP8TFsrH34Q" source="http://www.eclipse.org/papyrus/infra/nattable/version">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="__eRgoanKEeeZP8TFsrH34Q" key="version" value="1.3.0"/>
+ </eAnnotations>
+ <styles xmi:type="nattablestyle:IntListValueStyle" xmi:id="__dqcoanKEeeZP8TFsrH34Q" name="hiddenCategoriesByDepth">
+ <intListValue>1</intListValue>
+ </styles>
+ <context xmi:type="uml:Model" href="UpdateMatrixAxisColumnTest.uml#_Mipu4JoSEeeMicUUPua1Vw"/>
+ <owner xmi:type="uml:Model" href="UpdateMatrixAxisColumnTest.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="__dqcoqnKEeeZP8TFsrH34Q" description="This axis provider manages the columns, according to the wanted hierarchy" name="HierarchicalColumnsAxisManager" disconnectSlave="true">
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_FO8ewKnLEeeZP8TFsrH34Q">
+ <element xmi:type="uml:Package" href="UpdateMatrixAxisColumnTest.uml#_TzF2oJoSEeeMicUUPua1Vw"/>
+ </sources>
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_FO8ewanLEeeZP8TFsrH34Q">
+ <element xmi:type="uml:Package" href="UpdateMatrixAxisColumnTest.uml#_YHPMYJoSEeeMicUUPua1Vw"/>
+ </sources>
+ </columnAxisProvidersHistory>
+ <rowAxisProvidersHistory xmi:type="nattableaxisprovider:MasterObjectAxisProvider" xmi:id="__dqco6nKEeeZP8TFsrH34Q" description="This axis provider manages the rows, according to the wanted hierarchy" name="HierarchicalRowAxisManager" disconnectSlave="true">
+ <axis xmi:type="nattableaxis:EObjectTreeItemAxis" xmi:id="_L010sKnLEeeZP8TFsrH34Q">
+ <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="UpdateMatrixAxisColumnTest.uml#_d_8FIJoSEeeMicUUPua1Vw"/>
+ </axis>
+ <axis xmi:type="nattableaxis:EObjectTreeItemAxis" xmi:id="_L010sanLEeeZP8TFsrH34Q">
+ <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="UpdateMatrixAxisColumnTest.uml#_fCThEJoSEeeMicUUPua1Vw"/>
+ </axis>
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_L010sqnLEeeZP8TFsrH34Q">
+ <element xmi:type="uml:Interface" href="UpdateMatrixAxisColumnTest.uml#_d_8FIJoSEeeMicUUPua1Vw"/>
+ </sources>
+ <sources xmi:type="nattablewrapper:EObjectWrapper" xmi:id="_L010s6nLEeeZP8TFsrH34Q">
+ <element xmi:type="uml:Interface" href="UpdateMatrixAxisColumnTest.uml#_fCThEJoSEeeMicUUPua1Vw"/>
+ </sources>
+ </rowAxisProvidersHistory>
+ <ownedCellEditorConfigurations xmi:type="nattablecelleditor:GenericRelationshipMatrixCellEditorConfiguration" xmi:id="__dqcpKnKEeeZP8TFsrH34Q" cellEditorId="GenericRelationshipMatrixEditorConfiguration"/>
+</nattable:Table>
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.uml new file mode 100644 index 00000000000..fd7d4e89feb --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.uml @@ -0,0 +1,19 @@ +<?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="UpdateMatrixAxisColumnTest">
+ <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="_TzF2oJoSEeeMicUUPua1Vw" name="Package1_ColumnSource">
+ <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="Package2_ColumnSource">
+ <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="Package3_RowSource">
+ <packagedElement xmi:type="uml:Interface" xmi:id="_d_8FIJoSEeeMicUUPua1Vw" name="Interface1"/>
+ <packagedElement xmi:type="uml:Interface" xmi:id="_fCThEJoSEeeMicUUPua1Vw" name="Interface2"/>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Enumeration" xmi:id="_kCgHsJoWEeeMicUUPua1Vw" name="Enumeration1"/>
+</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/AbstractTableTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AbstractTableTest.java index 60a43665fe2..60a43665fe2 100755..100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AbstractTableTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/AbstractTableTest.java 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 f25b8bdb7e7..31603fe91a8 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, 525367 + * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 525245, 525367, 520602 *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.matrix.tests.tests; @@ -24,7 +24,9 @@ import org.junit.runners.Suite.SuiteClasses; UpdateTableAfterEditingRowSourceTest.class, UpdateTableAfterEditingColumnSourceTest.class, UpdateTableContentsAfterExpressionChangeWithLocalHeaderPreconfiguredTests.class, - DeleteObjectWrapperForSourceElementsTest.class + DeleteObjectWrapperForSourceElementsTest.class, + // Bug 520602 - Columns are not deleted when the semantic element is destroyed from the ModelExplorer + UpdateMatrixAxisColumnTest.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/UpdateMatrixAxisColumnTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/UpdateMatrixAxisColumnTest.java new file mode 100644 index 00000000000..678942b850c --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.matrix.tests/src/org/eclipse/papyrus/uml/nattable/matrix/tests/tests/UpdateMatrixAxisColumnTest.java @@ -0,0 +1,263 @@ +/***************************************************************************** + * 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 520602 + *****************************************************************************/ + +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.CreateElementRequest; +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.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.manager.table.IMatrixTableWidgetManager; +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.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.Package; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test the update of matrix axis columns when model element are changed as described in the bug 520602. + */ +@SuppressWarnings("nls") +@PluginResource("resources/updateMatrixAxisColumnTests/UpdateMatrixAxisColumnTest.di") +public class UpdateMatrixAxisColumnTest extends AbstractTableTest { + + /** The root model. */ + private Model rootModel = null; + + /** The Package1 as column source. */ + private Package package1ColumnSource = null; + + /** The Package2 as column source. */ + private Package package2ColumnSource = null; + + /** The Package3 as row source. */ + private Package package3RowSource = null; + + /** The initial number column. */ + private int initNumberColumn; + + /** The initial column names string. */ + private String initColumnNames; + + /** The transactional editing domain. */ + private TransactionalEditingDomain editingDomain = null; + + /** + * Default constructor. + */ + public UpdateMatrixAxisColumnTest() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + public void initTest() { + super.initTest(); + + final IEditorPart tableEditor = fixture.getActiveTableEditor(); + Assert.assertTrue("Table editor must be a nattable editor", tableEditor instanceof NatTableEditor); + + Assert.assertTrue("The manager must be a matrix nattable model manager", this.manager instanceof IMatrixTableWidgetManager); + editingDomain = fixture.getEditingDomain(); + rootModel = (Model) fixture.getModel(); + + // Package1 and Package2 (each has 2 elements) are used as column source axis + package1ColumnSource = rootModel.getNestedPackage("Package1_ColumnSource"); + Assert.assertNotNull(package1ColumnSource); + package2ColumnSource = rootModel.getNestedPackage("Package2_ColumnSource"); + Assert.assertNotNull(package2ColumnSource); + + // Check the column header names + initColumnNames = getAllAxisNameString(manager.getVerticalFilterList()); + Assert.assertEquals("Class1, Class2, Component1, Component2", getAllAxisNameString(manager.getVerticalFilterList())); + + // The initial number of column axis must equal 4 + initNumberColumn = manager.getColumnCount(); + Assert.assertEquals(4, initNumberColumn); + + // Package3 with 2 elements is used as row source axis + package3RowSource = rootModel.getNestedPackage("Package3_RowSource"); + Assert.assertNotNull(package3RowSource); + + // Check the row header names + Assert.assertEquals("Interface1, Interface2", getAllAxisNameString(manager.getHorizontalFilterEventList())); + // The initial number of row axis must be 2 + Assert.assertEquals(2, manager.getRowCount()); + } + + /** + * This tests the addition of one element in a column source package. + * A new column must be inserted in the column axis of the table. + */ + @Test + @ActiveTable("Relationship Generic Matrix") + public void testAddElementInsideAColumnSourcePackage() { + initTest(); + + // Add a new class inside the Package2 + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(package1ColumnSource); + ICommand cmd = provider.getEditCommand(new CreateElementRequest(package1ColumnSource, UMLElementTypes.CLASS)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute((new GMFtoEMFCommandWrapper(cmd))); + + String expectedColumnNames = "Class1, Class2, Class3, Component1, Component2"; + + // Check the column header names + Assert.assertEquals(expectedColumnNames, getAllAxisNameString(manager.getVerticalFilterList())); + + // The number of column axis must be increased by 1 + Assert.assertEquals(5, manager.getColumnCount()); + + checkUndoRedo(1, expectedColumnNames); + } + + /** + * This tests the addition of one element outside the column source objects. + * The table column axis must not be changed. + */ + @Test + @ActiveTable("Relationship Generic Matrix") + public void testAddElementOutsideColumnSourcePackages(){ + initTest(); + + // Add a new class inside the Package1 + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(rootModel); + ICommand cmd = provider.getEditCommand(new CreateElementRequest(rootModel, UMLElementTypes.CLASS)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute((new GMFtoEMFCommandWrapper(cmd))); + + // The column header names must be the same + Assert.assertEquals(initColumnNames, getAllAxisNameString(manager.getVerticalFilterList())); + + // The number of column axis must not be changed + Assert.assertEquals(4, manager.getColumnCount()); + + checkUndoRedo(0, initColumnNames); + } + + /** + * This tests the delete of one element in a column source package. + * The corresponding column axis must be removed from the table. + */ + @Test + @ActiveTable("Relationship Generic Matrix") + public void testDeleteElementInsideAColumnSourcePackage() { + initTest(); + + Class class1 = (Class) package1ColumnSource.getPackagedElement("Class1"); + Assert.assertNotNull(class1); + + // Delete the Class1 element inside the Package2 + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(class1); + ICommand cmd = provider.getEditCommand(new DestroyElementRequest(class1, false)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute((new GMFtoEMFCommandWrapper(cmd))); + + // The column corresponding to Class1 element is deleted + String expectedColumnNames = "Class2, Component1, Component2"; + Assert.assertEquals(expectedColumnNames, getAllAxisNameString(manager.getVerticalFilterList())); + + // The number of column axis must be decreased by 1 + Assert.assertEquals(3, manager.getColumnCount()); + + checkUndoRedo(-1, expectedColumnNames); + } + + /** + * This tests the delete of one element outside the column source objects. + * The table column axis must not be changed. + */ + @Test + @ActiveTable("Relationship Generic Matrix") + public void testDeleteElementOutsideColumnSourcePackages() { + initTest(); + + Enumeration enum1 = (Enumeration) rootModel.getPackagedElement("Enumeration1"); + Assert.assertNotNull(enum1); + + // Delete the Enumeration1 element inside the Root model + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(enum1); + ICommand cmd = provider.getEditCommand(new DestroyElementRequest(enum1, false)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute((new GMFtoEMFCommandWrapper(cmd))); + + // The column header names must be the same + Assert.assertEquals(initColumnNames, getAllAxisNameString(manager.getVerticalFilterList())); + + // The number of column axis must not be changed + Assert.assertEquals(initNumberColumn, manager.getColumnCount()); + + checkUndoRedo(0, initColumnNames); + } + + /** + * This tests the delete of one column source object package. + * All column axis corresponding to the deleted one must also be removed from the table. + */ + @Test + @ActiveTable("Relationship Generic Matrix") + public void testDeleteAColumnSourcePackage() { + initTest(); + + // Delete the Package2 column source + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(package2ColumnSource); + ICommand cmd = provider.getEditCommand(new DestroyElementRequest(package2ColumnSource, false)); + Assert.assertTrue(cmd.canExecute()); + editingDomain.getCommandStack().execute((new GMFtoEMFCommandWrapper(cmd))); + + // There are only 2 columns corresponding to elements in the Package1 + String expectedColumnNames = "Class1, Class2"; + Assert.assertEquals(expectedColumnNames, getAllAxisNameString(manager.getVerticalFilterList())); + + // The number of column axis must be decreased by 2 + Assert.assertEquals(2, manager.getColumnCount()); + + checkUndoRedo(-2, expectedColumnNames); + } + + /** + * Check the undo/redo operation. + * + * @param numberColumnAffected The number of column is affected by the command, 0 for unchanged, >0 for number columns are added, <0 for number columns are deleted + * @param expectedColumnNamesString The expected column names string + */ + private void checkUndoRedo(final int numberColumnAffected, final String expectedColumnNamesString) { + // Check the undo + editingDomain.getCommandStack().undo(); + Assert.assertEquals(initColumnNames, getAllAxisNameString(manager.getVerticalFilterList())); + Assert.assertEquals(initNumberColumn, manager.getColumnCount()); + + // Check the redo + editingDomain.getCommandStack().redo(); + Assert.assertEquals(expectedColumnNamesString, getAllAxisNameString(manager.getVerticalFilterList())); + Assert.assertEquals(initNumberColumn + numberColumnAffected, manager.getColumnCount()); + } + + /** + * {@inheritDoc} + */ + @Override + protected String getSourcePath() { + return "resources/updateMatrixAxisColumnTests/"; //$NON-NLS-1$ + } +} |