diff options
author | Christian W. Damus | 2014-02-14 22:11:39 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-02-20 19:38:53 +0000 |
commit | 8ef9f1713ffdc6d441a11d96812f624dc7bd433e (patch) | |
tree | 09e46c84d2c1105319dc64ae9886a0dc7969fb07 /tests | |
parent | 4d9b5f1786a1a311b4df7379c419d56a5d58bd74 (diff) | |
download | org.eclipse.papyrus-8ef9f1713ffdc6d441a11d96812f624dc7bd433e.tar.gz org.eclipse.papyrus-8ef9f1713ffdc6d441a11d96812f624dc7bd433e.tar.xz org.eclipse.papyrus-8ef9f1713ffdc6d441a11d96812f624dc7bd433e.zip |
323802: [General] Papyrus shall provide a read only mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=323802
Junit tests for roll-back of commands/operations that modify read-only objects.
Diffstat (limited to 'tests')
13 files changed, 399 insertions, 6 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/core/org.eclipse.papyrus.tests/META-INF/MANIFEST.MF index b4c29f16401..e3035beefc8 100644 --- a/tests/junit/plugins/core/org.eclipse.papyrus.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/core/org.eclipse.papyrus.tests/META-INF/MANIFEST.MF @@ -45,7 +45,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.papyrus.uml.diagram.composite.tests;bundle-version="1.0.0",
org.eclipse.papyrus.infra.gmfdiag.css.tests;bundle-version="1.0.0",
org.eclipse.papyrus.infra.extendedtypes.tests;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0"
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.0.0.qualifier
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.tests/test/org/eclipse/papyrus/tests/AllTests.java b/tests/junit/plugins/core/org.eclipse.papyrus.tests/test/org/eclipse/papyrus/tests/AllTests.java index bea80b1597d..104335a6181 100644 --- a/tests/junit/plugins/core/org.eclipse.papyrus.tests/test/org/eclipse/papyrus/tests/AllTests.java +++ b/tests/junit/plugins/core/org.eclipse.papyrus.tests/test/org/eclipse/papyrus/tests/AllTests.java @@ -1,6 +1,6 @@ /*****************************************************************************
* Copyright (c) 2010, 2014 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
@@ -8,7 +8,7 @@ *
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 402525
+ * Christian W. Damus (CEA) - bugs 402525, 323802
*
*****************************************************************************/
package org.eclipse.papyrus.tests;
@@ -53,6 +53,7 @@ public class AllTests { suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.infra.extendedtypes.tests.AllTests.class));
// suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.infra.services.openelement.tests.AllTests.class));
suiteClasses.add(new FragmentTestSuiteClass(org.eclipse.papyrus.commands.Activator.PLUGIN_ID, "org.eclipse.papyrus.infra.gmfdiag.commands.tests.AllTests"));
+ suiteClasses.add(new FragmentTestSuiteClass(org.eclipse.papyrus.infra.emf.readonly.Activator.PLUGIN_ID, "org.eclipse.papyrus.infra.emf.readonly.tests.AllTests"));
/* views */
suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.views.modelexplorer.tests.AllTests.class));
@@ -90,7 +91,7 @@ public class AllTests { suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.uml.diagram.composite.test.AllTests.class));
//suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.uml.diagram.sequence.tests.AllTests.class)); //Disabled. They currently do not run on Hudson
// suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.uml.diagram.interactionoverview.tests.AllTests.class)); //Disabled. They currently do not run on Hudson
- //
+ //
//nattable tests
suiteClasses.add(new PluginTestSuiteClass(org.eclipse.papyrus.uml.nattable.tests.tests.AllTests.class));
@@ -109,7 +110,7 @@ public class AllTests { /**
* Constructor.
- *
+ *
* @param clazz
* the suite class � AllTests2
* @throws InitializationError
@@ -123,7 +124,7 @@ public class AllTests { /**
* Returns the list of test classes
- *
+ *
* @return the list of test classes
*/
private static Class<?>[] getSuites() {
diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.classpath b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.classpath new file mode 100644 index 00000000000..64c5e31b7a2 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.project b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.project new file mode 100644 index 00000000000..fdbdaeef2f6 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.emf.readonly.tests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.settings/org.eclipse.jdt.core.prefs b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..af0f20f97a5 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..7afe89216a1 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.emf.readonly.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %providerName +Bundle-Localization: fragment +Fragment-Host: org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.junit;bundle-version="4.10.0", + org.eclipse.uml2.uml;bundle-version="5.0.0", + com.google.guava;bundle-version="11.0.0" diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/about.html b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/about.html new file mode 100644 index 00000000000..d35d5aed64c --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 5, 2007</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html> diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/build.properties b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/build.properties new file mode 100644 index 00000000000..3e62f5b1114 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/build.properties @@ -0,0 +1,18 @@ +# Copyright (c) 2014 CEA 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 (CEA) - Initial API and implementation +# + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.properties,\ + about.html +src.includes = about.html diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/fragment.properties b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/fragment.properties new file mode 100644 index 00000000000..836d5c8643e --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/fragment.properties @@ -0,0 +1,13 @@ +################################################################################# +# Copyright (c) 2014 CEA 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 (CEA) - Initial API and implementation +# +################################################################################## +pluginName=Papyrus EMF Read-only Suport Test (Incubation) +providerName=Eclipse Modeling Project diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/org.eclipse.papyrus.infra.emf.readonly.tests.launch b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/org.eclipse.papyrus.infra.emf.readonly.tests.launch new file mode 100644 index 00000000000..f88fd3877e9 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/org.eclipse.papyrus.infra.emf.readonly.tests.launch @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig"> +<booleanAttribute key="append.args" value="true"/> +<booleanAttribute key="askclear" value="false"/> +<booleanAttribute key="automaticAdd" value="true"/> +<booleanAttribute key="automaticValidate" value="false"/> +<stringAttribute key="bootstrap" value=""/> +<stringAttribute key="checked" value="[NONE]"/> +<booleanAttribute key="clearConfig" value="true"/> +<booleanAttribute key="clearws" value="true"/> +<booleanAttribute key="clearwslog" value="false"/> +<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> +<booleanAttribute key="default" value="true"/> +<booleanAttribute key="includeOptional" value="true"/> +<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/AllTests.java"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> +<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.JAVA_COMMAND" value="java"/> +<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.infra.emf.readonly.tests.AllTests"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.infra.emf.readonly.tests"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.requiredJavaVersion=1.5 -Xms768m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=512M"/> +<stringAttribute key="pde.version" value="3.3"/> +<stringAttribute key="product" value="org.eclipse.platform.ide"/> +<booleanAttribute key="run_in_ui_thread" value="true"/> +<booleanAttribute key="show_selected_only" value="false"/> +<booleanAttribute key="tracing" value="false"/> +<booleanAttribute key="useCustomFeatures" value="false"/> +<booleanAttribute key="useDefaultConfig" value="true"/> +<booleanAttribute key="useDefaultConfigArea" value="false"/> +<booleanAttribute key="useProduct" value="true"/> +</launchConfiguration> diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/Bug323802.uml b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/Bug323802.uml new file mode 100644 index 00000000000..61aca0ef7fc --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/Bug323802.uml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20110701" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:uml="http://www.eclipse.org/uml2/4.0.0/UML" xmi:id="_-3u4cJW3EeOfoK3RwHm3pQ" name="bug323802"> + <packagedElement xmi:type="uml:Class" xmi:id="_C3c2UJW4EeOfoK3RwHm3pQ" clientDependency="_f_HJAJW4EeOfoK3RwHm3pQ" name="A"/> + <packagedElement xmi:type="uml:Class" xmi:id="_ExBnEJW4EeOfoK3RwHm3pQ" name="B"/> + <packagedElement xmi:type="uml:Dependency" xmi:id="_f_HJAJW4EeOfoK3RwHm3pQ" name="A-->B" client="_C3c2UJW4EeOfoK3RwHm3pQ" supplier="_ExBnEJW4EeOfoK3RwHm3pQ"/> +</uml:Model> diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomainTest.java b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomainTest.java new file mode 100644 index 00000000000..54d5d6b1dee --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomainTest.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2014 CEA 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 (CEA) - Initial API and implementation + * + */ +package org.eclipse.papyrus.infra.emf.readonly; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.fail; + +import java.io.InputStream; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IOperationHistory; +import org.eclipse.core.commands.operations.IOperationHistoryListener; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.commands.operations.OperationHistoryEvent; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.workspace.AbstractEMFOperation; +import org.eclipse.emf.workspace.IWorkspaceCommandStack; +import org.eclipse.papyrus.infra.core.resource.IRollbackStatus; +import org.eclipse.papyrus.infra.core.resource.RollbackStatus; +import org.eclipse.uml2.common.util.UML2Util; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.Type; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.resource.UMLResource; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.Iterables; + + +/** + * Test suite for the {@link PapyrusROTransactionalEditingDomain} class. + */ +public class PapyrusROTransactionalEditingDomainTest { + + private PapyrusROTransactionalEditingDomain fixture; + + private Model model; + + public PapyrusROTransactionalEditingDomainTest() { + super(); + } + + /** + * Test that attempting to establish a reference (in a writable object) to a read-only object will be rolled back if that reference has an + * opposite, which implies modification of the read-only object. + */ + @Test + public void testReferenceToReadOnlyObjectWithOppositeRolledBackCommand() { + RecordingCommand cmd = new RecordingCommand(fixture) { + + @Override + protected void doExecute() { + Dependency ab = (Dependency)model.getPackagedElement("A-->B"); + assertThat(ab, notNullValue()); + + // can load a read-only resource just fine + Model primTypes = UML2Util.load(fixture.getResourceSet(), URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), UMLPackage.Literals.MODEL); + Type string = primTypes.getOwnedType("String"); + assertThat(string, notNullValue()); + ab.getClients().add(string); + } + }; + + fixture.getCommandStack().execute(cmd); + + // The command was rolled back, so it wasn't stacked + assertThat(fixture.getCommandStack().canUndo(), is(false)); + + // The change was rolled back + Dependency ab = (Dependency)model.getPackagedElement("A-->B"); + assertThat(ab.getClients().size(), is(1)); + assertThat(ab.getClients().get(0), instanceOf(org.eclipse.uml2.uml.Class.class)); + } + + /** + * Test that attempting to establish a reference (in a writable object) to a read-only object will be rolled back if that reference has an + * opposite, which implies modification of the read-only object. + */ + @Test + public void testReferenceToReadOnlyObjectWithOppositeRolledBackOperation() { + final Type string[] = { null }; + + AbstractEMFOperation op = new AbstractEMFOperation(fixture, "Test") { + + @Override + protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + Dependency ab = (Dependency)model.getPackagedElement("A-->B"); + assertThat(ab, notNullValue()); + + // can load a read-only resource just fine + Model primTypes = UML2Util.load(fixture.getResourceSet(), URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), UMLPackage.Literals.MODEL); + string[0] = primTypes.getOwnedType("String"); + assertThat(string, notNullValue()); + ab.getClients().add(string[0]); + + return Status.OK_STATUS; + } + }; + + IOperationHistory history = ((IWorkspaceCommandStack)fixture.getCommandStack()).getOperationHistory(); + IUndoContext ctx = ((IWorkspaceCommandStack)fixture.getCommandStack()).getDefaultUndoContext(); + + final IRollbackStatus[] status = { null }; + + IOperationHistoryListener l = new IOperationHistoryListener() { + + public void historyNotification(OperationHistoryEvent event) { + if(event.getEventType() == OperationHistoryEvent.OPERATION_NOT_OK) { + status[0] = RollbackStatus.findRollbackStatus(event.getStatus()); + } + } + }; + + try { + history.addOperationHistoryListener(l); + history.execute(op, new NullProgressMonitor(), null); + } catch (ExecutionException e) { + fail("Should not have thown ExecutionException because roll-back is normal."); + } finally { + history.removeOperationHistoryListener(l); + } + + // The operation was rolled back, so it wasn't stacked + assertThat(history.canUndo(ctx), is(false)); + + // The change was rolled back + Dependency ab = (Dependency)model.getPackagedElement("A-->B"); + assertThat(ab.getClients().size(), is(1)); + assertThat(ab.getClients().get(0), instanceOf(org.eclipse.uml2.uml.Class.class)); + + assertThat(status[0], notNullValue()); + assertThat(status[0].getCode(), is(IRollbackStatus.READ_ONLY_OBJECT)); + assertThat(status[0].getCausalObjects().isEmpty(), is(false)); + assertThat(string[0], notNullValue()); + assertThat(Iterables.filter(status[0].getCausalObjects(), Type.class), hasItem(string[0])); + } + + // + // Test framework + // + + @Before + public void createFixture() throws Exception { + fixture = (PapyrusROTransactionalEditingDomain)new PapyrusROTransactionalEditingDomainProvider().createTransactionalEditingDomain(new ResourceSetImpl()); + + Resource res = fixture.getResourceSet().createResource(URI.createURI("platform:/resource/bogus/model.uml")); + InputStream input = PapyrusROTransactionalEditingDomainTest.class.getResourceAsStream("Bug323802.uml"); + try { + res.load(input, null); + } finally { + input.close(); + } + model = (Model)res.getContents().get(0); + } + + @After + public void destroyFixture() { + ResourceSet rset = fixture.getResourceSet(); + + model = null; + + fixture.dispose(); + fixture = null; + + for(Resource next : rset.getResources()) { + next.unload(); + next.eAdapters().clear(); + } + + rset.getResources().clear(); + rset.eAdapters().clear(); + } +} diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/AllTests.java b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/AllTests.java new file mode 100644 index 00000000000..9f6f768fda5 --- /dev/null +++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly.tests/src/org/eclipse/papyrus/infra/emf/readonly/tests/AllTests.java @@ -0,0 +1,30 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA 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 (CEA) - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.emf.readonly.tests; + +import org.eclipse.papyrus.infra.emf.readonly.PapyrusROTransactionalEditingDomainTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + + +/** + * Master test suite. + */ +@RunWith(Suite.class) +@SuiteClasses({ +PapyrusROTransactionalEditingDomainTest.class +}) +public class AllTests { + +} |