Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2017-01-18 23:12:31 +0000
committerGerrit Code Review @ Eclipse.org2017-01-19 21:32:17 +0000
commit96fee2e1a3c0b87cd0036ca46f68c50a2fa70f78 (patch)
tree3b8e4db9cac15b556cfd2ad660c21375da7a0f44
parentc2b287437b484bc355889f1ad4f02d0bcdf627dd (diff)
downloadorg.eclipse.papyrus-rt-96fee2e1a3c0b87cd0036ca46f68c50a2fa70f78.tar.gz
org.eclipse.papyrus-rt-96fee2e1a3c0b87cd0036ca46f68c50a2fa70f78.tar.xz
org.eclipse.papyrus-rt-96fee2e1a3c0b87cd0036ca46f68c50a2fa70f78.zip
Bug 467545: [UML-RT] PapyrusRT shall provide a UML specific implementation to support redefinition
JUnit regression tests for the observable replication factor. https://bugs.eclipse.org/bugs/show_bug.cgi?id=467545 Change-Id: Ic2544964f28351d89efad8a340083a43aaa333df
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/MultiplicityElementAdapterTest.java31
-rw-r--r--tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui.tests/src/org/eclipse/papyrusrt/umlrt/tooling/ui/tests/modelelement/PropertyReplicationObservableValueTest.java235
2 files changed, 266 insertions, 0 deletions
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/MultiplicityElementAdapterTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/MultiplicityElementAdapterTest.java
index 7ed41f9c1..dd96511c3 100644
--- a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/MultiplicityElementAdapterTest.java
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/MultiplicityElementAdapterTest.java
@@ -34,6 +34,7 @@ import org.eclipse.papyrus.junit.utils.rules.AbstractHouseKeeperRule.CleanUp;
import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
import org.eclipse.papyrusrt.umlrt.core.utils.MultiplicityElementAdapter;
import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.OpaqueExpression;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.TypedElement;
@@ -120,6 +121,36 @@ public class MultiplicityElementAdapterTest {
}
@Test
+ public void setLowerOpaqueExpressionBody() {
+ OpaqueExpression expr = (OpaqueExpression) multiplicityElement.createLowerValue(null, null,
+ UMLPackage.Literals.OPAQUE_EXPRESSION);
+
+ reset();
+
+ expr.getBodies().add("MAX_REPLICATION");
+
+ assertThat(multNotified, hasItem(UMLPackage.Literals.OPAQUE_EXPRESSION__BODY));
+ assertThat(lowerNotified, hasItem(UMLPackage.Literals.OPAQUE_EXPRESSION__BODY));
+ assertThat(upperNotified, not(hasItem(anything())));
+ assertThat(typeNotified, not(hasItem(anything())));
+ }
+
+ @Test
+ public void setUpperOpaqueExpressionBody() {
+ OpaqueExpression expr = (OpaqueExpression) multiplicityElement.createUpperValue(null, null,
+ UMLPackage.Literals.OPAQUE_EXPRESSION);
+
+ reset();
+
+ expr.getBodies().add("MAX_REPLICATION");
+
+ assertThat(multNotified, hasItem(UMLPackage.Literals.OPAQUE_EXPRESSION__BODY));
+ assertThat(lowerNotified, not(hasItem(anything())));
+ assertThat(upperNotified, hasItem(UMLPackage.Literals.OPAQUE_EXPRESSION__BODY));
+ assertThat(typeNotified, not(hasItem(anything())));
+ }
+
+ @Test
public void removeLowerValue() {
ValueSpecification lowerValue = multiplicityElement.createLowerValue(null, null, UMLPackage.Literals.LITERAL_INTEGER);
reset();
diff --git a/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui.tests/src/org/eclipse/papyrusrt/umlrt/tooling/ui/tests/modelelement/PropertyReplicationObservableValueTest.java b/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui.tests/src/org/eclipse/papyrusrt/umlrt/tooling/ui/tests/modelelement/PropertyReplicationObservableValueTest.java
new file mode 100644
index 000000000..058490dd1
--- /dev/null
+++ b/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui.tests/src/org/eclipse/papyrusrt/umlrt/tooling/ui/tests/modelelement/PropertyReplicationObservableValueTest.java
@@ -0,0 +1,235 @@
+/*****************************************************************************
+ * Copyright (c) 2017 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.papyrusrt.umlrt.tooling.ui.tests.modelelement;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import javax.inject.Named;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.junit.utils.rules.AbstractHouseKeeperRule.CleanUp;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
+import org.eclipse.papyrus.junit.utils.rules.ModelSetFixture;
+import org.eclipse.papyrus.junit.utils.rules.PluginResource;
+import org.eclipse.papyrus.junit.utils.rules.ServiceRegistryModelSetFixture;
+import org.eclipse.papyrusrt.junit.rules.DataBindingsRule;
+import org.eclipse.papyrusrt.junit.rules.FixtureElementRule;
+import org.eclipse.papyrusrt.umlrt.tooling.ui.widgets.PropertyReplicationObservableValue;
+import org.eclipse.uml2.uml.OpaqueExpression;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecification;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+
+/**
+ * Test cases for the {@link PropertyReplicationObservableValue} class.
+ */
+@PluginResource("resource/modelelement/model.di")
+public class PropertyReplicationObservableValueTest {
+
+ @Rule
+ public final HouseKeeper housekeeper = new HouseKeeper();
+
+ // Yes, it's heavyweight, but the observable needs the default language service
+ @Rule
+ public final ModelSetFixture modelSet = new ServiceRegistryModelSetFixture();
+
+ /** We are testing an observable, so give it a nice realm. */
+ @Rule
+ public final TestRule dataBindings = new DataBindingsRule();
+
+ @Rule
+ public final FixtureElementRule elements = new FixtureElementRule("model");
+
+ @CleanUp
+ IObservableValue<String> fixture;
+
+ @Named("Capsule::externalBehavior")
+ Property property;
+
+ public PropertyReplicationObservableValueTest() {
+ super();
+ }
+
+ @Test
+ public void setIntegerReplication() {
+ fixture.setValue("4");
+
+ assertReplication(4);
+ }
+
+ @Test
+ public void setSymbolicReplication() {
+ fixture.setValue("MAX_REPLICATION");
+
+ assertReplication("MAX_REPLICATION");
+ }
+
+ @Test
+ public void valueSpecificationsUnnamed() {
+ fixture.setValue("4");
+
+ assumeThat(property.getLowerValue(), notNullValue());
+ assertThat(property.getLowerValue().getName(), nullValue());
+ assumeThat(property.getUpperValue(), notNullValue());
+ assertThat(property.getUpperValue().getName(), nullValue());
+
+ fixture.setValue("MAX_REPLICATION");
+
+ assumeThat(property.getLowerValue(), notNullValue());
+ assertThat(property.getLowerValue().getName(), nullValue());
+ assumeThat(property.getUpperValue(), notNullValue());
+ assertThat(property.getUpperValue().getName(), nullValue());
+ }
+
+ @Test
+ public void changeNumericReplication() {
+ initReplication(4);
+
+ ValueSpecification lowerValue = property.getLowerValue();
+ ValueSpecification upperValue = property.getUpperValue();
+
+ fixture.setValue("7");
+
+ assertReplication(7);
+
+ assertThat("Lower value replaced", property.getLowerValue(), sameInstance(lowerValue));
+ assertThat("Upper value replaced", property.getUpperValue(), sameInstance(upperValue));
+ }
+
+ @Test
+ public void changeNumericReplicationToSymbolic() {
+ initReplication(4);
+
+ fixture.setValue("MAX_REPLICATION");
+
+ assertReplication("MAX_REPLICATION");
+ }
+
+ @Test
+ public void changeSymbolicReplication() {
+ initReplication("MAX_REPLICATION");
+
+ ValueSpecification lowerValue = property.getLowerValue();
+ ValueSpecification upperValue = property.getUpperValue();
+
+ fixture.setValue("NUM_PORTS");
+
+ assertReplication("NUM_PORTS");
+
+ assertThat("Lower value replaced", property.getLowerValue(), sameInstance(lowerValue));
+ assertThat("Upper value replaced", property.getUpperValue(), sameInstance(upperValue));
+ }
+
+ @Test
+ public void changeSymbolicReplicationToNumeric() {
+ initReplication("MAX_REPLICATION");
+
+ fixture.setValue("4");
+
+ assertReplication(4);
+ }
+
+ @Test
+ public void resetNumericReplication() {
+ initReplication(4);
+
+ fixture.setValue("None (1)");
+
+ assertDefaultReplication();
+ }
+
+ @Test
+ public void resetSymbolicReplication() {
+ initReplication("MAX_REPLICATION");
+
+ fixture.setValue("None (1)");
+
+ assertDefaultReplication();
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ @SuppressWarnings("unchecked")
+ public void createFixture() {
+ fixture = new PropertyReplicationObservableValue(property, modelSet.getEditingDomain());
+ }
+
+ void assertDefaultReplication() {
+ assertThat("Has lower bound", property.getLowerValue(), nullValue());
+ assertThat("Wrong lower bound", property.getLower(), is(1));
+ assertThat("Has upper bound", property.getUpperValue(), nullValue());
+ assertThat("Wrong upper bound", property.getUpper(), is(1));
+
+ assertThat("Wrong observable value", fixture.getValue(), is("None (1)"));
+ }
+
+ void assertReplication(int replication) {
+ assertThat("Wrong lower bound", property.getLower(), is(replication));
+ assertThat("Wrong upper bound", property.getUpper(), is(replication));
+
+ assertThat("Wrong observable value", fixture.getValue(), is(String.valueOf(replication)));
+ }
+
+ void assertReplication(String replication) {
+ assertThat("No lower bound", property.getLowerValue(), notNullValue());
+ assertThat("Wrong lower bound", property.getLowerValue().stringValue(), is(replication));
+ assertThat("No upper bound", property.getUpperValue(), notNullValue());
+ assertThat("Wrong upper bound", property.getUpperValue().stringValue(), is(replication));
+
+ assertThat("Wrong observable value", fixture.getValue(), is(String.valueOf(replication)));
+ }
+
+ void initReplication(int replication) {
+ EditingDomain domain = modelSet.getEditingDomain();
+
+ Command command = SetCommand.create(domain, property, UMLPackage.Literals.MULTIPLICITY_ELEMENT__LOWER, replication);
+ command = command.chain(SetCommand.create(domain, property, UMLPackage.Literals.MULTIPLICITY_ELEMENT__UPPER, replication));
+
+ modelSet.execute(command);
+ }
+
+ void initReplication(String replication) {
+ EditingDomain domain = modelSet.getEditingDomain();
+ EFactory factory = modelSet.getResourceSet().getPackageRegistry().getEFactory(UMLPackage.eNS_URI);
+
+ OpaqueExpression lowerValue = (OpaqueExpression) factory.create(UMLPackage.Literals.OPAQUE_EXPRESSION);
+ lowerValue.getBodies().add(replication);
+ lowerValue.getLanguages().add("C++");
+ OpaqueExpression upperValue = (OpaqueExpression) factory.create(UMLPackage.Literals.OPAQUE_EXPRESSION);
+ upperValue.getBodies().add(replication);
+ upperValue.getLanguages().add("C++");
+
+
+ Command command = SetCommand.create(domain, property, UMLPackage.Literals.MULTIPLICITY_ELEMENT__LOWER_VALUE, lowerValue);
+ command = command.chain(SetCommand.create(domain, property, UMLPackage.Literals.MULTIPLICITY_ELEMENT__UPPER_VALUE, upperValue));
+
+ modelSet.execute(command);
+ }
+}

Back to the top