Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2015-07-23 10:12:15 +0000
committerNicolas FAUVERGUE2015-07-23 10:12:15 +0000
commit731587d29c1cc77db57d7d54613ff1479d271e2d (patch)
tree19be2089119d4acdef3e67b462d7347f596ad56c
parent9dec4b826e348aa7495ec1ab6a1e343a0845dd71 (diff)
downloadorg.eclipse.papyrus-731587d29c1cc77db57d7d54613ff1479d271e2d.tar.gz
org.eclipse.papyrus-731587d29c1cc77db57d7d54613ff1479d271e2d.tar.xz
org.eclipse.papyrus-731587d29c1cc77db57d7d54613ff1479d271e2d.zip
Bug 469443: [Table] JUnit tests will implement the invert axis action
for synchronized and generic tables https://bugs.eclipse.org/bugs/show_bug.cgi?id=469443 - Add invert axis action JUnit tests for generic and synchronized tables Change-Id: I5ab7f4bc83abb90ada7a34e7d9f4deb29118baac Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
-rwxr-xr-xtests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/AllTests.java1
-rw-r--r--tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/InvertAxisRequirementTableTest.java186
-rwxr-xr-xtests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java1
-rw-r--r--tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/InvertAxisGenericTableTest.java195
4 files changed, 383 insertions, 0 deletions
diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/AllTests.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/AllTests.java
index 918f06ce982..1a1e2d760f6 100755
--- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/AllTests.java
+++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/AllTests.java
@@ -21,6 +21,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
SortAxisRequirementTableTest.class,
+ InvertAxisRequirementTableTest.class,
Bug443814_Enumeration.class,
TableCreationInSysMLModelTest.class,
OpenTableTest.class,
diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/InvertAxisRequirementTableTest.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/InvertAxisRequirementTableTest.java
new file mode 100644
index 00000000000..03bf28a8fe6
--- /dev/null
+++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/tests/InvertAxisRequirementTableTest.java
@@ -0,0 +1,186 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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.sysml.nattable.requirement.tests.tests;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+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.nattableaxis.IAxis;
+import org.eclipse.papyrus.junit.utils.GenericUtils;
+import org.eclipse.papyrus.sysml.nattable.requirement.tests.paste.without.service.edit.AbstractOpenTableTest;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * This class allows to test the invert axis in the Requirements NatTable
+ */
+public class InvertAxisRequirementTableTest extends AbstractOpenTableTest {
+
+ /**
+ * The file name of the papyrus project used.
+ */
+ public static String fileName = "contents_sort_invert_edit_model"; //$NON-NLS-1$
+
+ /**
+ * The first class name in the model.
+ */
+ private static final String FIRST_CLASS = "Class1"; //$NON-NLS-1$
+
+ /**
+ * The second class name in the model.
+ */
+ private static final String SECOND_CLASS = "Class2"; //$NON-NLS-1$
+
+ /**
+ * The second class name in the model.
+ */
+ private static final String THIRD_CLASS = "Class3"; //$NON-NLS-1$
+
+ /**
+ * The 'derived' property of requirement stereotype.
+ */
+ private static final String DERIVED_PROPERTY = "property_of_stereotype:/SysML::Requirements::Requirement::derived"; //$NON-NLS-1$
+
+ /**
+ * The 'traced to' property of requirement stereotype.
+ */
+ private static final String TRACED_TO_PROPERTY = "property_of_stereotype:/SysML::Requirements::Requirement::tracedTo"; //$NON-NLS-1$
+
+ /**
+ * Initialize the model.
+ *
+ * @throws Exception
+ * The exception.
+ */
+ @Before
+ public void initModel() throws Exception {
+ initModel("RequirementTable", fileName, getBundle()); //$NON-NLS-1$
+ };
+
+ /**
+ * This allow to test the invert axis method.
+ *
+ * @throws Exception
+ * The exception.
+ */
+ @Test
+ public void invertAxis() throws Exception {
+ testOpenExistingTable(fileName, "RequirementTable"); //$NON-NLS-1$
+ IEditorPart tableEditor = editor.getActiveEditor();
+ Assert.assertTrue(tableEditor instanceof NatTableEditor);
+ INattableModelManager manager = (INattableModelManager) tableEditor.getAdapter(INattableModelManager.class);
+
+ // Check the initial rows ans columns
+ Assert.assertEquals(4, manager.getColumnElementsList().size());
+ Assert.assertEquals(3, manager.getRowElementsList().size());
+ checkInitialTable(manager.getColumnElementsList(), manager.getRowElementsList());
+
+ // Invert Axis and check the rows and columns
+ manager.invertAxis();
+ Assert.assertEquals(4, manager.getRowElementsList().size());
+ Assert.assertEquals(3, manager.getColumnElementsList().size());
+ checkInitialTable(manager.getRowElementsList(), manager.getColumnElementsList());
+
+ // Invert Axis a second time and check the rows and columns
+ manager.invertAxis();
+ Assert.assertEquals(4, manager.getColumnElementsList().size());
+ Assert.assertEquals(3, manager.getRowElementsList().size());
+ checkInitialTable(manager.getColumnElementsList(), manager.getRowElementsList());
+
+ checkUndoRedo(manager);
+ }
+
+ /**
+ * This allow to check the undo and the redo action.
+ *
+ * @param manager The nattable model manager.
+ * @throws Exception The exception.
+ */
+ public void checkUndoRedo(final INattableModelManager manager) throws Exception {
+ getTransactionalEditingDomain().getCommandStack().undo();
+ Assert.assertEquals(4, manager.getRowElementsList().size());
+ Assert.assertEquals(3, manager.getColumnElementsList().size());
+ checkInitialTable(manager.getRowElementsList(), manager.getColumnElementsList());
+
+ // check the redo
+ getTransactionalEditingDomain().getCommandStack().redo();
+ Assert.assertEquals(4, manager.getColumnElementsList().size());
+ Assert.assertEquals(3, manager.getRowElementsList().size());
+ checkInitialTable(manager.getColumnElementsList(), manager.getRowElementsList());
+ }
+
+ /**
+ * This allow to test the row and the columns elements.
+ *
+ * @param columnElements
+ * The column elements.
+ * @param rowElements
+ * The row elements.
+ * @throws Exception
+ * The exception.
+ */
+ private void checkInitialTable(List<?> columnElements, final List<?> rowElements) throws Exception {
+ // Check the columns elements
+ IAxis firstColumn = (IAxis) columnElements.get(0);
+ Object firstColumnRepresentedElement = firstColumn.getElement();
+ Assert.assertEquals(UMLPackage.Literals.NAMED_ELEMENT__NAME, firstColumnRepresentedElement);
+
+ IAxis secondColumn = (IAxis) columnElements.get(1);
+ Object secondColumnRepresentedElement = secondColumn.getElement();
+ Assert.assertEquals(UMLPackage.Literals.NAMED_ELEMENT__VISIBILITY, secondColumnRepresentedElement);
+
+ IAxis thirdColumn = (IAxis) columnElements.get(2);
+ Object thirdColumnRepresentedElement = thirdColumn.getElement();
+ Assert.assertEquals(DERIVED_PROPERTY, thirdColumnRepresentedElement);
+
+ IAxis fourthColumn = (IAxis) columnElements.get(3);
+ Object fourthColumnRepresentedElement = fourthColumn.getElement();
+ Assert.assertEquals(TRACED_TO_PROPERTY, fourthColumnRepresentedElement);
+
+ // Check the row elements
+ EObject firstRow = (EObject) rowElements.get(0);
+ Assert.assertEquals(UMLPackage.eINSTANCE.getClass_(), ((EObject) firstRow).eClass());
+ Assert.assertEquals(FIRST_CLASS, ((org.eclipse.uml2.uml.Class) firstRow).getName());
+
+ EObject secondRow = (EObject) rowElements.get(1);
+ Assert.assertEquals(UMLPackage.eINSTANCE.getClass_(), ((EObject) secondRow).eClass());
+ Assert.assertEquals(SECOND_CLASS, ((org.eclipse.uml2.uml.Class) secondRow).getName());
+
+ EObject thirdRow = (EObject) rowElements.get(2);
+ Assert.assertEquals(UMLPackage.eINSTANCE.getClass_(), ((EObject) thirdRow).eClass());
+ Assert.assertEquals(THIRD_CLASS, ((org.eclipse.uml2.uml.Class) thirdRow).getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getSourcePath() {
+ return "/resources/contents_tests_resources/"; //$NON-NLS-1$
+ }
+
+ /**
+ * This allow to close the opened editors.
+ */
+ @AfterClass
+ public static void endOfTest() {
+ GenericUtils.closeAllEditors();
+ }
+}
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 63f04a2fecf..06a26555d51 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.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
SortAxisGenericTableTest.class,
+ InvertAxisGenericTableTest.class,
OpenAndDeleteTest.class,
Bug458492_Edition_Enumeration.class,
RevealGenericTableTest.class,
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/InvertAxisGenericTableTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/InvertAxisGenericTableTest.java
new file mode 100644
index 00000000000..b002168d3f0
--- /dev/null
+++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/InvertAxisGenericTableTest.java
@@ -0,0 +1,195 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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.tests;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+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.nattableaxis.IAxis;
+import org.eclipse.papyrus.junit.utils.GenericUtils;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * This class allows to test the invert axis in the Generic NatTable
+ */
+public class InvertAxisGenericTableTest extends AbstractGenericTableTest {
+
+ /**
+ * The file name of the papyrus project used.
+ */
+ public static String fileName = "contents_sort_invert_edit_model"; //$NON-NLS-1$
+
+ /**
+ * The first class name in the model.
+ */
+ private static final String FIRST_CLASS = "Class1"; //$NON-NLS-1$
+
+ /**
+ * The second class name in the model.
+ */
+ private static final String SECOND_CLASS = "Class2"; //$NON-NLS-1$
+
+ /**
+ * The first attribute name in the model.
+ */
+ private static final String FIRST_PROPERTY = "Attribute11"; //$NON-NLS-1$
+
+ /**
+ * The second attribute name in the model.
+ */
+ private static final String SECOND_PROPERTY = "Attribute12"; //$NON-NLS-1$
+
+ /**
+ * The third attribute name in the model.
+ */
+ private static final String THIRD_PROPERTY = "Attribute21"; //$NON-NLS-1$
+
+ /**
+ * Initialize the model.
+ *
+ * @throws Exception
+ * The exception.
+ */
+ @Before
+ public void initModel() throws Exception {
+ initModel("GenericTable", fileName, getBundle()); //$NON-NLS-1$
+ };
+
+ /**
+ * This allow to test the invert axis method.
+ *
+ * @throws Exception
+ * The exception.
+ */
+ @Test
+ public void invertAxis() throws Exception {
+ loadGenericTable();
+ IEditorPart tableEditor = editor.getActiveEditor();
+ Assert.assertTrue(tableEditor instanceof NatTableEditor);
+ INattableModelManager manager = (INattableModelManager) tableEditor.getAdapter(INattableModelManager.class);
+
+ // Check the initial rows ans columns
+ Assert.assertEquals(3, manager.getColumnElementsList().size());
+ Assert.assertEquals(5, manager.getRowElementsList().size());
+ checkInitialTable(manager.getColumnElementsList(), manager.getRowElementsList());
+
+ // Invert Axis and check the rows and columns
+ manager.invertAxis();
+ Assert.assertEquals(3, manager.getRowElementsList().size());
+ Assert.assertEquals(5, manager.getColumnElementsList().size());
+ checkInitialTable(manager.getRowElementsList(), manager.getColumnElementsList());
+
+ // Invert Axis a second time and check the rows and columns
+ manager.invertAxis();
+ Assert.assertEquals(3, manager.getColumnElementsList().size());
+ Assert.assertEquals(5, manager.getRowElementsList().size());
+ checkInitialTable(manager.getColumnElementsList(), manager.getRowElementsList());
+
+ checkUndoRedo(manager);
+ }
+
+ /**
+ * This allow to check the undo and the redo action.
+ *
+ * @param manager The nattable model manager.
+ * @throws Exception The exception.
+ */
+ public void checkUndoRedo(final INattableModelManager manager) throws Exception {
+ getTransactionalEditingDomain().getCommandStack().undo();
+ Assert.assertEquals(3, manager.getRowElementsList().size());
+ Assert.assertEquals(5, manager.getColumnElementsList().size());
+ checkInitialTable(manager.getRowElementsList(), manager.getColumnElementsList());
+
+ // check the redo
+ getTransactionalEditingDomain().getCommandStack().redo();
+ Assert.assertEquals(3, manager.getColumnElementsList().size());
+ Assert.assertEquals(5, manager.getRowElementsList().size());
+ checkInitialTable(manager.getColumnElementsList(), manager.getRowElementsList());
+ }
+
+ /**
+ * This allow to test the row and the columns elements.
+ *
+ * @param columnElements
+ * The column elements.
+ * @param rowElements
+ * The row elements.
+ * @throws Exception
+ * The exception.
+ */
+ private void checkInitialTable(List<?> columnElements, final List<?> rowElements) throws Exception {
+ // Check the columns elements
+ IAxis firstColumn = (IAxis) columnElements.get(0);
+ Object firstColumnRepresentedElement = firstColumn.getElement();
+ Assert.assertEquals(UMLPackage.Literals.NAMED_ELEMENT__NAME, firstColumnRepresentedElement);
+
+ IAxis secondColumn = (IAxis) columnElements.get(1);
+ Object secondColumnRepresentedElement = secondColumn.getElement();
+ Assert.assertEquals(UMLPackage.Literals.PROPERTY__DEFAULT_VALUE, secondColumnRepresentedElement);
+
+ IAxis thirdColumn = (IAxis) columnElements.get(2);
+ Object thirdColumnRepresentedElement = thirdColumn.getElement();
+ Assert.assertEquals(UMLPackage.Literals.TYPED_ELEMENT__TYPE, thirdColumnRepresentedElement);
+
+ // Check the row elements
+ IAxis firstRow = (IAxis) rowElements.get(0);
+ Object firstRowRepresentedElement = firstRow.getElement();
+ Assert.assertEquals(UMLPackage.eINSTANCE.getClass_(), ((EObject) firstRowRepresentedElement).eClass());
+ Assert.assertEquals(FIRST_CLASS, ((org.eclipse.uml2.uml.Class) firstRowRepresentedElement).getName());
+
+ IAxis secondRow = (IAxis) rowElements.get(1);
+ Object secondRowRepresentedElement = secondRow.getElement();
+ Assert.assertEquals(UMLPackage.eINSTANCE.getProperty(), ((EObject) secondRowRepresentedElement).eClass());
+ Assert.assertEquals(FIRST_PROPERTY, ((Property) secondRowRepresentedElement).getName());
+
+ IAxis thirdRow = (IAxis) rowElements.get(2);
+ Object thirdRowRepresentedElement = thirdRow.getElement();
+ Assert.assertEquals(UMLPackage.eINSTANCE.getProperty(), ((EObject) thirdRowRepresentedElement).eClass());
+ Assert.assertEquals(SECOND_PROPERTY, ((Property) thirdRowRepresentedElement).getName());
+
+ IAxis fourthRow = (IAxis) rowElements.get(3);
+ Object fourthRowRepresentedElement = fourthRow.getElement();
+ Assert.assertEquals(UMLPackage.eINSTANCE.getClass_(), ((EObject) fourthRowRepresentedElement).eClass());
+ Assert.assertEquals(SECOND_CLASS, ((org.eclipse.uml2.uml.Class) fourthRowRepresentedElement).getName());
+
+ IAxis fifthRow = (IAxis) rowElements.get(4);
+ Object fifthRowRepresentedElement = fifthRow.getElement();
+ Assert.assertEquals(UMLPackage.eINSTANCE.getProperty(), ((EObject) fifthRowRepresentedElement).eClass());
+ Assert.assertEquals(THIRD_PROPERTY, ((Property) fifthRowRepresentedElement).getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getSourcePath() {
+ return "/resources/contents_tests_resources/"; //$NON-NLS-1$
+ }
+
+ /**
+ * This allow to close the opened editors.
+ */
+ @AfterClass
+ public static void endOfTest() {
+ GenericUtils.closeAllEditors();
+ }
+}

Back to the top