diff options
Diffstat (limited to 'tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse')
53 files changed, 3146 insertions, 1 deletions
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportCellsTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportCellsTest.java new file mode 100644 index 00000000000..4eb902efa00 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportCellsTest.java @@ -0,0 +1,47 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the import CSV file tests into rows. + */ +public abstract class AbstractImportCellsTest extends AbstractImportTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectCellCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 0, false, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#getCommandId() + * + * @return + */ + @Override + public String getCommandId() { + return "org.eclipse.papyrus.infra.nattable.row.import.command"; //$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/importfile/AbstractImportEmptyTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportEmptyTest.java new file mode 100644 index 00000000000..376d16843cc --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportEmptyTest.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the import CSV file tests into rows. + */ +public abstract class AbstractImportEmptyTest extends AbstractImportTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#getCommandId() + * + * @return + */ + @Override + public String getCommandId() { + return "org.eclipse.papyrus.infra.nattable.import.command"; //$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/importfile/AbstractImportRowsTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportRowsTest.java new file mode 100644 index 00000000000..95ead525557 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportRowsTest.java @@ -0,0 +1,47 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the import CSV file tests into rows. + */ +public abstract class AbstractImportRowsTest extends AbstractImportTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 0, false, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#getCommandId() + * + * @return + */ + @Override + public String getCommandId() { + return "org.eclipse.papyrus.infra.nattable.row.import.command"; //$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/importfile/AbstractImportTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportTest.java new file mode 100644 index 00000000000..0a49c140f60 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportTest.java @@ -0,0 +1,147 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.util.URI; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.tools.util.EclipseCommandUtils; +import org.eclipse.papyrus.infra.tools.util.FileUtils; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Test; + +/** + * This class allows to manage the import CSV file tests. + */ +public abstract class AbstractImportTest extends AbstractPasteInsertTest { + + /** + * The path of the model to test. + */ + public static final String INSERT_FOLDER_PATH = "/resources/import/"; //$NON-NLS-1$ + + /** + * The variable name to determinate if the final dialog must be opened for the import. + */ + public static final String OPEN_DIALOG_BOOLEAN_PARAMETER = "openDialog"; //$NON-NLS-1$ + + /** + * The variable name to determinate the selected file path. + */ + public static final String SELECTED_FILE_PATH_STRING_PARAMETER = "selectedFilePath"; //$NON-NLS-1$ + + /** + * Constructor. + */ + public AbstractImportTest() { + super(); + } + + /** + * This allows to test the paste. + * + * @throws Exception + * The caught exception + */ + @Test + public void testImport() throws Exception { + // Open the table and get the manager + loadGenericTable(); + final IEditorPart editorPart = editor.getActiveEditor(); + Assert.assertTrue("Table editor must be a nattable editor", editorPart instanceof NatTableEditor); //$NON-NLS-1$ + final INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue("The manager must be a nattable model manager", currentManager instanceof NattableModelManager); //$NON-NLS-1$ + final NattableModelManager manager = (NattableModelManager) currentManager; + + // Check the table context before command + checkTableContent(manager, INITIAL_POST_FILE_NAME); + + // Manage the selection + flushDisplayEvents(); + manageSelection(manager); + flushDisplayEvents(); + + // fill the clipboard + final ICommandService commandService = EclipseCommandUtils.getCommandService(); + Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ + + // Get the paste command + final Command cmd = commandService.getCommand(getCommandId()); // $NON-NLS-1$ + final IHandler handler = cmd.getHandler(); + Assert.assertTrue("The handler must be enabled", handler.isEnabled()); //$NON-NLS-1$ + + // Execute the command with the non-UI parameters + final Map<Object, Object> parameters = new HashMap<Object, Object>(); + parameters.put(ImportTableHandler.OPEN_DIALOG_BOOLEAN_PARAMETER, Boolean.FALSE); + manageParameters(parameters, manager); + final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); + flushDisplayEvents(); + cmd.executeWithChecks(event); + + // Check the table content after command + checkTableContent(manager, RESULT_POST_FILE_NAME); + + // Undo/Redo + testUndo_Redo(manager); + } + + /** + * This allows to add parameters if necessary + * + * @param parameters + * The parameters for the command. + */ + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + // Create the path for the csv to load (must be with the following form : 'resources/import/TableName.csv') + URI uri = manager.getTable().eResource().getURI(); + uri = uri.trimFileExtension(); + final StringBuffer buffer = new StringBuffer(uri.lastSegment()); + buffer.append(FileUtils.DOT_STRING); + buffer.append(FileUtils.CSV_EXTENSIOn); + + String csvFileAsString = getWantedString(buffer.toString()); + + parameters.put(ImportTableHandler.SELECTED_FILE_PATH_STRING_PARAMETER, csvFileAsString); + } + + /** + * This allows to get the command id. + * + * @return The command id. + */ + public abstract String getCommandId(); + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.tests.AbstractOpenTableTest#getSourcePath() + */ + @Override + protected String getSourcePath() { + return INSERT_FOLDER_PATH; + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportCellsAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportCellsAll_Test.java new file mode 100644 index 00000000000..fd977217ba5 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportCellsAll_Test.java @@ -0,0 +1,51 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportCellsAll_Test extends AbstractImportCellsTest { + + /** + * Constructor. + */ + public ImportCellsAll_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.importfile.AbstractImportEmptyTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectCellCommand(manager.getBodyLayerStack().getSelectionLayer(), 2, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest#testUndo_Redo(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + protected void testUndo_Redo(NattableModelManager treeManager) throws Exception { + // Do nothing : The undo/redo is not implemented for the old basic paste + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptyAddAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptyAddAll_Test.java new file mode 100644 index 00000000000..6683d18aaed --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptyAddAll_Test.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportEmptyAddAll_Test extends AbstractImportEmptyTest { + + /** + * Constructor. + */ + public ImportEmptyAddAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + super.manageParameters(parameters, manager); + parameters.put(ImportTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.ADD_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptyReplaceAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptyReplaceAll_Test.java new file mode 100644 index 00000000000..59f734da99a --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptyReplaceAll_Test.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportEmptyReplaceAll_Test extends AbstractImportEmptyTest { + + /** + * Constructor. + */ + public ImportEmptyReplaceAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + super.manageParameters(parameters, manager); + parameters.put(ImportTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.REPLACE_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptySkipAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptySkipAll_Test.java new file mode 100644 index 00000000000..a01a39c13d5 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportEmptySkipAll_Test.java @@ -0,0 +1,55 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportEmptySkipAll_Test extends AbstractImportEmptyTest { + + /** + * Constructor. + */ + public ImportEmptySkipAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + super.manageParameters(parameters, manager); + parameters.put(ImportTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.SKIP_USER_ACTION); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest#testUndo_Redo(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + protected void testUndo_Redo(final NattableModelManager treeManager) throws Exception { + // Do nothing + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsAddAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsAddAll_Test.java new file mode 100644 index 00000000000..fd1d8e1360f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsAddAll_Test.java @@ -0,0 +1,58 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.Map; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportRowsAddAll_Test extends AbstractImportRowsTest { + + /** + * Constructor. + */ + public ImportRowsAddAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + super.manageParameters(parameters, manager); + parameters.put(ImportTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.ADD_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsReplaceAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsReplaceAll_Test.java new file mode 100644 index 00000000000..0d7186ce926 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsReplaceAll_Test.java @@ -0,0 +1,58 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.Map; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportRowsReplaceAll_Test extends AbstractImportRowsTest { + + /** + * Constructor. + */ + public ImportRowsReplaceAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + super.manageParameters(parameters, manager); + parameters.put(ImportTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.REPLACE_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsSkipAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsSkipAll_Test.java new file mode 100644 index 00000000000..9b12a8bc7ed --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/ImportRowsSkipAll_Test.java @@ -0,0 +1,68 @@ +/***************************************************************************** + * Copyright (c) 2015 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.importfile; + +import java.util.Map; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test import all of selection with hidden categories. + */ +public class ImportRowsSkipAll_Test extends AbstractImportRowsTest { + + /** + * Constructor. + */ + public ImportRowsSkipAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(final Map<Object, Object> parameters, final INattableModelManager manager) { + super.manageParameters(parameters, manager); + parameters.put(ImportTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.SKIP_USER_ACTION); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest#testUndo_Redo(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + protected void testUndo_Redo(final NattableModelManager treeManager) throws Exception { + // Do nothing + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertEmptyTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertEmptyTest.java new file mode 100644 index 00000000000..435c4fb13c6 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertEmptyTest.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the insert tests. + */ +public abstract class AbstractInsertEmptyTest extends AbstractInsertTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#getCommandId() + * + * @return + */ + @Override + public String getCommandId() { + return "org.eclipse.papyrus.infra.nattable.row.insert"; //$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/insert/AbstractInsertRowsTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertRowsTest.java new file mode 100644 index 00000000000..7f5dd0e4966 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertRowsTest.java @@ -0,0 +1,47 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the insert tests. + */ +public abstract class AbstractInsertRowsTest extends AbstractInsertTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 0, false, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#getCommandId() + * + * @return + */ + @Override + public String getCommandId() { + return "org.eclipse.papyrus.infra.nattable.row.insert"; //$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/insert/AbstractInsertTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertTest.java new file mode 100644 index 00000000000..d735eaf344a --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertTest.java @@ -0,0 +1,137 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.handler.PasteInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.tools.util.EclipseCommandUtils; +import org.eclipse.papyrus.infra.tools.util.FileUtils; +import org.eclipse.papyrus.uml.nattable.generic.tests.Activator; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Test; + +/** + * This class allows to manage the insert tests. + */ +public abstract class AbstractInsertTest extends AbstractPasteInsertTest { + + /** + * The path of the model to test. + */ + public static final String INSERT_FOLDER_PATH = "/resources/insert/"; //$NON-NLS-1$ + + /** + * Constructor. + */ + public AbstractInsertTest() { + super(); + } + + /** + * This allows to test the paste. + * + * @throws Exception + * The caught exception + */ + @Test + public void testInsert() throws Exception { + // Open the table and get the manager + loadGenericTable(); + final IEditorPart editorPart = editor.getActiveEditor(); + Assert.assertTrue("Table editor must be a nattable editor", editorPart instanceof NatTableEditor); //$NON-NLS-1$ + final INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue("The manager must be a nattable model manager", currentManager instanceof NattableModelManager); //$NON-NLS-1$ + final NattableModelManager manager = (NattableModelManager) currentManager; + + // Check the table context before command + checkTableContent(manager, INITIAL_POST_FILE_NAME); + + // Manage the selection + manageSelection(manager); + flushDisplayEvents(); + + // fill the clipboard + final ICommandService commandService = EclipseCommandUtils.getCommandService(); + Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ + final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); + final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); + fillClipboard(str); + + // Get the paste command + final Command cmd = commandService.getCommand(getCommandId()); // $NON-NLS-1$ + final IHandler handler = cmd.getHandler(); + Assert.assertTrue("The handler must be enabled", handler.isEnabled()); //$NON-NLS-1$ + + // Execute the command with the non-UI parameters + final Map<Object, Object> parameters = new HashMap<Object, Object>(); + parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); + parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + manageParameters(parameters); + final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); + flushDisplayEvents(); + final Object res = cmd.executeWithChecks(event); + Assert.assertTrue("The result must be a status", res instanceof IStatus); //$NON-NLS-1$ + final IStatus status = (IStatus) res; + + // Check the returned status + checkReturned_Status(status); + + if (status.isOK()) { + // Check the table content after command + checkTableContent(manager, RESULT_POST_FILE_NAME); + + // Undo/Redo + testUndo_Redo(manager); + } + } + + /** + * This allows to add parameters if necessary + * + * @param parameters + * The parameters for the command. + */ + public void manageParameters(final Map<Object, Object> parameters) { + // Do nothing + } + + /** + * This allows to get the command id. + * + * @return The command id. + */ + public abstract String getCommandId(); + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.tests.AbstractOpenTableTest#getSourcePath() + */ + @Override + protected String getSourcePath() { + return INSERT_FOLDER_PATH; + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyAddAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyAddAll_Test.java new file mode 100644 index 00000000000..84b6af1361b --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyAddAll_Test.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertEmptyAddAll_Test extends AbstractInsertEmptyTest { + + /** + * Constructor. + */ + public InsertEmptyAddAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.ADD_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyAxisIdentifierNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyAxisIdentifierNotExisting_Test.java new file mode 100644 index 00000000000..984d8ed2d9b --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyAxisIdentifierNotExisting_Test.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertEmptyAxisIdentifierNotExisting_Test extends AbstractInsertEmptyTest { + + /** + * Constructor. + */ + public InsertEmptyAxisIdentifierNotExisting_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasNotBeenDoneBecauseOfSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_TheAxisUsedAsIdentifierNotAvailable, ((MultiStatus) status).getChildren()[0].getMessage()); //$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/insert/InsertEmptyFailColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyFailColumns_Test.java new file mode 100644 index 00000000000..df7f7ed5c25 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyFailColumns_Test.java @@ -0,0 +1,42 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test insert when the number of columns to paste is not equals to the number of columns selected. + */ +public class InsertEmptyFailColumns_Test extends AbstractInsertEmptyTest { + + /** + * Constructor. + */ + public InsertEmptyFailColumns_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readcolumnsexceedsexistingcolumns, status.getMessage()); //$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/insert/InsertEmptyReplaceAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyReplaceAll_Test.java new file mode 100644 index 00000000000..7a542e77cfc --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyReplaceAll_Test.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertEmptyReplaceAll_Test extends AbstractInsertEmptyTest { + + /** + * Constructor. + */ + public InsertEmptyReplaceAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.REPLACE_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptySkipAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptySkipAll_Test.java new file mode 100644 index 00000000000..59f08402d9f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptySkipAll_Test.java @@ -0,0 +1,55 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertEmptySkipAll_Test extends AbstractInsertEmptyTest { + + /** + * Constructor. + */ + public InsertEmptySkipAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.SKIP_USER_ACTION); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest#testUndo_Redo(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + * + * @param treeManager + * @throws Exception + */ + @Override + protected void testUndo_Redo(NattableModelManager treeManager) throws Exception { + // Do nothing + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyWarningNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyWarningNotExisting_Test.java new file mode 100644 index 00000000000..373c492d39b --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertEmptyWarningNotExisting_Test.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class InsertEmptyWarningNotExisting_Test extends AbstractInsertEmptyTest { + + /** + * Constructor. + */ + public InsertEmptyWarningNotExisting_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Warning must be caught", IStatus.WARNING, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasBeenDoneWithSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", "The identifier 'Class2' was not found in the selection, so the object was created", ((MultiStatus) status).getChildren()[0].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsAddAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsAddAll_Test.java new file mode 100644 index 00000000000..9ef14cbeb51 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsAddAll_Test.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.Map; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertRowsAddAll_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsAddAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.ADD_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsAxisIdentifierNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsAxisIdentifierNotExisting_Test.java new file mode 100644 index 00000000000..a6b09ca7d54 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsAxisIdentifierNotExisting_Test.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertRowsAxisIdentifierNotExisting_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsAxisIdentifierNotExisting_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasNotBeenDoneBecauseOfSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_TheAxisUsedAsIdentifierNotAvailable, ((MultiStatus)status).getChildren()[0].getMessage()); //$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/insert/InsertRowsFailColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsFailColumns_Test.java new file mode 100644 index 00000000000..f2aeffdc31c --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsFailColumns_Test.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test insert when the number of columns to paste is not equals to the number of columns selected. + */ +public class InsertRowsFailColumns_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsFailColumns_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readcolumnsexceedsexistingcolumns, status.getMessage()); //$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/insert/InsertRowsFailRows_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsFailRows_Test.java new file mode 100644 index 00000000000..702f5961050 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsFailRows_Test.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test insert when the number of rows to paste is not equals to the number of rows selected. + */ +public class InsertRowsFailRows_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsFailRows_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 1, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readrowsexceedsexistingrows, status.getMessage()); //$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/insert/InsertRowsReplaceAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsReplaceAll_Test.java new file mode 100644 index 00000000000..b4a53701630 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsReplaceAll_Test.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.Map; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertRowsReplaceAll_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsReplaceAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.REPLACE_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsSkipAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsSkipAll_Test.java new file mode 100644 index 00000000000..200d6145ab3 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsSkipAll_Test.java @@ -0,0 +1,68 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import java.util.Map; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test insert all of selection with hidden categories. + */ +public class InsertRowsSkipAll_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsSkipAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.insert.AbstractInsertTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.SKIP_USER_ACTION); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest#testUndo_Redo(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + * + * @param treeManager + * @throws Exception + */ + @Override + protected void testUndo_Redo(NattableModelManager treeManager) throws Exception { + // Do nothing + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsWarningNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsWarningNotExisting_Test.java new file mode 100644 index 00000000000..e64e2262fcd --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/InsertRowsWarningNotExisting_Test.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2015 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.insert; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class InsertRowsWarningNotExisting_Test extends AbstractInsertRowsTest { + + /** + * Constructor. + */ + public InsertRowsWarningNotExisting_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Warning must be caught", IStatus.WARNING, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasBeenDoneWithSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", "The identifier 'Class2' was not found in the selection, so the object was created", ((MultiStatus)status).getChildren()[0].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteCellsOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteCellsOverwriteTest.java new file mode 100644 index 00000000000..8ced2b2ca22 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteCellsOverwriteTest.java @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the paste with overwrite tests. + */ +public abstract class AbstractPasteCellsOverwriteTest extends AbstractPasteOverwriteTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectCellCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 0, false, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteColumnsOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteColumnsOverwriteTest.java new file mode 100644 index 00000000000..9c40a94bb43 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteColumnsOverwriteTest.java @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the paste with overwrite tests. + */ +public abstract class AbstractPasteColumnsOverwriteTest extends AbstractPasteOverwriteTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 0, false, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java new file mode 100644 index 00000000000..ae2ca858a8e --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java @@ -0,0 +1,121 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.handler.PasteInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.tools.util.EclipseCommandUtils; +import org.eclipse.papyrus.infra.tools.util.FileUtils; +import org.eclipse.papyrus.uml.nattable.generic.tests.Activator; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Test; + +/** + * This class allows to manage the paste with overwrite tests. + */ +public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverwriteTest { + + /** + * This allows to test the paste. + * + * @throws Exception + * The caught exception + */ + @Override + @Test + public void testPaste() throws Exception { + // Open the table and get the manager + loadGenericTable(); + final IEditorPart editorPart = editor.getActiveEditor(); + Assert.assertTrue("Table editor must be a nattable editor", editorPart instanceof NatTableEditor); //$NON-NLS-1$ + final INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue("The manager must be a nattable model manager", currentManager instanceof NattableModelManager); //$NON-NLS-1$ + final NattableModelManager manager = (NattableModelManager) currentManager; + + // Check the table context before command + checkTableContent(manager, INITIAL_POST_FILE_NAME); + + // Manage the selection + manageSelection(manager); + flushDisplayEvents(); + + // fill the clipboard + final ICommandService commandService = EclipseCommandUtils.getCommandService(); + Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ + final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); + final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); + fillClipboard(str); + + // Get the paste command + final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ + final IHandler handler = cmd.getHandler(); + Assert.assertTrue("The handler must be enabled", handler.isEnabled()); //$NON-NLS-1$ + + // Execute the command with the non-UI parameters + final Map<Object, Object> parameters = new HashMap<Object, Object>(); + parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); + parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + manageParameters(parameters); + final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); + flushDisplayEvents(); + final Object res = cmd.executeWithChecks(event); + Assert.assertTrue("The result must be a status", res instanceof IStatus); //$NON-NLS-1$ + final IStatus status = (IStatus) res; + + // Check the returned status + checkReturned_Status(status); + + if (status.isOK()) { + // Check the table content after command + checkTableContent(manager, RESULT_POST_FILE_NAME); + + // Undo/Redo + testUndo_Redo(manager); + } + } + + /** + * This allows to add parameters if necessary + * + * @param parameters + * The parameters for the command. + */ + public void manageParameters(final Map<Object, Object> parameters) { + // Do nothing + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java new file mode 100644 index 00000000000..387791ed45f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java @@ -0,0 +1,199 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import java.awt.Toolkit; +import java.awt.datatransfer.StringSelection; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.URI; +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils; +import org.eclipse.papyrus.infra.tools.util.FileUtils; +import org.eclipse.papyrus.junit.utils.GenericUtils; +import org.eclipse.papyrus.uml.nattable.generic.tests.Activator; +import org.eclipse.papyrus.uml.nattable.generic.tests.tests.AbstractGenericTableTest; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; + +/** + * This class allows to manage the paste with overwrite tests. + */ +public abstract class AbstractPasteInsertTest extends AbstractGenericTableTest { + + /** + * The suffix of the file containing the initial content. + */ + public static final String INITIAL_POST_FILE_NAME = "_Initial"; //$NON-NLS-1$ + + /** + * The suffix of the file containing the content to copy. + */ + public static final String TOCOPY_POST_FILE_NAME = "_ToCopy"; //$NON-NLS-1$ + + /** + * The suffix of the file containing the result content. + */ + public static final String RESULT_POST_FILE_NAME = "_Result"; //$NON-NLS-1$ + + /** + * Constructor. + */ + public AbstractPasteInsertTest() { + super(); + } + + /** + * Initialize the model. + * + * @throws Exception + * The caught exception. + */ + @Before + public void initModel() throws Exception { + initModel("GenericTable", getClass().getSimpleName(), getBundle()); //$NON-NLS-1$ + }; + + /** + * This allows to set the selection in table for the paste. The initial selection is the first cell of the table. + * + * @param manager + * The tree nattable model manager. + * @throws Exception + * The caught exception. + */ + public abstract void manageSelection(final NattableModelManager manager) throws Exception; + + /** + * This allows to test the undo redo commands. + * + * @param treeManager + * The tree nattable model manager. + * @throws Exception + * The caught exception. + */ + protected void testUndo_Redo(final NattableModelManager treeManager) throws Exception { + // Check the undo + getTransactionalEditingDomain().getCommandStack().undo(); + // Check the table context after undo + checkTableContent(treeManager, INITIAL_POST_FILE_NAME); + + // Check the redo + getTransactionalEditingDomain().getCommandStack().redo(); + // Check the table context after redo + checkTableContent(treeManager, RESULT_POST_FILE_NAME); + } + + /** + * This allows to check the returned status. + * + * @param status + * The status. + */ + protected void checkReturned_Status(final IStatus status) { + Assert.assertTrue("The status must be OK", status.isOK()); //$NON-NLS-1$ + } + + /** + * This allows to check the table content comparing the table content with file content. + * + * @param manager + * The nattable model manager. + * @param suffixFileName + * The suffix of the file to check. + * @throws Exception + * The caught exception. + */ + protected void checkTableContent(final NattableModelManager manager, final String suffixFileName) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + flushDisplayEvents(); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.selectAll(); + manager.copyToClipboard(); + String clipboard = getClipboardContent(); + // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result + Assert.assertNotNull("Clipboard must not be null", clipboard); //$NON-NLS-1$ + String str = getWantedString(getSuffixStateFileName(manager, suffixFileName)); + // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result + Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, clipboard); //$NON-NLS-1$ + } + + /** + * Get the string content from a file. + * + * @param fileName + * a file name + * @return + * the text stored in the file associated to this test + */ + protected String getWantedString(final String fileName) { + return FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName, FileUtils.getSystemPropertyLineSeparator());// $NON-NLS-1$ + } + + /** + * Get the file name corresponding to the model with the suffix in parameter. + * + * @param manager + * The nattable model manager. + * @param suffixFileName + * The suffix of the file to get. + * @return The file name corresponding + */ + protected String getSuffixStateFileName(final NattableModelManager manager, final String suffixFileName) { + URI uri = manager.getTable().eResource().getURI(); + uri = uri.trimFileExtension(); + final StringBuffer buffer = new StringBuffer(uri.lastSegment()); + buffer.append(suffixFileName); + buffer.append(FileUtils.DOT_STRING); + buffer.append(FileUtils.TEXT_EXTENSION); + return buffer.toString(); + } + + /** + * Get the clipboard contents. + * + * @return + * the clipboard contents. + */ + protected String getClipboardContent() { + String clipboard = TableClipboardUtils.getClipboardContentsAsString(); + return clipboard; + } + + /** + * This allows to fill the clipboard with the string in parameter. + * + * @param newClipBoardContents + * The string needed to fill the clipboard. + */ + protected void fillClipboard(final String newClipBoardContents) { + + // its seems that the clipboard must be filled with the same way than we read it! + java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + + StringSelection s = new StringSelection(newClipBoardContents); + clipboard.setContents(s, s); + } + + /** + * 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/paste/overwrite/AbstractPasteOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteOverwriteTest.java new file mode 100644 index 00000000000..46b6da4b72e --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteOverwriteTest.java @@ -0,0 +1,119 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.handler.PasteInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.tools.util.EclipseCommandUtils; +import org.eclipse.papyrus.infra.tools.util.FileUtils; +import org.eclipse.papyrus.uml.nattable.generic.tests.Activator; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Test; + +/** + * This class allows to manage the paste with overwrite tests. + */ +public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest { + + /** + * The path of the model to test. + */ + public static final String PASTE_FOLDER_PATH = "/resources/paste_overwrite/"; //$NON-NLS-1$ + + /** + * Constructor. + */ + public AbstractPasteOverwriteTest() { + super(); + } + + /** + * This allows to test the paste. + * + * @throws Exception + * The caught exception + */ + @Test + public void testPaste() throws Exception { + // Open the table and get the manager + loadGenericTable(); + final IEditorPart editorPart = editor.getActiveEditor(); + Assert.assertTrue("Table editor must be a nattable editor", editorPart instanceof NatTableEditor); //$NON-NLS-1$ + final INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue("The manager must be a nattable model manager", currentManager instanceof NattableModelManager); //$NON-NLS-1$ + final NattableModelManager manager = (NattableModelManager) currentManager; + + // Check the table context before command + checkTableContent(manager, INITIAL_POST_FILE_NAME); + + // Manage the selection + manageSelection(manager); + flushDisplayEvents(); + + // fill the clipboard + final ICommandService commandService = EclipseCommandUtils.getCommandService(); + Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ + final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); + final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); + fillClipboard(str); + + // Get the paste command + final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ + final IHandler handler = cmd.getHandler(); + Assert.assertTrue("The handler must be enabled", handler.isEnabled()); //$NON-NLS-1$ + + // Execute the command with the non-UI parameters + final Map<Object, Object> parameters = new HashMap<Object, Object>(); + parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); + parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); + flushDisplayEvents(); + final Object res = cmd.executeWithChecks(event); + Assert.assertTrue("The result must be a status", res instanceof IStatus); //$NON-NLS-1$ + final IStatus status = (IStatus) res; + + // Check the returned status + checkReturned_Status(status); + + if (status.isOK()) { + // Check the table content after command + checkTableContent(manager, RESULT_POST_FILE_NAME); + + // Undo/Redo + testUndo_Redo(manager); + } + } + + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.tests.AbstractOpenTableTest#getSourcePath() + */ + @Override + protected String getSourcePath() { + return PASTE_FOLDER_PATH; + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteRowsOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteRowsOverwriteTest.java new file mode 100644 index 00000000000..04f1a28a521 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteRowsOverwriteTest.java @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * This class allows to manage the paste with overwrite tests. + */ +public abstract class AbstractPasteRowsOverwriteTest extends AbstractPasteOverwriteTest { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 0, false, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteAll_Test.java new file mode 100644 index 00000000000..7ec78734141 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteAll_Test.java @@ -0,0 +1,27 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteCellsOverwriteAll_Test extends AbstractPasteCellsOverwriteTest { + + /** + * Constructor. + */ + public PasteCellsOverwriteAll_Test() { + super(); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteByOneLine_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteByOneLine_Test.java new file mode 100644 index 00000000000..ac5a7d9da9b --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteByOneLine_Test.java @@ -0,0 +1,42 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * Test pastes overwrite all of selection with hidden categories when a single line is copied. + */ +public class PasteCellsOverwriteByOneLine_Test extends AbstractPasteCellsOverwriteTest { + + /** + * Constructor. + */ + public PasteCellsOverwriteByOneLine_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectCellCommand(manager.getBodyLayerStack().getSelectionLayer(), 2, 2, true, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteFailColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteFailColumns_Test.java new file mode 100644 index 00000000000..55d5a1824c9 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteFailColumns_Test.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of columns to paste is not equals to the number of columns selected. + */ +public class PasteCellsOverwriteFailColumns_Test extends AbstractPasteCellsOverwriteTest { + + /** + * Constructor. + */ + public PasteCellsOverwriteFailColumns_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectCellCommand(manager.getBodyLayerStack().getSelectionLayer(), 1, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readcolumnsexceedsexistingcolumns, status.getMessage()); //$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/paste/overwrite/PasteCellsOverwriteFailRows_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteFailRows_Test.java new file mode 100644 index 00000000000..ced57006df6 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteCellsOverwriteFailRows_Test.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of rows to paste is not equals to the number of rows selected. + */ +public class PasteCellsOverwriteFailRows_Test extends AbstractPasteCellsOverwriteTest { + + /** + * Constructor. + */ + public PasteCellsOverwriteFailRows_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectCellCommand(manager.getBodyLayerStack().getSelectionLayer(), 2, 1, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readrowsexceedsexistingrows, status.getMessage()); //$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/paste/overwrite/PasteColumnsOverwriteAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteAll_Test.java new file mode 100644 index 00000000000..96824210328 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteAll_Test.java @@ -0,0 +1,41 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteColumnsOverwriteAll_Test extends AbstractPasteColumnsOverwriteTest { + + /** + * Constructor. + */ + public PasteColumnsOverwriteAll_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteColumnsOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 2, 0, true, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteByOneLine_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteByOneLine_Test.java new file mode 100644 index 00000000000..93fa8bddea2 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteByOneLine_Test.java @@ -0,0 +1,47 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * Test pastes overwrite all of selection with hidden categories when a single line is copied. + */ +public class PasteColumnsOverwriteByOneLine_Test extends AbstractPasteColumnsOverwriteTest { + + /** + * Constructor. + */ + public PasteColumnsOverwriteByOneLine_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); + natTable.doCommand(new ClearAllSelectionsCommand()); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 1, 0, false, false)); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 2, 0, true, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteFailColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteFailColumns_Test.java new file mode 100644 index 00000000000..5f14d170fd3 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteFailColumns_Test.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of columns to paste is not equals to the number of columns selected. + */ +public class PasteColumnsOverwriteFailColumns_Test extends AbstractPasteColumnsOverwriteTest { + + /** + * Constructor. + */ + public PasteColumnsOverwriteFailColumns_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 1, 0, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readcolumnsexceedsexistingcolumns, status.getMessage()); //$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/paste/overwrite/PasteColumnsOverwriteFailRows_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteFailRows_Test.java new file mode 100644 index 00000000000..e9964de7f34 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteColumnsOverwriteFailRows_Test.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of rows to paste is not equals to the number of rows selected. + */ +public class PasteColumnsOverwriteFailRows_Test extends AbstractPasteColumnsOverwriteTest { + + /** + * Constructor. + */ + public PasteColumnsOverwriteFailRows_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 2, 0, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readrowsexceedsexistingrows, status.getMessage()); //$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/paste/overwrite/PasteEmptyOverwriteAddAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteAddAll_Test.java new file mode 100644 index 00000000000..4c405bef66b --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteAddAll_Test.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteEmptyOverwriteAddAll_Test extends AbstractPasteEmptyOverwriteTest { + + /** + * Constructor. + */ + public PasteEmptyOverwriteAddAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteEmptyOverwriteTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.ADD_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteAxisIdentifierNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteAxisIdentifierNotExisting_Test.java new file mode 100644 index 00000000000..0042601d800 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteAxisIdentifierNotExisting_Test.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteEmptyOverwriteAxisIdentifierNotExisting_Test extends AbstractPasteEmptyOverwriteTest { + + /** + * Constructor. + */ + public PasteEmptyOverwriteAxisIdentifierNotExisting_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasNotBeenDoneBecauseOfSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_TheAxisUsedAsIdentifierNotAvailable, ((MultiStatus) status).getChildren()[0].getMessage()); //$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/paste/overwrite/PasteEmptyOverwriteFailColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteFailColumns_Test.java new file mode 100644 index 00000000000..1de1769f944 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteFailColumns_Test.java @@ -0,0 +1,42 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of columns to paste is not equals to the number of columns selected. + */ +public class PasteEmptyOverwriteFailColumns_Test extends AbstractPasteEmptyOverwriteTest { + + /** + * Constructor. + */ + public PasteEmptyOverwriteFailColumns_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readcolumnsexceedsexistingcolumns, status.getMessage()); //$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/paste/overwrite/PasteEmptyOverwriteReplaceAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteReplaceAll_Test.java new file mode 100644 index 00000000000..0288afa3bf6 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteReplaceAll_Test.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteEmptyOverwriteReplaceAll_Test extends AbstractPasteEmptyOverwriteTest { + + /** + * Constructor. + */ + public PasteEmptyOverwriteReplaceAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteEmptyOverwriteTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.REPLACE_USER_ACTION); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteSkipAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteSkipAll_Test.java new file mode 100644 index 00000000000..4e91f55cd84 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteSkipAll_Test.java @@ -0,0 +1,55 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import java.util.Map; + +import org.eclipse.papyrus.infra.nattable.handler.InsertInTableHandler; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteEmptyOverwriteSkipAll_Test extends AbstractPasteEmptyOverwriteTest { + + /** + * Constructor. + */ + public PasteEmptyOverwriteSkipAll_Test() { + super(); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteEmptyOverwriteTest#manageParameters(java.util.Map) + * + * @param parameters + */ + @Override + public void manageParameters(Map<Object, Object> parameters) { + super.manageParameters(parameters); + parameters.put(InsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION, UserActionConstants.SKIP_USER_ACTION); + } + + /** + * @see org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.AbstractPasteInsertTest#testUndo_Redo(org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager) + * + * @param treeManager + * @throws Exception + */ + @Override + protected void testUndo_Redo(NattableModelManager treeManager) throws Exception { + // Do nothing + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteWarningNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteWarningNotExisting_Test.java new file mode 100644 index 00000000000..1f51f14daf3 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteEmptyOverwriteWarningNotExisting_Test.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteEmptyOverwriteWarningNotExisting_Test extends AbstractPasteEmptyOverwriteTest { + + /** + * Constructor. + */ + public PasteEmptyOverwriteWarningNotExisting_Test() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Warning must be caught", IStatus.WARNING, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasBeenDoneWithSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", "The identifier 'Class2' was not found in the selection, so the object was created", ((MultiStatus) status).getChildren()[0].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteAll_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteAll_Test.java new file mode 100644 index 00000000000..272b3bb1782 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteAll_Test.java @@ -0,0 +1,42 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteRowsOverwriteAll_Test extends AbstractPasteRowsOverwriteTest { + + /** + * Constructor. + */ + public PasteRowsOverwriteAll_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteAxisIdentifierNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteAxisIdentifierNotExisting_Test.java new file mode 100644 index 00000000000..09f85315f9a --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteAxisIdentifierNotExisting_Test.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteRowsOverwriteAxisIdentifierNotExisting_Test extends AbstractPasteRowsOverwriteTest { + + /** + * Constructor. + */ + public PasteRowsOverwriteAxisIdentifierNotExisting_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasNotBeenDoneBecauseOfSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_TheAxisUsedAsIdentifierNotAvailable, ((MultiStatus)status).getChildren()[0].getMessage()); //$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/paste/overwrite/PasteRowsOverwriteFailColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteFailColumns_Test.java new file mode 100644 index 00000000000..0f3f9a374c9 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteFailColumns_Test.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of columns to paste is not equals to the number of columns selected. + */ +public class PasteRowsOverwriteFailColumns_Test extends AbstractPasteRowsOverwriteTest { + + /** + * Constructor. + */ + public PasteRowsOverwriteFailColumns_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readcolumnsexceedsexistingcolumns, status.getMessage()); //$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/paste/overwrite/PasteRowsOverwriteFailRows_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteFailRows_Test.java new file mode 100644 index 00000000000..c0717aed6b3 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteFailRows_Test.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite when the number of rows to paste is not equals to the number of rows selected. + */ +public class PasteRowsOverwriteFailRows_Test extends AbstractPasteRowsOverwriteTest { + + /** + * Constructor. + */ + public PasteRowsOverwriteFailRows_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 1, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Error must be caught", IStatus.ERROR, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Error message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_readrowsexceedsexistingrows, status.getMessage()); //$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/paste/overwrite/PasteRowsOverwriteWarningNotExisting_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteWarningNotExisting_Test.java new file mode 100644 index 00000000000..b6eb8df1285 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/PasteRowsOverwriteWarningNotExisting_Test.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2015 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.paste.overwrite; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.junit.Assert; + +/** + * Test pastes overwrite all of selection with hidden categories. + */ +public class PasteRowsOverwriteWarningNotExisting_Test extends AbstractPasteRowsOverwriteTest { + + /** + * Constructor. + */ + public PasteRowsOverwriteWarningNotExisting_Test() { + super(); + } + + /** + * Manage the selection with the shift key. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#manageSelection(org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager) + */ + @Override + public void manageSelection(final NattableModelManager manager) throws Exception { + super.manageSelection(manager); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 2, true, false)); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite.AbstractPasteOverwriteTest#checkReturned_Status(org.eclipse.core.runtime.IStatus) + */ + @Override + protected void checkReturned_Status(final IStatus status) { + Assert.assertEquals("Warning must be caught", IStatus.WARNING, status.getSeverity()); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", Messages.AbstractPasteInSelectionNattableCommandProvider_ThePasteHasBeenDoneWithSomeProblems, status.getMessage()); //$NON-NLS-1$ + Assert.assertTrue("Status must be a multi-status", status instanceof MultiStatus); //$NON-NLS-1$ + Assert.assertEquals("Warning message is not the expected message", "The identifier 'Class2' was not found in the selection", ((MultiStatus)status).getChildren()[0].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ + } +} 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 a089ed6a8b2..c9a62c797f4 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 @@ -20,6 +20,44 @@ import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AxisChangeIndexWithou 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.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; +import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportEmptySkipAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportRowsAddAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportRowsReplaceAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.importfile.ImportRowsSkipAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertEmptyAddAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertEmptyAxisIdentifierNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertEmptyFailColumns_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertEmptyReplaceAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertEmptySkipAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertEmptyWarningNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsAddAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsAxisIdentifierNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsFailColumns_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsFailRows_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsReplaceAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsSkipAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.insert.InsertRowsWarningNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteCellsOverwriteAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteCellsOverwriteByOneLine_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteCellsOverwriteFailColumns_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteCellsOverwriteFailRows_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteColumnsOverwriteAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteColumnsOverwriteFailColumns_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteColumnsOverwriteFailRows_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteEmptyOverwriteAddAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteEmptyOverwriteAxisIdentifierNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteEmptyOverwriteFailColumns_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteEmptyOverwriteReplaceAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteEmptyOverwriteSkipAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteEmptyOverwriteWarningNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteRowsOverwriteAll_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteRowsOverwriteAxisIdentifierNotExisting_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteRowsOverwriteFailColumns_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteRowsOverwriteFailRows_Test; +import org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite.PasteRowsOverwriteWarningNotExisting_Test; import org.junit.runner.RunWith; import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite; import org.junit.runners.Suite.SuiteClasses; @@ -40,7 +78,56 @@ import org.junit.runners.Suite.SuiteClasses; FilterStringMatcherTest.class, FilterEEnumMatcherTest.class, FilterNumericMatcherTest.class, - FilterUMLEnumerationMatcherTest.class + FilterUMLEnumerationMatcherTest.class, + + // Paste Overwrite tests + PasteCellsOverwriteAll_Test.class, + PasteCellsOverwriteByOneLine_Test.class, + PasteCellsOverwriteFailColumns_Test.class, + PasteCellsOverwriteFailRows_Test.class, + + PasteColumnsOverwriteAll_Test.class, + PasteCellsOverwriteByOneLine_Test.class, + PasteColumnsOverwriteFailColumns_Test.class, + PasteColumnsOverwriteFailRows_Test.class, + + PasteRowsOverwriteAll_Test.class, + PasteRowsOverwriteFailColumns_Test.class, + PasteRowsOverwriteFailRows_Test.class, + PasteRowsOverwriteWarningNotExisting_Test.class, + PasteRowsOverwriteAxisIdentifierNotExisting_Test.class, + + PasteEmptyOverwriteReplaceAll_Test.class, + PasteEmptyOverwriteAddAll_Test.class, + PasteEmptyOverwriteSkipAll_Test.class, + PasteEmptyOverwriteFailColumns_Test.class, + PasteEmptyOverwriteWarningNotExisting_Test.class, + PasteEmptyOverwriteAxisIdentifierNotExisting_Test.class, + + // Insert tests + InsertRowsReplaceAll_Test.class, + InsertRowsAddAll_Test.class, + InsertRowsSkipAll_Test.class, + InsertRowsFailColumns_Test.class, + InsertRowsFailRows_Test.class, + InsertRowsAxisIdentifierNotExisting_Test.class, + InsertRowsWarningNotExisting_Test.class, + + InsertEmptyReplaceAll_Test.class, + InsertEmptyAddAll_Test.class, + InsertEmptySkipAll_Test.class, + InsertEmptyFailColumns_Test.class, + InsertEmptyAxisIdentifierNotExisting_Test.class, + InsertEmptyWarningNotExisting_Test.class, + + // Import tests + ImportCellsAll_Test.class, + ImportRowsReplaceAll_Test.class, + ImportRowsAddAll_Test.class, + ImportRowsSkipAll_Test.class, + ImportEmptyReplaceAll_Test.class, + ImportEmptyAddAll_Test.class, + ImportEmptySkipAll_Test.class }) public class AllTests { // JUnit 4 test suite |