Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2015-02-16 09:30:38 -0500
committerGerrit Code Review @ Eclipse.org2015-02-16 09:30:39 -0500
commita3f8a0d5b37fbfe0f4f403bbd321682b6df57d16 (patch)
tree376d58e3124c2dfa4414aa737cb195bedf67da46
parent006c9ad85a638f94bfdaa3e3c865b61c5c49ccbc (diff)
parentf96488935a3e889e5452b956ee5c8f0e6e6c12c5 (diff)
downloadorg.eclipse.papyrus-a3f8a0d5b37fbfe0f4f403bbd321682b6df57d16.tar.gz
org.eclipse.papyrus-a3f8a0d5b37fbfe0f4f403bbd321682b6df57d16.tar.xz
org.eclipse.papyrus-a3f8a0d5b37fbfe0f4f403bbd321682b6df57d16.zip
Merge "Bug 459746: Model remains dirty after save and undo https://bugs.eclipse.org/bugs/show_bug.cgi?id=459746" into streams/1.0-maintenance
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStack.java11
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStackTest.java226
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/infra/gmfdiag/commands/tests/AllTests.java8
3 files changed, 237 insertions, 8 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStack.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStack.java
index 867d457bf32..958bb7e90c6 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStack.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStack.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011, 2014 Atos, CEA, and others.
+ * Copyright (c) 2011, 2015 Atos, CEA, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -14,6 +14,7 @@
* Christian W. Damus (CEA) - bug 430648
* Christian W. Damus (CEA) - bug 431023
* Christian W. Damus (CEA) - bug 384169
+ * Christian W. Damus - bug 459746
*
*****************************************************************************/
package org.eclipse.papyrus.commands;
@@ -628,10 +629,8 @@ public class NotifyingWorkspaceCommandStack extends AbstractTransactionalCommand
// => so we have to implement the isSaveNeeded method here.
IUndoableOperation nextUndoableOperation = history.getUndoOperation(getDefaultUndoContext());
if (nextUndoableOperation == null) {
- // this is the last undoable operation. But the document might have been save
- // CAVEAT: will trigger 410310, if the model has been saved before => use superclass method in this case.
- // return savedContext != null;
- return super.isSaveNeeded();
+ // this is the last undoable operation. But the document might have been saved at some operation now on the redo stack
+ return savedContext != null;
}
return savedContext != null ? !nextUndoableOperation.hasContext(getSavedContext()) && isDirty(history.getUndoHistory(getDefaultUndoContext()), history.getRedoHistory(getDefaultUndoContext()), history.getUndoOperation(savedContext))
: anyDirtying(history.getUndoHistory(getDefaultUndoContext()));
@@ -655,6 +654,8 @@ public class NotifyingWorkspaceCommandStack extends AbstractTransactionalCommand
}
IUndoableOperation nextUndoableOperation = history.getUndoOperation(getDefaultUndoContext());
if (nextUndoableOperation == null) {
+ // We no longer have any operation that was saved
+ savedContext = null;
return;
}
nextUndoableOperation.addContext(getSavedContext());
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStackTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStackTest.java
new file mode 100644
index 00000000000..d4307ea13bf
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/commands/NotifyingWorkspaceCommandStackTest.java
@@ -0,0 +1,226 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.commands;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.transaction.TransactionalCommandStack;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Regression tests for the {@link NotifyingWorkspaceCommandStack} class.
+ */
+public class NotifyingWorkspaceCommandStackTest extends AbstractPapyrusTest {
+
+ private TransactionalEditingDomain domain;
+ private NotifyingWorkspaceCommandStack fixture;
+
+ @Test
+ public void dirtyAfterExecute() {
+ assertNotDirty();
+ execute(new TestCommand());
+ assertDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecuteNonDirtying() {
+ assertNotDirty();
+ execute(new NonDirtyingCommand());
+ assertNotDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecute_undo() {
+ assertNotDirty();
+ execute(new TestCommand());
+ undo();
+ assertNotDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecuteNonDirtying_undo() {
+ assertNotDirty();
+ execute(new NonDirtyingCommand());
+ undo();
+ assertNotDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecute_save() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ assertNotDirty();
+ }
+
+ @Test
+ public void dirtyAfterExecute_save_undo() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ undo();
+ assertDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecute_save_undo_save() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ undo();
+ save();
+ assertNotDirty();
+ }
+
+ @Test
+ public void dirtyAfterExecute_save_undo_save_redo() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ undo();
+ save();
+ redo();
+ assertDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecute_save_executeNonDirtying_undo_undo_redo_redo() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ execute(new NonDirtyingCommand());
+ undo();
+ undo();
+ redo();
+ redo();
+ assertNotDirty();
+ }
+
+ @Test
+ public void notDirtyAfterExecute_save_execute_undo_undo_redo() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ execute(new TestCommand());
+ undo();
+ undo();
+ redo();
+ assertNotDirty();
+ }
+
+ @Test
+ public void dirtyAfterExecute_save_execute_undo_undo_save_redo() {
+ assertNotDirty();
+ execute(new TestCommand());
+ save();
+ execute(new TestCommand());
+ undo();
+ undo();
+ save();
+ redo();
+ assertDirty();
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ public void createFixture() {
+ fixture = new NotifyingWorkspaceCommandStack(CheckedOperationHistory.getInstance());
+ AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ domain = new TransactionalEditingDomainImpl(adapterFactory, (TransactionalCommandStack) fixture);
+ }
+
+ @After
+ public void destroyFixture() {
+ // This disposes the command stack for us
+ domain.dispose();
+ domain = null;
+ fixture = null;
+ }
+
+ void execute(Command command) {
+ assertThat("Cannot execute", command.canExecute(), is(true));
+ fixture.execute(command);
+ }
+
+ void undo() {
+ assertThat("Cannot undo", fixture.canUndo(), is(true));
+ fixture.undo();
+ }
+
+ void redo() {
+ assertThat("Cannot redo", fixture.canRedo(), is(true));
+ fixture.redo();
+ }
+
+ void save() {
+ assertDirty();
+ fixture.saveIsDone();
+ }
+
+ void assertDirty() {
+ assertThat("Stack is not dirty", fixture.isSaveNeeded(), is(true));
+ }
+
+ void assertNotDirty() {
+ assertThat("Stack is dirty", fixture.isSaveNeeded(), is(false));
+ }
+
+ static class TestCommand extends AbstractCommand {
+ TestCommand() {
+ super();
+ }
+
+ @Override
+ public boolean canExecute() {
+ return true;
+ }
+
+ public void execute() {
+ // Pass
+ }
+
+ @Override
+ public boolean canUndo() {
+ return true;
+ }
+
+ @Override
+ public void undo() {
+ // Pass
+ }
+
+ public void redo() {
+ // Pass
+ }
+ }
+
+ static class NonDirtyingCommand extends TestCommand implements AbstractCommand.NonDirtying {
+ NonDirtyingCommand() {
+ super();
+ }
+ }
+}
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/infra/gmfdiag/commands/tests/AllTests.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/infra/gmfdiag/commands/tests/AllTests.java
index ecce7998eb4..b73b4fde80d 100644
--- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/infra/gmfdiag/commands/tests/AllTests.java
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands.tests/src/org/eclipse/papyrus/infra/gmfdiag/commands/tests/AllTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 CEA LIST and others.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,10 +8,12 @@
*
* Contributors:
* Christian W. Damus (CEA) - initial API and implementation
+ * Christian W. Damus - bug 459746
*/
package org.eclipse.papyrus.infra.gmfdiag.commands.tests;
import org.eclipse.papyrus.commands.NestingNotifyingWorkspaceCommandStackTest;
+import org.eclipse.papyrus.commands.NotifyingWorkspaceCommandStackTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -22,8 +24,8 @@ import org.junit.runners.Suite.SuiteClasses;
*/
@RunWith(Suite.class)
@SuiteClasses({
-// {oep.commands}
-NestingNotifyingWorkspaceCommandStackTest.class })
+ // {oep.commands}
+ NotifyingWorkspaceCommandStackTest.class, NestingNotifyingWorkspaceCommandStackTest.class })
public class AllTests {
}

Back to the top