Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-01-14 16:01:09 +0000
committerChristian W. Damus2014-01-14 16:01:55 +0000
commit852812e09f0f507ac4b172bc3bc94a0c083e4b3f (patch)
tree197990c5451ae92540696dd7d30143a80f4e010b
parentf0c731b2e7c9f87f06ab848192e89c6208cb8ecd (diff)
downloadorg.eclipse.uml2-852812e09f0f507ac4b172bc3bc94a0c083e4b3f.tar.gz
org.eclipse.uml2-852812e09f0f507ac4b172bc3bc94a0c083e4b3f.tar.xz
org.eclipse.uml2-852812e09f0f507ac4b172bc3bc94a0c083e4b3f.zip
[405065] OCL Property initializers should be copied during conversion to Ecore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=405065 JUnit tests.
-rw-r--r--tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml29
-rw-r--r--tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java217
-rw-r--r--tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java3
3 files changed, 248 insertions, 1 deletions
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml
new file mode 100644
index 000000000..b1827e686
--- /dev/null
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Package 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="_yboL0HrWEeOmgIVCTlT7jw" name="initials" URI="http://www.eclipse.org/uml2/schemas/tests/bugs/405065">
+ <elementImport xmi:id="_ExyDwHrXEeOmgIVCTlT7jw">
+ <importedElement xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ </elementImport>
+ <packagedElement xmi:type="uml:Class" xmi:id="_4Z_AoHrWEeOmgIVCTlT7jw" name="Thing">
+ <ownedAttribute xmi:id="__ApLkHrWEeOmgIVCTlT7jw" name="cost">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_J7sj4HrXEeOmgIVCTlT7jw" name="tax">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ <defaultValue xmi:type="uml:LiteralReal" xmi:id="_a5vRAHrlEeOU_OLbrrQL2A" value="0.08"/>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_LbQ5MHrXEeOmgIVCTlT7jw" name="discount">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ <defaultValue xmi:type="uml:OpaqueExpression" xmi:id="_V51J0HrXEeOmgIVCTlT7jw">
+ <language>OCL</language>
+ <body>self.cost / 10.0</body>
+ </defaultValue>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_NLQQIHrXEeOmgIVCTlT7jw" name="price" isReadOnly="true" isDerived="true">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ <defaultValue xmi:type="uml:OpaqueExpression" xmi:id="_W2ei0HrYEeOmgIVCTlT7jw">
+ <language>OCL</language>
+ <body>(self.cost - self.discount) * (1.0 + self.tax)</body>
+ </defaultValue>
+ </ownedAttribute>
+ </packagedElement>
+</uml:Package>
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java
new file mode 100644
index 000000000..f2173463d
--- /dev/null
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java
@@ -0,0 +1,217 @@
+/*
+ * 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.uml2.uml.bug.tests;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+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.ecore.util.EcoreUtil;
+import org.eclipse.uml2.common.util.UML2Util;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.tests.util.StandaloneSupport;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * Tests the support for non-API constraints in classifiers that convert to
+ * Ecore EClasses.
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=405065
+ */
+public class Bug405065Test
+ extends TestCase {
+
+ private static final String ECORE_ANNOTATION_URI = "http://www.eclipse.org/emf/2002/Ecore";
+
+ private static final String OCL_ANNOTATION_URI = ECORE_ANNOTATION_URI
+ + "/OCL";
+
+ private ResourceSet rset;
+
+ private Package fixture;
+
+ public Bug405065Test() {
+ super();
+ }
+
+ public Bug405065Test(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new TestSuite(Bug405065Test.class, "Bug 405065 tests"); //$NON-NLS-1$
+ }
+
+ public void testControl() {
+ // a control test for features that should not be annotated
+ EPackage ePackage = convert();
+
+ EAttribute cost = getEAttribute(getEClass(ePackage, "Thing"), "cost");
+ assertNoOCLAnnotation(cost);
+ assertFalse(cost.isDerived());
+ assertTrue(cost.isChangeable());
+ }
+
+ public void testDerivedFeature() {
+ EPackage ePackage = convert();
+
+ EAttribute price = getEAttribute(getEClass(ePackage, "Thing"), "price");
+ assertOCLAnnotation(price, "derivation",
+ "(self.cost - self.discount) * (1.0 + self.tax)");
+ assertTrue(price.isDerived());
+ assertFalse(price.isChangeable());
+ }
+
+ public void testInitialValueFeature() {
+ EPackage ePackage = convert();
+
+ EAttribute discount = getEAttribute(getEClass(ePackage, "Thing"),
+ "discount");
+ assertOCLAnnotation(discount, "initial", "self.cost / 10.0");
+ assertFalse(discount.isDerived());
+ assertTrue(discount.isChangeable());
+ }
+
+ //
+ // Test framework
+ //
+
+ @Override
+ protected void setUp()
+ throws Exception {
+
+ rset = new ResourceSetImpl();
+ if (StandaloneSupport.isStandalone()) {
+ StandaloneSupport.init(rset);
+ }
+
+ fixture = getTestModel();
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception {
+
+ fixture = null;
+
+ // clean up the CacheAdapter as well as we can
+ for (Resource next : rset.getResources()) {
+ next.unload();
+ next.eAdapters().clear();
+ }
+
+ rset.getResources().clear();
+ rset.eAdapters().clear();
+ }
+
+ Package getTestModel() {
+ URL url = getClass().getResource("Bug405065.uml"); //$NON-NLS-1$
+ return (Package) UML2Util.load(rset,
+ URI.createURI(url.toExternalForm()), UMLPackage.Literals.PACKAGE);
+ }
+
+ EPackage convert() {
+ return convert(fixture);
+ }
+
+ EPackage convert(Package package_) {
+ Map<String, String> options = new HashMap<String, String>();
+ options.put(
+ UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ UMLUtil.OPTION__PROCESS);
+ options.put(UMLUtil.UML2EcoreConverter.OPTION__DERIVED_FEATURES,
+ UMLUtil.OPTION__PROCESS);
+
+ Collection<EPackage> ecores = UMLUtil.convertToEcore(package_, options);
+
+ assertNotNull(ecores);
+ assertTrue(ecores.size() > 0);
+
+ EPackage result = ecores.iterator().next();
+ assertEquals("initials", result.getName());
+
+ assertEcoreAnnotation(result, "settingDelegates", OCL_ANNOTATION_URI);
+
+ return result;
+ }
+
+ EClass getEClass(EPackage ePackage, String name) {
+ return getEClassifier(ePackage, name, EClass.class);
+ }
+
+ EDataType getEDataType(EPackage ePackage, String name) {
+ return getEClassifier(ePackage, name, EDataType.class);
+ }
+
+ <T extends EClassifier> T getEClassifier(EPackage ePackage, String name,
+ Class<T> metaclass) {
+ EClassifier result = ePackage.getEClassifier(name);
+ assertTrue(metaclass.isInstance(result));
+ return metaclass.cast(result);
+ }
+
+ EAttribute getEAttribute(EClass eClass, String name) {
+ EStructuralFeature result = eClass.getEStructuralFeature(name);
+
+ assertTrue("EAttribute not found: " + name,
+ result instanceof EAttribute);
+ return (EAttribute) result;
+ }
+
+ void assertEcoreAnnotation(EModelElement element, String key, String value) {
+ assertAnnotation(element, ECORE_ANNOTATION_URI, key, value);
+ }
+
+ void assertOCLAnnotation(EModelElement element, String key, String value) {
+ assertAnnotation(element, OCL_ANNOTATION_URI, key, value);
+ }
+
+ void assertAnnotation(EModelElement element, String source, String key,
+ String value) {
+ String annotation = EcoreUtil.getAnnotation(element, source, key);
+ assertNotNull("Annotation key not found", annotation);
+ assertTrue(Pattern
+ .compile(
+ String.format("(?:^|\\s)%s(?:$|\\s)", Pattern.quote(value)))
+ .matcher(annotation).find());
+ }
+
+ void assertNoOCLAnnotation(EModelElement element) {
+ assertNoAnnotation(element, OCL_ANNOTATION_URI);
+ }
+
+ void assertNoAnnotation(EModelElement element, String source) {
+ EAnnotation annotation = element.getEAnnotation(source);
+ assertNull("Found annotation", annotation);
+ }
+
+}
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java
index b3c807dd9..e21585d40 100644
--- a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Christian W. Damus (CEA) - initial API and implementation
- * Christian W. Damus (CEA) - 409396, 403365, 300957, 405061, 401682, 176998, 180744, 403374, 420338
+ * Christian W. Damus (CEA) - 409396, 403365, 300957, 405061, 401682, 176998, 180744, 403374, 420338, 405065
* Manuel Bork <bork@yatta.de> (Yatta Solutions GmbH) - 421756, 422000
*
*/
@@ -53,6 +53,7 @@ public class UMLBugTests
result.addTest(Bug403374Test.suite());
result.addTest(Bug416833Test.suite());
result.addTest(Bug420338Test.suite());
+ result.addTest(Bug405065Test.suite());
return result;
}

Back to the top