Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-02-20 22:21:21 +0000
committerChristian W. Damus2014-02-20 22:21:21 +0000
commit9f0e323f6fc7b38880295bddd2ee2a0992ad9fd3 (patch)
tree45a09fc962d1237ebd89fdc419831a376b0e7573 /tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests
parent03d8c7d3e2c8e945343fda4a4b661edced9dc78e (diff)
downloadorg.eclipse.papyrus-9f0e323f6fc7b38880295bddd2ee2a0992ad9fd3.tar.gz
org.eclipse.papyrus-9f0e323f6fc7b38880295bddd2ee2a0992ad9fd3.tar.xz
org.eclipse.papyrus-9f0e323f6fc7b38880295bddd2ee2a0992ad9fd3.zip
323802: [General] Papyrus shall provide a read only mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=323802 Merely disapproving the edit in an advice is not enough because in the diagram editor, the GEF EditPolicy can produce a command that is used instead of the "semantic" command produced (and null if disapproved) by the edit-helper. So, we must actually return an unelectable command in order to block the execution of this fall-back command.
Diffstat (limited to 'tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests')
-rw-r--r--tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/advice/ReadOnlyObjectEditAdviceTest.java25
1 files changed, 14 insertions, 11 deletions
diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/advice/ReadOnlyObjectEditAdviceTest.java b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/advice/ReadOnlyObjectEditAdviceTest.java
index 2ee507e2884..07528c94cba 100644
--- a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/advice/ReadOnlyObjectEditAdviceTest.java
+++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/advice/ReadOnlyObjectEditAdviceTest.java
@@ -14,6 +14,7 @@ package org.eclipse.papyrus.infra.emf.advice;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assume.assumeThat;
@@ -219,7 +220,7 @@ public class ReadOnlyObjectEditAdviceTest {
assumeThat(resourceMode.isAdviceEnabled(), is(true));
// We don't have any edit helpers suitable for this use case
- assertApproval(new DuplicateElementsRequest(Collections.singletonList(classB)));
+ assertAdvice(new DuplicateElementsRequest(Collections.singletonList(classB)));
}
@Test
@@ -311,7 +312,7 @@ public class ReadOnlyObjectEditAdviceTest {
// We don't have any edit helpers suitable for this use case.
// Reorienting the target is always permitted because there is no inverse reference
- assertThat(new ReadOnlyObjectEditAdvice().approveRequest(new ReorientReferenceRelationshipRequest(comment[0], classA, classB, ReorientRequest.REORIENT_TARGET)), is(true));
+ assertThat(new ReadOnlyObjectEditAdvice().getBeforeEditCommand(new ReorientReferenceRelationshipRequest(comment[0], classA, classB, ReorientRequest.REORIENT_TARGET)), nullValue());
}
@Test
@@ -332,7 +333,7 @@ public class ReadOnlyObjectEditAdviceTest {
// We don't have any edit helpers suitable for this use case.
// Reorienting the target is always permitted because there is no inverse reference
- assertThat(new ReadOnlyObjectEditAdvice().approveRequest(new ReorientReferenceRelationshipRequest(comment[0], classB, classA, ReorientRequest.REORIENT_TARGET)), is(true));
+ assertThat(new ReadOnlyObjectEditAdvice().getBeforeEditCommand(new ReorientReferenceRelationshipRequest(comment[0], classB, classA, ReorientRequest.REORIENT_TARGET)), nullValue());
}
@Test
@@ -353,7 +354,7 @@ public class ReadOnlyObjectEditAdviceTest {
});
// We don't have any edit helpers suitable for this use case
- assertApproval(new ReorientReferenceRelationshipRequest(comment[0], comment[1], comment[0], ReorientRequest.REORIENT_SOURCE));
+ assertAdvice(new ReorientReferenceRelationshipRequest(comment[0], comment[1], comment[0], ReorientRequest.REORIENT_SOURCE));
}
@Test
@@ -374,7 +375,7 @@ public class ReadOnlyObjectEditAdviceTest {
});
// We don't have any edit helpers suitable for this use case
- assertApproval(new ReorientReferenceRelationshipRequest(comment[0], comment[1], comment[0], ReorientRequest.REORIENT_SOURCE));
+ assertAdvice(new ReorientReferenceRelationshipRequest(comment[0], comment[1], comment[0], ReorientRequest.REORIENT_SOURCE));
}
//
@@ -542,7 +543,8 @@ public class ReadOnlyObjectEditAdviceTest {
case LOCAL_WRITEABLE:
case LOCAL_READONLY:
case PLUGIN_NOADVICE:
- assertThat("Command should be executable", command.canExecute(), is(true)); //$NON-NLS-1$
+ // The edit-helper can return null if there is no executable command to be provided
+ assertThat("Command should be executable", (command != null) && command.canExecute(), is(true)); //$NON-NLS-1$
break;
default:
// The edit-helper can return null if there is no executable command to be provided
@@ -551,8 +553,8 @@ public class ReadOnlyObjectEditAdviceTest {
}
}
- void assertApproval(IEditCommandRequest request) {
- boolean approved = new ReadOnlyObjectEditAdvice().approveRequest(request);
+ void assertAdvice(IEditCommandRequest request) {
+ ICommand command = new ReadOnlyObjectEditAdvice().getBeforeEditCommand(request);
switch(resourceMode) {
case WORKSPACE_WRITEABLE:
@@ -560,11 +562,12 @@ public class ReadOnlyObjectEditAdviceTest {
case LOCAL_WRITEABLE:
case LOCAL_READONLY:
case PLUGIN_NOADVICE:
- assertThat("Request should be approved", approved, is(true)); //$NON-NLS-1$
+ // The advice can return null if there is no need to decorate the operation
+ assertThat("Request should be approved", (command == null) || command.canExecute(), is(true)); //$NON-NLS-1$
break;
default:
- // The edit-helper can return null if there is no executable command to be provided
- assertThat("Request should not be approved", approved, is(false)); //$NON-NLS-1$
+ // The advice can return null if there is no need to decorate the operation
+ assertThat("Request should not be approved", (command == null) || command.canExecute(), is(false)); //$NON-NLS-1$
break;
}
}

Back to the top