summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-10 06:09:18 (EDT)
committerEd Merks2011-08-10 06:09:18 (EDT)
commitdd4f2f7dfbe0003c15c502f39dc45ac1974cf44b (patch)
tree4032fa603c887994315f750f7193096336b7ebe2
parenta25783533a9e61364fb9be05258a6bf2a0fde9c9 (diff)
downloadorg.eclipse.emf-dd4f2f7dfbe0003c15c502f39dc45ac1974cf44b.zip
org.eclipse.emf-dd4f2f7dfbe0003c15c502f39dc45ac1974cf44b.tar.gz
org.eclipse.emf-dd4f2f7dfbe0003c15c502f39dc45ac1974cf44b.tar.bz2
added a multi file tests incl. bidirectional relationships between two XPackages
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.xtend95
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/interpreter/XcoreInterpreterXbaseIntegrationTest.java2
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.java169
3 files changed, 265 insertions, 1 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.xtend b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.xtend
new file mode 100644
index 0000000..3aa635d
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.xtend
@@ -0,0 +1,95 @@
+package org.eclipse.emf.ecore.xcore.tests
+
+import com.google.inject.Inject
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage
+import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.ecore.xcore.XClass
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider
+import org.eclipse.xtext.junit4.InjectWith
+import org.eclipse.xtext.junit4.XtextRunner
+import org.eclipse.xtext.junit4.validation.ValidationTestHelper
+import org.eclipse.xtext.resource.IResourceDescriptions
+import org.eclipse.xtext.resource.XtextResourceSet
+import org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions
+import org.eclipse.xtext.util.StringInputStream
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import static org.junit.Assert.*
+
+import static extension org.eclipse.xtext.xtend2.lib.ResourceExtensions.*
+import org.eclipse.emf.ecore.xcore.XReference
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper
+
+@RunWith(typeof(XtextRunner))
+@InjectWith(typeof(XcoreInjectorProvider))
+class MultiFileTest {
+
+ @Inject
+ XtextResourceSet resourceSet
+
+ @Inject
+ ValidationTestHelper validator
+
+ @Inject
+ IResourceDescriptions descriptions
+
+ @Inject
+ extension XcoreMapper mapper
+
+ @Test
+ def void testReferenceBetweenTwoModels() {
+ val resourceA = resourceSet.createResource(URI::createURI('file:/modelA.xcore'))
+ val resourceB = resourceSet.createResource(URI::createURI('file:/modelB.xcore'))
+ resourceB.load(new StringInputStream('''
+ package packB
+
+ class TypeB {
+ }
+ '''.toString), null)
+ resourceA.load(new StringInputStream('''
+ package packA
+
+ class TypeA {
+ refers packB.TypeB refToB
+ }
+ '''.toString), null)
+
+ validator.assertNoErrors(resourceA.contents.head)
+ validator.assertNoErrors(resourceB.contents.head)
+ val allContents = resourceA.allContentsIterable
+ val xclass = allContents.filter(typeof(XClass)).head
+ val referencedGenClass = xclass.members.head.type.type
+ assertEquals('TypeB', (referencedGenClass as GenClass).name)
+ }
+
+ @Test
+ def void testBidirectionalReferenceBetweenTwoModels() {
+ val resourceA = resourceSet.createResource(URI::createURI('file:/modelA.xcore'))
+ val resourceB = resourceSet.createResource(URI::createURI('file:/modelB.xcore'))
+ resourceB.load(new StringInputStream('''
+ package packB
+
+ class TypeB {
+ refers packA.TypeA refToA opposite refToB
+ }
+ '''.toString), null)
+ resourceA.load(new StringInputStream('''
+ package packA
+
+ class TypeA {
+ refers packB.TypeB refToB opposite refToA
+ }
+ '''.toString), null)
+
+ validator.assertNoErrors(resourceA.contents.head)
+ validator.assertNoErrors(resourceB.contents.head)
+ val allContents = resourceA.allContentsIterable
+ val xclass = allContents.filter(typeof(XClass)).head
+ val referencedGenClass = xclass.members.head.type.type
+ assertEquals('TypeB', (referencedGenClass as GenClass).name)
+ val ref = xclass.members.head as XReference
+ assertEquals(ref , (ref.opposite.XFeature as XReference).opposite.XFeature)
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/interpreter/XcoreInterpreterXbaseIntegrationTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/interpreter/XcoreInterpreterXbaseIntegrationTest.java
index f81a2ea..6499892 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/interpreter/XcoreInterpreterXbaseIntegrationTest.java
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/interpreter/XcoreInterpreterXbaseIntegrationTest.java
@@ -44,7 +44,7 @@ public class XcoreInterpreterXbaseIntegrationTest extends AbstractXbaseEvaluatio
private ValidationTestHelper validator;
protected Object invokeXbaseExpression(String expression) throws Exception {
- XPackage pack = parser.parse("package foo class Bar { op void foo() { "+expression+" } }");
+ XPackage pack = parser.parse("package foo class Bar { op Object foo() { "+expression+" } }");
validator.assertNoErrors(pack);
EPackage ePack = (EPackage) pack.eResource().getContents().get(2);
EClass barClass = (EClass) ePack.getEClassifier("Bar");
diff --git a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.java b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.java
new file mode 100644
index 0000000..62ebea7
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/MultiFileTest.java
@@ -0,0 +1,169 @@
+package org.eclipse.emf.ecore.xcore.tests;
+
+import com.google.inject.Inject;
+import java.io.IOException;
+import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XGenericType;
+import org.eclipse.emf.ecore.xcore.XMember;
+import org.eclipse.emf.ecore.xcore.XReference;
+import org.eclipse.emf.ecore.xcore.XStructuralFeature;
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.junit4.validation.ValidationTestHelper;
+import org.eclipse.xtext.resource.IResourceDescriptions;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.util.StringInputStream;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xtend2.lib.ResourceExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SuppressWarnings("all")
+@RunWith(XtextRunner.class)
+@InjectWith(XcoreInjectorProvider.class)
+public class MultiFileTest {
+
+ @Inject
+ private XtextResourceSet resourceSet;
+
+ @Inject
+ private ValidationTestHelper validator;
+
+ @Inject
+ private IResourceDescriptions descriptions;
+
+ @Inject
+ private XcoreMapper mapper;
+
+ @Test
+ public void testReferenceBetweenTwoModels() throws IOException {
+ {
+ URI _createURI = URI.createURI("file:/modelA.xcore");
+ Resource _createResource = this.resourceSet.createResource(_createURI);
+ final Resource resourceA = _createResource;
+ URI _createURI_1 = URI.createURI("file:/modelB.xcore");
+ Resource _createResource_1 = this.resourceSet.createResource(_createURI_1);
+ final Resource resourceB = _createResource_1;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package packB");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class TypeB {");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ String _string = _builder.toString();
+ StringInputStream _stringInputStream = new StringInputStream(_string);
+ resourceB.load(_stringInputStream, null);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("package packA");
+ _builder_1.newLine();
+ _builder_1.newLine();
+ _builder_1.append("class TypeA {");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.append("refers packB.TypeB refToB ");
+ _builder_1.newLine();
+ _builder_1.append("}");
+ _builder_1.newLine();
+ String _string_1 = _builder_1.toString();
+ StringInputStream _stringInputStream_1 = new StringInputStream(_string_1);
+ resourceA.load(_stringInputStream_1, null);
+ EList<EObject> _contents = resourceA.getContents();
+ EObject _head = IterableExtensions.<EObject>head(_contents);
+ this.validator.assertNoErrors(_head);
+ EList<EObject> _contents_1 = resourceB.getContents();
+ EObject _head_1 = IterableExtensions.<EObject>head(_contents_1);
+ this.validator.assertNoErrors(_head_1);
+ Iterable<EObject> _allContentsIterable = ResourceExtensions.allContentsIterable(resourceA);
+ final Iterable<EObject> allContents = _allContentsIterable;
+ Iterable<XClass> _filter = IterableExtensions.<XClass>filter(allContents, org.eclipse.emf.ecore.xcore.XClass.class);
+ XClass _head_2 = IterableExtensions.<XClass>head(_filter);
+ final XClass xclass = _head_2;
+ EList<XMember> _members = xclass.getMembers();
+ XMember _head_3 = IterableExtensions.<XMember>head(_members);
+ XGenericType _type = _head_3.getType();
+ GenBase _type_1 = _type.getType();
+ final GenBase referencedGenClass = _type_1;
+ String _name = ((GenClass) referencedGenClass).getName();
+ Assert.assertEquals("TypeB", _name);
+ }
+ }
+
+ @Test
+ public void testBidirectionalReferenceBetweenTwoModels() throws IOException {
+ {
+ URI _createURI = URI.createURI("file:/modelA.xcore");
+ Resource _createResource = this.resourceSet.createResource(_createURI);
+ final Resource resourceA = _createResource;
+ URI _createURI_1 = URI.createURI("file:/modelB.xcore");
+ Resource _createResource_1 = this.resourceSet.createResource(_createURI_1);
+ final Resource resourceB = _createResource_1;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package packB");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class TypeB {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("refers packA.TypeA refToA opposite refToB");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ String _string = _builder.toString();
+ StringInputStream _stringInputStream = new StringInputStream(_string);
+ resourceB.load(_stringInputStream, null);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("package packA");
+ _builder_1.newLine();
+ _builder_1.newLine();
+ _builder_1.append("class TypeA {");
+ _builder_1.newLine();
+ _builder_1.append("\t");
+ _builder_1.append("refers packB.TypeB refToB opposite refToA");
+ _builder_1.newLine();
+ _builder_1.append("}");
+ _builder_1.newLine();
+ String _string_1 = _builder_1.toString();
+ StringInputStream _stringInputStream_1 = new StringInputStream(_string_1);
+ resourceA.load(_stringInputStream_1, null);
+ EList<EObject> _contents = resourceA.getContents();
+ EObject _head = IterableExtensions.<EObject>head(_contents);
+ this.validator.assertNoErrors(_head);
+ EList<EObject> _contents_1 = resourceB.getContents();
+ EObject _head_1 = IterableExtensions.<EObject>head(_contents_1);
+ this.validator.assertNoErrors(_head_1);
+ Iterable<EObject> _allContentsIterable = ResourceExtensions.allContentsIterable(resourceA);
+ final Iterable<EObject> allContents = _allContentsIterable;
+ Iterable<XClass> _filter = IterableExtensions.<XClass>filter(allContents, org.eclipse.emf.ecore.xcore.XClass.class);
+ XClass _head_2 = IterableExtensions.<XClass>head(_filter);
+ final XClass xclass = _head_2;
+ EList<XMember> _members = xclass.getMembers();
+ XMember _head_3 = IterableExtensions.<XMember>head(_members);
+ XGenericType _type = _head_3.getType();
+ GenBase _type_1 = _type.getType();
+ final GenBase referencedGenClass = _type_1;
+ String _name = ((GenClass) referencedGenClass).getName();
+ Assert.assertEquals("TypeB", _name);
+ EList<XMember> _members_1 = xclass.getMembers();
+ XMember _head_4 = IterableExtensions.<XMember>head(_members_1);
+ final XReference ref = ((XReference) _head_4);
+ GenFeature _opposite = ref.getOpposite();
+ XStructuralFeature _xFeature = this.mapper.getXFeature(_opposite);
+ GenFeature _opposite_1 = ((XReference) _xFeature).getOpposite();
+ XStructuralFeature _xFeature_1 = this.mapper.getXFeature(_opposite_1);
+ Assert.assertEquals(ref, _xFeature_1);
+ }
+ }
+} \ No newline at end of file