[241148] cdamus - [UML] Stereotype application instances not found by allInstances()
diff --git a/tests/org.eclipse.ocl.uml.tests/model/OCLTest.profile.uml b/tests/org.eclipse.ocl.uml.tests/model/OCLTest.profile.uml
index 4d9a3bf..5380419 100644
--- a/tests/org.eclipse.ocl.uml.tests/model/OCLTest.profile.uml
+++ b/tests/org.eclipse.ocl.uml.tests/model/OCLTest.profile.uml
@@ -6,11 +6,12 @@
<eAnnotations xmi:id="_OKrFNJw_Edu3G72hG9l7lw" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_UXYxAJw9Edu3G72hG9l7lw"/>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_OKrFNZw_Edu3G72hG9l7lw" name="yesno" ordered="false" lowerBound="1" eType="_OKrFO5w_Edu3G72hG9l7lw"/>
<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_OKrFN5w_Edu3G72hG9l7lw" name="base_Classifier" ordered="false" lowerBound="1">
- <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/2.0.0/UML#//Classifier"/>
+ <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/2.1.0/UML#//Classifier"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_OKrFOZw_Edu3G72hG9l7lw" name="x" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
</eStructuralFeatures>
+ <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_WPrW-WFoEd2KF7b32sxqwA" name="tag" ordered="false" upperBound="-1" eType="_WPrXAGFoEd2KF7b32sxqwA" containment="true"/>
</eClassifiers>
<eClassifiers xmi:type="ecore:EEnum" xmi:id="_OKrFO5w_Edu3G72hG9l7lw" name="YesNo">
<eAnnotations xmi:id="_OKrFPJw_Edu3G72hG9l7lw" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_YyviAJw9Edu3G72hG9l7lw"/>
@@ -18,6 +19,12 @@
<eLiterals xmi:id="_OKrFPpw_Edu3G72hG9l7lw" name="no" value="1"/>
<eLiterals xmi:id="_OKrFP5w_Edu3G72hG9l7lw" name="yes" value="2"/>
</eClassifiers>
+ <eClassifiers xmi:type="ecore:EClass" xmi:id="_WPrXAGFoEd2KF7b32sxqwA" name="Tag">
+ <eAnnotations xmi:id="_WPrXAWFoEd2KF7b32sxqwA" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_0hjPcGFnEd2KF7b32sxqwA"/>
+ <eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_WPrXAmFoEd2KF7b32sxqwA" name="name" ordered="false" lowerBound="1">
+ <eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eStructuralFeatures>
+ </eClassifiers>
</contents>
</eAnnotations>
<packageImport xmi:id="_MKZhcJw9Edu3G72hG9l7lw">
@@ -31,6 +38,10 @@
<ownedAttribute xmi:id="_IEWAIJw_Edu3G72hG9l7lw" name="x">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
</ownedAttribute>
+ <ownedAttribute xmi:id="_APs4oGFoEd2KF7b32sxqwA" name="tag" type="_0hjPcGFnEd2KF7b32sxqwA" aggregation="composite" association="_JOYq4GFoEd2KF7b32sxqwA">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_DD10MGFoEd2KF7b32sxqwA" value="*"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_CdBEwGFoEd2KF7b32sxqwA"/>
+ </ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Enumeration" xmi:id="_YyviAJw9Edu3G72hG9l7lw" name="YesNo">
<ownedLiteral xmi:id="_aTlpsJw9Edu3G72hG9l7lw" name="maybe"/>
@@ -40,4 +51,12 @@
<packagedElement xmi:type="uml:Extension" xmi:id="_xkm5IJw9Edu3G72hG9l7lw" name="Classifier_Stereo1" memberEnd="_xkm5IZw9Edu3G72hG9l7lw _xkm5Ipw9Edu3G72hG9l7lw">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_xkm5IZw9Edu3G72hG9l7lw" name="extension_Stereo1" type="_UXYxAJw9Edu3G72hG9l7lw" aggregation="composite" association="_xkm5IJw9Edu3G72hG9l7lw"/>
</packagedElement>
+ <packagedElement xmi:type="uml:Class" xmi:id="_0hjPcGFnEd2KF7b32sxqwA" name="Tag">
+ <ownedAttribute xmi:id="_5Aop4GFnEd2KF7b32sxqwA" name="name">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
+ </ownedAttribute>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Association" xmi:id="_JOYq4GFoEd2KF7b32sxqwA" memberEnd="_APs4oGFoEd2KF7b32sxqwA _QktYMGFoEd2KF7b32sxqwA">
+ <ownedEnd xmi:id="_QktYMGFoEd2KF7b32sxqwA" type="_UXYxAJw9Edu3G72hG9l7lw" association="_JOYq4GFoEd2KF7b32sxqwA"/>
+ </packagedElement>
</uml:Profile>
diff --git a/tests/org.eclipse.ocl.uml.tests/src/org/eclipse/ocl/uml/tests/ProfilesTest.java b/tests/org.eclipse.ocl.uml.tests/src/org/eclipse/ocl/uml/tests/ProfilesTest.java
index fd81971..2ff413b 100644
--- a/tests/org.eclipse.ocl.uml.tests/src/org/eclipse/ocl/uml/tests/ProfilesTest.java
+++ b/tests/org.eclipse.ocl.uml.tests/src/org/eclipse/ocl/uml/tests/ProfilesTest.java
@@ -1,7 +1,7 @@
/**
* <copyright>
*
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2008 IBM Corporation, Zeligsoft Inc. 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
@@ -9,19 +9,32 @@
*
* Contributors:
* IBM - Initial API and implementation
- *
+ * Zeligsoft - Bug 241148
+ *
* </copyright>
*
- * $Id: ProfilesTest.java,v 1.4 2008/02/15 05:20:16 cdamus Exp $
+ * $Id: ProfilesTest.java,v 1.4.2.1 2008/08/03 14:38:14 cdamus Exp $
*/
package org.eclipse.ocl.uml.tests;
+import java.util.List;
+import java.util.Set;
+
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.ocl.expressions.OCLExpression;
+import org.eclipse.ocl.util.Bag;
+import org.eclipse.ocl.util.CollectionUtil;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
@@ -44,6 +57,8 @@
private static Property stereoEnum;
private static Property stereoX;
+
+ private static Property stereoTag;
private static Enumeration testEnumeration;
@@ -52,6 +67,14 @@
private static EnumerationLiteral no;
private static EnumerationLiteral yes;
+
+ private static Class tag;
+
+ private static EClass eTag;
+
+ private static Property tagName;
+
+ private static EAttribute eTagName;
public ProfilesTest(String name) {
super(name);
@@ -137,6 +160,74 @@
fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
}
+
+ /**
+ * Tests the <tt>allInstances()</tt> query on stereotypes.
+ */
+ public void test_allInstances_stereotype_241148() {
+ helper.setContext(testStereotype);
+
+ try {
+ OCLExpression<Classifier> expr = helper
+ .createQuery("Stereo1.allInstances().base_Classifier.name"); //$NON-NLS-1$
+
+ // set up a couple of stereotyped classes to test the query on
+ fruit.applyStereotype(testStereotype);
+
+ tree.applyStereotype(testStereotype);
+
+ Bag<String> expectedValue = CollectionUtil.createNewBag();
+ expectedValue.add("Fruit"); //$NON-NLS-1$
+ expectedValue.add("Tree"); //$NON-NLS-1$
+
+ assertEquals(expectedValue, evaluate(expr, fruit));
+ } catch (Exception e) {
+ fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Tests the <tt>allInstances()</tt> query on classes defined in profiles.
+ */
+ @SuppressWarnings("unchecked")
+ public void test_allInstances_profileClass_241148() {
+ helper.setContext(testStereotype);
+
+ try {
+ OCLExpression<Classifier> expr = helper
+ .createQuery("Tag.allInstances()"); //$NON-NLS-1$
+
+ // set up a couple of stereotyped classes to test the query on
+ fruit.applyStereotype(testStereotype);
+ EObject tag1 = EcoreUtil.create(eTag);
+ List<EObject> tags = (List<EObject>) fruit.getValue(testStereotype,
+ stereoTag.getName());
+ tags.add(tag1);
+ tag1.eSet(eTagName, "myTag"); //$NON-NLS-1$
+
+ tree.applyStereotype(testStereotype);
+ EObject tag2 = EcoreUtil.create(eTag);
+ tags = (List<EObject>) tree.getValue(testStereotype, stereoTag
+ .getName());
+ tags.add(tag2);
+ tag2.eSet(eTagName, "anotherTag"); //$NON-NLS-1$
+
+ Set<EObject> expectedInstances = new java.util.HashSet<EObject>();
+ expectedInstances.add(tag1);
+ expectedInstances.add(tag2);
+ assertEquals(expectedInstances, evaluate(expr, fruit));
+
+ expr = helper.createQuery("Tag.allInstances().name"); //$NON-NLS-1$
+
+ Bag<String> expectedValue = CollectionUtil.createNewBag();
+ expectedValue.add("myTag"); //$NON-NLS-1$
+ expectedValue.add("anotherTag"); //$NON-NLS-1$
+
+ assertEquals(expectedValue, evaluate(expr, fruit));
+ } catch (Exception e) {
+ fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); //$NON-NLS-1$
+ }
+ }
//
// Test Framework
@@ -163,10 +254,13 @@
testStereotype = null;
stereoEnum = null;
stereoX = null;
+ stereoTag = null;
testEnumeration = null;
maybe = null;
no = null;
yes = null;
+ tag = null;
+ tagName = null;
super.tearDown();
}
@@ -186,6 +280,8 @@
assertNotNull(stereoEnum);
stereoX = testStereotype.getOwnedAttribute("x", null); //$NON-NLS-1$
assertNotNull(stereoX);
+ stereoTag = testStereotype.getOwnedAttribute("tag", null); //$NON-NLS-1$
+ assertNotNull(stereoTag);
testEnumeration = (Enumeration) testProfile.getOwnedType("YesNo"); //$NON-NLS-1$
assertNotNull(testEnumeration);
@@ -195,5 +291,14 @@
assertNotNull(no);
yes = testEnumeration.getOwnedLiteral("yes"); //$NON-NLS-1$
assertNotNull(yes);
+
+ tag = (Class) testProfile.getOwnedType("Tag"); //$NON-NLS-1$
+ assertNotNull(tag);
+ eTag = (EClass) testProfile.getDefinition(tag);
+ assertNotNull(eTag);
+ tagName = tag.getOwnedAttribute("name", null); //$NON-NLS-1$
+ assertNotNull(tagName);
+ eTagName = (EAttribute) eTag.getEStructuralFeature(tagName.getName());
+ assertNotNull(eTagName);
}
}