Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus')
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/UMLModelElementTest.java152
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/bug507479.uml37
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/tests/AllTests.java29
3 files changed, 218 insertions, 0 deletions
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/UMLModelElementTest.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/UMLModelElementTest.java
new file mode 100644
index 00000000000..bdbbb13f364
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/UMLModelElementTest.java
@@ -0,0 +1,152 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.properties.modelelement.tests;
+
+import static java.util.Collections.singleton;
+import static java.util.stream.Collectors.toSet;
+import static org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.properties.ui.modelelement.ModelElement;
+import org.eclipse.papyrus.infra.ui.emf.providers.strategy.ContainmentBrowseStrategy;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy;
+import org.eclipse.papyrus.infra.widgets.strategy.StrategyBasedContentProvider;
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.eclipse.papyrus.junit.utils.rules.JavaResource;
+import org.eclipse.papyrus.junit.utils.rules.ResourceSetFixture;
+import org.eclipse.papyrus.uml.properties.modelelement.UMLModelElement;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.CombinedFragment;
+import org.eclipse.uml2.uml.Interaction;
+import org.eclipse.uml2.uml.InteractionOperand;
+import org.eclipse.uml2.uml.Lifeline;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests for the {@link UMLModelElement} class.
+ */
+public class UMLModelElementTest extends AbstractPapyrusTest {
+
+ @Rule
+ public final ResourceSetFixture rset = new ResourceSetFixture();
+
+ /**
+ * Initializes me.
+ */
+ public UMLModelElementTest() {
+ super();
+ }
+
+ /**
+ * Verify that the content provider supplied for browsing potential covered lifelines
+ * of combined fragments includes only and exactly lifelines from the contextual
+ * interaction.
+ */
+ @Test
+ @JavaResource("bug507479.uml")
+ public void combinedFragment_contentProvider() {
+ Interaction interaction = getInteraction("Foo");
+ CombinedFragment cfrag = (CombinedFragment) interaction.getFragment("cfrag");
+
+ ITreeContentProvider content = getContentProvider(getElement(cfrag), "covered");
+
+ // The other class and its lifelines are not provided
+ Collection<Lifeline> lifelines = getProvidedContent(content, Lifeline.class);
+ Set<Interaction> fromInteractions = lifelines.stream().map(Lifeline::getInteraction).collect(toSet());
+ assertThat("Lifelines from wrong interaction", fromInteractions, is(singleton(interaction)));
+ }
+
+ /**
+ * Verify that the content provider supplied for browsing potential covered lifelines
+ * of interaction operands includes only and exactly lifelines from the contextual
+ * interaction.
+ */
+ @Test
+ @JavaResource("bug507479.uml")
+ public void interactionOperand_contentProvider() {
+ Interaction interaction = getInteraction("Foo");
+ CombinedFragment cfrag = (CombinedFragment) interaction.getFragment("cfrag");
+ InteractionOperand operand = cfrag.getOperand("opt");
+
+ ITreeContentProvider content = getContentProvider(getElement(operand), "covered");
+
+ // The other class and its lifelines are not provided
+ Collection<Lifeline> lifelines = getProvidedContent(content, Lifeline.class);
+ Set<Interaction> fromInteractions = lifelines.stream().map(Lifeline::getInteraction).collect(toSet());
+ assertThat("Lifelines from wrong interaction", fromInteractions, is(singleton(interaction)));
+ }
+
+ //
+ // Test framework
+ //
+
+ private Class getClass(String name) {
+ return (Class) rset.getModel().getOwnedType(name);
+ }
+
+ private Interaction getInteraction(String className) {
+ return (Interaction) getClass(className).getClassifierBehavior();
+ }
+
+ ModelElement getElement(EObject object) {
+ return new UMLModelElement(object, getEditingDomainFor(object));
+ }
+
+ ITreeContentProvider getContentProvider(ModelElement element, String propertyPath) {
+ IStaticContentProvider content = element.getContentProvider(propertyPath);
+ assertThat("Not a tree content provider", content, instanceOf(ITreeContentProvider.class));
+
+ ITreeContentProvider treeContent = (ITreeContentProvider) content;
+
+ // This uses isValidValue as in the Reference Editor Dialog to determine what
+ // to show and what may be selected
+ return new StrategyBasedContentProvider(new ProviderBasedBrowseStrategy(treeContent),
+ new ContainmentBrowseStrategy(treeContent));
+ }
+
+ <T> Collection<T> getProvidedContent(ITreeContentProvider content, java.lang.Class<T> type) {
+ Collection<T> result = new LinkedHashSet<>();
+
+ IStaticContentProvider staticContent = (IStaticContentProvider) content;
+ collectProvidedContent(content, staticContent.getElements(), type, 0, result);
+
+ return result;
+ }
+
+ private <T> void collectProvidedContent(ITreeContentProvider content, Object[] elements, java.lang.Class<T> type, int depth, Collection<? super T> result) {
+ if (depth < 100) { // Some content providers are cyclic
+ Stream.of(elements)
+ .peek(child -> collectProvidedContent(content, child, type, depth + 1, result))
+ .map(EMFHelper::getEObject)
+ .filter(type::isInstance).map(type::cast)
+ .forEach(result::add);
+ }
+ }
+
+ private <T> void collectProvidedContent(ITreeContentProvider content, Object parent, java.lang.Class<T> type, int depth, Collection<? super T> result) {
+ collectProvidedContent(content, content.getChildren(parent), type, depth, result);
+ }
+}
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/bug507479.uml b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/bug507479.uml
new file mode 100644
index 00000000000..b50b4552f18
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/modelelement/tests/bug507479.uml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Sot0IHi_EeizYruIlswaLQ" name="model">
+ <packagedElement xmi:type="uml:Class" xmi:id="_V4QSQHi_EeizYruIlswaLQ" name="Foo" classifierBehavior="_aYuMwHi_EeizYruIlswaLQ" isActive="true">
+ <ownedBehavior xmi:type="uml:Interaction" xmi:id="_aYuMwHi_EeizYruIlswaLQ" name="doIt">
+ <lifeline xmi:id="_b8u9MHi_EeizYruIlswaLQ" name="a" coveredBy="_i6VBcHi_EeizYruIlswaLQ _6u_wgHi_EeizYruIlswaLQ _4Ax2wHi_EeizYruIlswaLQ"/>
+ <lifeline xmi:id="_c2R0UHi_EeizYruIlswaLQ" name="b" coveredBy="_kj188Hi_EeizYruIlswaLQ _6u_wgHi_EeizYruIlswaLQ _4Ax2wHi_EeizYruIlswaLQ"/>
+ <lifeline xmi:id="_dAHs0Hi_EeizYruIlswaLQ" name="c"/>
+ <fragment xmi:type="uml:CombinedFragment" xmi:id="_4Ax2wHi_EeizYruIlswaLQ" name="cfrag" covered="_b8u9MHi_EeizYruIlswaLQ _c2R0UHi_EeizYruIlswaLQ" interactionOperator="opt">
+ <operand xmi:id="_6u_wgHi_EeizYruIlswaLQ" name="opt" covered="_b8u9MHi_EeizYruIlswaLQ _c2R0UHi_EeizYruIlswaLQ">
+ <fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_i6VBcHi_EeizYruIlswaLQ" name="send" covered="_b8u9MHi_EeizYruIlswaLQ" message="_mgSbgHi_EeizYruIlswaLQ"/>
+ <fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_kj188Hi_EeizYruIlswaLQ" name="recv" covered="_c2R0UHi_EeizYruIlswaLQ" message="_mgSbgHi_EeizYruIlswaLQ"/>
+ <guard xmi:id="_CU38wHjAEeizYruIlswaLQ">
+ <specification xmi:type="uml:LiteralBoolean" xmi:id="_E0eLsHjAEeizYruIlswaLQ" value="true"/>
+ </guard>
+ </operand>
+ </fragment>
+ <message xmi:id="_mgSbgHi_EeizYruIlswaLQ" name="hello" messageSort="asynchSignal" receiveEvent="_kj188Hi_EeizYruIlswaLQ" sendEvent="_i6VBcHi_EeizYruIlswaLQ"/>
+ </ownedBehavior>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Class" xmi:id="_HBI3kHjAEeizYruIlswaLQ" name="Bar" classifierBehavior="_HBI3kXjAEeizYruIlswaLQ" isActive="true">
+ <ownedBehavior xmi:type="uml:Interaction" xmi:id="_HBI3kXjAEeizYruIlswaLQ" name="forbidden">
+ <lifeline xmi:id="_HBI3knjAEeizYruIlswaLQ" name="a" coveredBy="_HBI3l3jAEeizYruIlswaLQ _HBI3lnjAEeizYruIlswaLQ _HBI3lXjAEeizYruIlswaLQ"/>
+ <lifeline xmi:id="_HBI3k3jAEeizYruIlswaLQ" name="b" coveredBy="_HBI3mHjAEeizYruIlswaLQ _HBI3lnjAEeizYruIlswaLQ _HBI3lXjAEeizYruIlswaLQ"/>
+ <lifeline xmi:id="_HBI3lHjAEeizYruIlswaLQ" name="c"/>
+ <fragment xmi:type="uml:CombinedFragment" xmi:id="_HBI3lXjAEeizYruIlswaLQ" name="cfrag" covered="_HBI3knjAEeizYruIlswaLQ _HBI3k3jAEeizYruIlswaLQ" interactionOperator="opt">
+ <operand xmi:id="_HBI3lnjAEeizYruIlswaLQ" name="opt" covered="_HBI3knjAEeizYruIlswaLQ _HBI3k3jAEeizYruIlswaLQ">
+ <fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_HBI3l3jAEeizYruIlswaLQ" name="send" covered="_HBI3knjAEeizYruIlswaLQ" message="_HBI3m3jAEeizYruIlswaLQ"/>
+ <fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_HBI3mHjAEeizYruIlswaLQ" name="recv" covered="_HBI3k3jAEeizYruIlswaLQ" message="_HBI3m3jAEeizYruIlswaLQ"/>
+ <guard xmi:id="_HBI3mXjAEeizYruIlswaLQ">
+ <specification xmi:type="uml:LiteralBoolean" xmi:id="_HBI3mnjAEeizYruIlswaLQ" value="true"/>
+ </guard>
+ </operand>
+ </fragment>
+ <message xmi:id="_HBI3m3jAEeizYruIlswaLQ" name="greet" messageSort="asynchSignal" receiveEvent="_HBI3mHjAEeizYruIlswaLQ" sendEvent="_HBI3l3jAEeizYruIlswaLQ"/>
+ </ownedBehavior>
+ </packagedElement>
+</uml:Model>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/tests/AllTests.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/tests/AllTests.java
new file mode 100644
index 00000000000..8cec2243e43
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.properties.tests/src/org/eclipse/papyrus/uml/properties/tests/AllTests.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Christian W. Damus - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.properties.tests;
+
+import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
+import org.eclipse.papyrus.uml.properties.modelelement.tests.UMLModelElementTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Test suite for the UML Properties bundle.
+ */
+@RunWith(ClassificationSuite.class)
+@SuiteClasses({
+ UMLModelElementTest.class,
+})
+public class AllTests {
+ // Everything is specified in class annotations
+}

Back to the top