@@ -2,8 +2,14 @@ import { afterEach, beforeAll, describe, expect, test } from 'vitest'
22import { EmptyFileSystem , type LangiumDocument } from 'langium'
33import { clearDocuments , parseHelper } from 'langium/test'
44import { createContextMapperDslServices } from '../../src/language/ContextMapperDslModule.js'
5- import { ContextMappingModel , isSharedKernel } from '../../src/language/generated/ast.js'
6- import { checkDocumentValid } from '../TestHelper.js'
5+ import {
6+ ContextMappingModel ,
7+ CustomerSupplierRelationship ,
8+ Partnership ,
9+ SharedKernel ,
10+ UpstreamDownstreamRelationship
11+ } from '../../src/language/generated/ast.js'
12+ import { parseValidInput } from '../ParsingTestHelper.js'
713
814let services : ReturnType < typeof createContextMapperDslServices >
915let parse : ReturnType < typeof parseHelper < ContextMappingModel > >
@@ -12,38 +18,155 @@ let document: LangiumDocument<ContextMappingModel> | undefined
1218beforeAll ( async ( ) => {
1319 services = createContextMapperDslServices ( EmptyFileSystem )
1420 parse = parseHelper < ContextMappingModel > ( services . ContextMapperDsl )
15-
16- // activate the following if your linking test requires elements from a built-in library, for example
17- // await services.shared.workspace.WorkspaceManager.initializeWorkspace([]);
1821} )
1922
2023afterEach ( async ( ) => {
2124 document && await clearDocuments ( services . shared , [ document ] )
2225} )
2326
2427describe ( 'Bounded context linking tests' , ( ) => {
25- test ( 'linking of bounded contexts in context map' , async ( ) => {
26- document = await parse ( `
27- ContextMap {
28- TestContext [SK] <-> [SK] FirstContext
29- }
30- BoundedContext FirstContext
31- BoundedContext TestContext
32- ` )
33-
34- const errors = checkDocumentValid ( document )
35- expect ( errors == null ) . toBeTruthy ( )
36-
37- const referencedContexts : Array < string | undefined > = [ ]
38-
39- document . parseResult . value . contextMaps [ 0 ] . relationships . forEach ( r => {
40- if ( isSharedKernel ( r ) ) {
41- referencedContexts . push ( r . participant1 . ref ?. name )
42- referencedContexts . push ( r . participant2 . ref ?. name )
43- }
44- } )
45-
46- expect ( referencedContexts . length ) . toBe ( 2 )
47- expect ( referencedContexts ) . toEqual ( [ 'TestContext' , 'FirstContext' ] )
28+ test ( 'check linking of bounded contexts in context map SharedKernel relationship' , async ( ) => {
29+ document = await parseValidInput ( parse , `
30+ ContextMap {
31+ TestContext [SK] <-> [SK] FirstContext
32+ }
33+ BoundedContext FirstContext
34+ BoundedContext TestContext
35+ ` )
36+
37+ const relationship = document . parseResult . value . contextMaps [ 0 ] . relationships [ 0 ] as SharedKernel
38+ expect ( relationship . participant1 . ref ) . not . toBeUndefined ( )
39+ expect ( relationship . participant1 . ref ?. name ) . toEqual ( 'TestContext' )
40+ expect ( relationship . participant2 . ref ) . not . toBeUndefined ( )
41+ expect ( relationship . participant2 . ref ?. name ) . toEqual ( 'FirstContext' )
42+ } )
43+
44+ test ( 'check linking of bounded contexts in context map Partnership relationship' , async ( ) => {
45+ document = await parseValidInput ( parse , `
46+ ContextMap {
47+ FirstContext Partnership TestContext
48+ }
49+ BoundedContext FirstContext
50+ BoundedContext TestContext
51+ ` )
52+
53+ const relationship = document . parseResult . value . contextMaps [ 0 ] . relationships [ 0 ] as Partnership
54+ expect ( relationship . participant1 . ref ) . not . toBeUndefined ( )
55+ expect ( relationship . participant1 . ref ?. name ) . toEqual ( 'FirstContext' )
56+ expect ( relationship . participant2 . ref ) . not . toBeUndefined ( )
57+ expect ( relationship . participant2 . ref ?. name ) . toEqual ( 'TestContext' )
58+ } )
59+
60+ test ( 'check linking of bounded contexts in context map UpstreamDownstream relationship' , async ( ) => {
61+ document = await parseValidInput ( parse , `
62+ ContextMap {
63+ FirstContext -> TestContext
64+ }
65+ BoundedContext FirstContext
66+ BoundedContext TestContext
67+ ` )
68+
69+ const relationship = document . parseResult . value . contextMaps [ 0 ] . relationships [ 0 ] as UpstreamDownstreamRelationship
70+ expect ( relationship . upstream . ref ) . not . toBeUndefined ( )
71+ expect ( relationship . upstream . ref ?. name ) . toEqual ( 'FirstContext' )
72+ expect ( relationship . downstream . ref ) . not . toBeUndefined ( )
73+ expect ( relationship . downstream . ref ?. name ) . toEqual ( 'TestContext' )
74+ } )
75+
76+ test ( 'check linking of bounded contexts in context map CustomerSupplier relationship' , async ( ) => {
77+ document = await parseValidInput ( parse , `
78+ ContextMap {
79+ FirstContext [C] <- [S] TestContext
80+ }
81+ BoundedContext FirstContext
82+ BoundedContext TestContext
83+ ` )
84+
85+ const relationship = document . parseResult . value . contextMaps [ 0 ] . relationships [ 0 ] as CustomerSupplierRelationship
86+ expect ( relationship . downstream . ref ) . not . toBeUndefined ( )
87+ expect ( relationship . downstream . ref ?. name ) . toEqual ( 'FirstContext' )
88+ expect ( relationship . upstream . ref ) . not . toBeUndefined ( )
89+ expect ( relationship . upstream . ref ?. name ) . toEqual ( 'TestContext' )
90+ } )
91+
92+ test ( 'check linking of bounded contexts in context map' , async ( ) => {
93+ document = await parseValidInput ( parse , `
94+ ContextMap {
95+ contains FirstContext
96+ contains SecondContext
97+ }
98+ BoundedContext FirstContext
99+ BoundedContext SecondContext
100+ ` )
101+
102+ const contextMap = document . parseResult . value . contextMaps [ 0 ]
103+ expect ( contextMap . boundedContexts ) . toHaveLength ( 2 )
104+ expect ( contextMap . boundedContexts [ 0 ] . ref ) . not . toBeUndefined ( )
105+ expect ( contextMap . boundedContexts [ 0 ] . ref ?. name ) . toEqual ( 'FirstContext' )
106+ expect ( contextMap . boundedContexts [ 1 ] . ref ) . not . toBeUndefined ( )
107+ expect ( contextMap . boundedContexts [ 1 ] . ref ?. name ) . toEqual ( 'SecondContext' )
108+ } )
109+
110+ test ( 'check linking of bounded context from bounded context' , async ( ) => {
111+ document = await parseValidInput ( parse , `
112+ BoundedContext TestContext
113+ refines RefinedContext
114+ realizes RealizedContext
115+
116+ BoundedContext RealizedContext
117+ BoundedContext RefinedContext
118+ ` )
119+
120+ const boundedContext = document . parseResult . value . boundedContexts [ 0 ]
121+ expect ( boundedContext . refinedBoundedContext ) . not . toBeUndefined ( )
122+ expect ( boundedContext . refinedBoundedContext . ref ) . not . toBeUndefined ( )
123+ expect ( boundedContext . refinedBoundedContext . ref ?. name ) . toEqual ( 'RefinedContext' )
124+ expect ( boundedContext . realizedBoundedContexts ) . toHaveLength ( 1 )
125+ expect ( boundedContext . realizedBoundedContexts [ 0 ] . ref ) . not . toBeUndefined ( )
126+ expect ( boundedContext . realizedBoundedContexts [ 0 ] . ref ?. name ) . toEqual ( 'RealizedContext' )
127+ } )
128+
129+ test ( 'check linking of aggregate owner' , async ( ) => {
130+ document = await parseValidInput ( parse , `
131+ BoundedContext TestContext {
132+ Aggregate TestAggregate {
133+ owner TestContext
134+ }
135+ }
136+ ` )
137+
138+ const aggregate = document . parseResult . value . boundedContexts [ 0 ] . aggregates [ 0 ]
139+ expect ( aggregate . owner ) . not . toBeUndefined ( )
140+ expect ( aggregate . owner ?. ref ) . not . toBeUndefined ( )
141+ expect ( aggregate . owner ?. ref ?. name ) . toEqual ( 'TestContext' )
142+ } )
143+
144+ test ( 'check linking of shareholders context' , async ( ) => {
145+ document = await parseValidInput ( parse , `
146+ BoundedContext FirstContext
147+ BoundedContext SecondContext
148+ Stakeholders of SecondContext, FirstContext
149+ ` )
150+
151+ const stakeholders = document . parseResult . value . stakeholders [ 0 ]
152+ expect ( stakeholders . contexts ) . toHaveLength ( 2 )
153+ expect ( stakeholders . contexts [ 0 ] ) . not . toBeUndefined ( )
154+ expect ( stakeholders . contexts [ 0 ] . ref ) . not . toBeUndefined ( )
155+ expect ( stakeholders . contexts [ 0 ] . ref ?. name ) . toEqual ( 'SecondContext' )
156+ expect ( stakeholders . contexts [ 1 ] ) . not . toBeUndefined ( )
157+ expect ( stakeholders . contexts [ 1 ] . ref ) . not . toBeUndefined ( )
158+ expect ( stakeholders . contexts [ 1 ] . ref ?. name ) . toEqual ( 'FirstContext' )
159+ } )
160+
161+ test ( 'check linking of ValueRegister context' , async ( ) => {
162+ document = await parseValidInput ( parse , `
163+ BoundedContext SecondContext
164+ ValueRegister TestRegister for SecondContext
165+ ` )
166+
167+ const valueRegister = document . parseResult . value . valueRegisters [ 0 ]
168+ expect ( valueRegister . context ) . not . toBeUndefined ( )
169+ expect ( valueRegister . context ?. ref ) . not . toBeUndefined ( )
170+ expect ( valueRegister . context ?. ref ?. name ) . toEqual ( 'SecondContext' )
48171 } )
49172} )
0 commit comments