From 4edc19c798eaa3aba0b1f2d083e49cea9eb04d60 Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Wed, 3 Feb 2016 11:21:19 +0100 Subject: Bug 435417: [table] NPE when removing profile from model https://bugs.eclipse.org/bugs/show_bug.cgi?id=435417 Add the JUnit tests. Change-Id: I169ae6aad44dd803917bdc07cf0ec749b26bc692 Signed-off-by: Nicolas FAUVERGUE --- .../resources/bugs/bug435417/435417.di | 2 + .../resources/bugs/bug435417/435417.notation | 27 ++++ .../resources/bugs/bug435417/435417.profile.di | 2 + .../bugs/bug435417/435417.profile.notation | 99 +++++++++++++++ .../resources/bugs/bug435417/435417.profile.uml | 123 ++++++++++++++++++ .../resources/bugs/bug435417/435417.uml | 20 +++ .../tests/bugs/StereotypeInheritDisplayTest.java | 139 +++++++++++++++++++++ .../uml/nattable/generic/tests/tests/AllTests.java | 4 + 8 files changed, 416 insertions(+) create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.di create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.notation create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.di create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.notation create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.uml create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.uml create mode 100644 tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/StereotypeInheritDisplayTest.java (limited to 'tests') diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.di @@ -0,0 +1,2 @@ + + diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.notation new file mode 100644 index 00000000000..e61e10aa48e --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.notation @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.di @@ -0,0 +1,2 @@ + + diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.notation new file mode 100644 index 00000000000..8c5401627a5 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.notation @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.uml new file mode 100644 index 00000000000..48220960537 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.profile.uml @@ -0,0 +1,123 @@ + + + + + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.uml new file mode 100644 index 00000000000..a21bf49e011 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug435417/435417.uml @@ -0,0 +1,20 @@ + + + + + + +
+
+
+
+
+ + + + + + + + + diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/StereotypeInheritDisplayTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/StereotypeInheritDisplayTest.java new file mode 100644 index 00000000000..ad01e9ae0d2 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/StereotypeInheritDisplayTest.java @@ -0,0 +1,139 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST 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: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.nattable.generic.tests.bugs; + +import java.util.List; + +import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; +import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.TableUtils; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Model; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * This allows to test the stereotype inherit properties in the table. + */ +@PluginResource("resources/bugs/bug435417/435417.di") +public class StereotypeInheritDisplayTest extends AbstractPapyrusTest { + + /** + * The table name. + */ + private static final String TABLE_NAME = "GenericTable0"; //$NON-NLS-1$ + + /** + * The papyrus fixture. + */ + @Rule + public final PapyrusEditorFixture fixture = new PapyrusEditorFixture(); + + /** + * Constructor. + */ + public StereotypeInheritDisplayTest() { + super(); + } + + /** + * This allow to initialize the tests. + */ + @Before + public void init() { + final Model model = (Model) fixture.getModel(); + Assert.assertNotNull("RootModel is null", model); //$NON-NLS-1$ + + // Get the table and open it + Table mainTable = TableUtils.getNotationFirstTable(fixture.getModelSet(), TABLE_NAME); + fixture.getPageManager().openPage(mainTable); + fixture.flushDisplayEvents(); + } + + /** + * This allows to test the stereotype inherited properties displayed in the table + * + * @throws Exception + * The caught exception. + */ + @Test + public void testStereotypePropeties() throws Exception { + // Open the table and get the manager + final IPageManager pageManager = fixture.getPageManager(); + final List pages = pageManager.allPages(); + pageManager.openPage(pages.get(0)); + final IEditorPart part = fixture.getEditor().getActiveEditor(); + Assert.assertTrue(part instanceof NatTableEditor); + final NatTableEditor editor = (NatTableEditor) part; + final INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue(currentManager instanceof INattableModelManager); + + checkTableContent(currentManager); + } + + /** + * This allows to test the table cell editors and values. + * + * @param currentManager + * The current nattable model manager. + * @throws Exception + * The caught exception. + */ + protected void checkTableContent(final INattableModelManager currentManager) throws Exception { + // check the rows and columns number + Assert.assertEquals("The rows number is not the expected one", 1, currentManager.getRowCount()); //$NON-NLS-1$ + Assert.assertEquals("The columns number is not the expected one", 4, currentManager.getColumnCount()); //$NON-NLS-1$ + + // Check the cell editors + final ILayerCell cell0 = currentManager.getBodyLayerStack().getCellByPosition(0, 0); + Assert.assertNotEquals("The first cell must have config labels", null, cell0.getConfigLabels()); //$NON-NLS-1$ + Assert.assertNotEquals("The first cell must have at least one cell editor configuration", 0, cell0.getConfigLabels().getLabels().size()); //$NON-NLS-1$ + Assert.assertEquals("The first cell editor must be an UMLStereotypeSingleStringCellEditorConfiguration", "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleStringCellEditorConfiguration.MultiLineText0", //$NON-NLS-1$ //$NON-NLS-2$ + cell0.getConfigLabels().getLabels().get(0)); + + final ILayerCell cell1 = currentManager.getBodyLayerStack().getCellByPosition(1, 0); + Assert.assertNotEquals("The second cell must have config labels", null, cell1.getConfigLabels()); //$NON-NLS-1$ + Assert.assertNotEquals("The second cell must have at least one cell editor configuration", 0, cell1.getConfigLabels().getLabels().size()); //$NON-NLS-1$ + Assert.assertEquals("The second cell editor must be an UMLStereotypeSingleBooleanCellEditorConfiguration", "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleBooleanCellEditorConfiguration.CheckBox1", //$NON-NLS-1$ //$NON-NLS-2$ + cell1.getConfigLabels().getLabels().get(0)); + + final ILayerCell cell2 = currentManager.getBodyLayerStack().getCellByPosition(2, 0); + Assert.assertNotEquals("The third cell must have config labels", null, cell2.getConfigLabels()); //$NON-NLS-1$ + Assert.assertNotEquals("The third cell must have at least one cell editor configuration", 0, cell2.getConfigLabels().getLabels().size()); //$NON-NLS-1$ + Assert.assertEquals("The third cell editor must be an UMLStereotypeSingleIntegerCellEditorConfiguration", "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleIntegerCellEditorConfiguration.Text2", //$NON-NLS-1$ //$NON-NLS-2$ + cell2.getConfigLabels().getLabels().get(0)); + + final ILayerCell cell3 = currentManager.getBodyLayerStack().getCellByPosition(3, 0); + Assert.assertNotEquals("The fourth cell must have config labels", null, cell3.getConfigLabels()); //$NON-NLS-1$ + Assert.assertNotEquals("The fourth cell must have at least one cell editor configuration", 0, cell3.getConfigLabels().getLabels().size()); //$NON-NLS-1$ + Assert.assertEquals("The fourth cell editor must be an UMLStereotypeSingleRealCellEditorConfiguration", "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleRealCellEditorConfiguration.Text3", //$NON-NLS-1$ //$NON-NLS-2$ + cell3.getConfigLabels().getLabels().get(0)); + + // Check the values + Assert.assertEquals("The first value is not the expected one", "Vincent", currentManager.getDataValue(0, 0)); //$NON-NLS-1$ //$NON-NLS-2$ + Assert.assertEquals("The second value is not the expected one", true, currentManager.getDataValue(1, 0)); //$NON-NLS-1$ + Assert.assertEquals("The third value is not the expected one", 30, currentManager.getDataValue(2, 0));//$NON-NLS-1$ + Assert.assertEquals("The fourth value is not the expected one", 68.5, currentManager.getDataValue(3, 0)); //$NON-NLS-1$ + + } + +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java index 759eb4bd054..66ecf5dd0f3 100755 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java @@ -22,6 +22,7 @@ import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.CellEditorsConfigurat import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.InvertedAxisChangeIndexWithConfigurationTest; import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.InvertedAxisChangeIndexWithoutConfigurationTest; import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.OpenAndDeleteTest; +import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.StereotypeInheritDisplayTest; import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportCellsAll_Test; import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportEmptyAddAll_Test; import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportEmptyReplaceAll_Test; @@ -83,6 +84,9 @@ import org.junit.runners.Suite.SuiteClasses; FilterNumericMatcherTest.class, FilterUMLEnumerationMatcherTest.class, CellEditorsConfigurationTest.class, + + // Stereotype inherited properties + StereotypeInheritDisplayTest.class, // Paste Overwrite tests PasteEmptyClipboard_Test.class, -- cgit v1.2.3