Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 49a0c97582980cb43bf20b6302a5573254f8d7b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.eclipse.emf.test.ecore.xcore

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)
	}
}

Back to the top