@@ -25,6 +25,7 @@ const ParserUtil = require('./parserutility');
25
25
26
26
const ModelManager = require ( '../../lib/modelmanager' ) ;
27
27
const Util = require ( '../composer/composermodelutility' ) ;
28
+ const fs = require ( 'fs' ) ;
28
29
29
30
const sinon = require ( 'sinon' ) ;
30
31
const expect = require ( 'chai' ) . expect ;
@@ -46,7 +47,7 @@ describe('MapDeclaration', () => {
46
47
47
48
describe ( '#constructor' , ( ) => {
48
49
49
- it ( 'should throw if ast contains no Map Key Property ' , ( ) => {
50
+ it ( 'should throw if ast contains no Map Key Type ' , ( ) => {
50
51
( ( ) => {
51
52
new MapDeclaration ( modelFile , {
52
53
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -162,6 +163,13 @@ describe('MapDeclaration', () => {
162
163
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.goodkey.scalar.string.cto' , MapDeclaration ) ;
163
164
decl . validate ( ) ;
164
165
} ) ;
166
+
167
+ it ( 'should validate when map key is imported and is of valid map key type' , ( ) => {
168
+ const base_cto = fs . readFileSync ( 'test/data/parser/mapdeclaration/base.cto' , 'utf-8' ) ;
169
+ introspectUtils . modelManager . addCTOModel ( base_cto , 'base.cto' ) ;
170
+ let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.goodkey.imported.scalar.cto' , MapDeclaration ) ;
171
+ decl . validate ( ) ;
172
+ } ) ;
165
173
} ) ;
166
174
167
175
describe ( '#validate success scenarios - Map Value' , ( ) => {
@@ -254,11 +262,18 @@ describe('MapDeclaration', () => {
254
262
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.goodvalue.primitive.long.cto' , MapDeclaration ) ;
255
263
decl . validate ( ) ;
256
264
} ) ;
265
+
266
+ it ( 'should validate when map value is imported and is of valid map key type' , ( ) => {
267
+ const base_cto = fs . readFileSync ( 'test/data/parser/mapdeclaration/base.cto' , 'utf-8' ) ;
268
+ introspectUtils . modelManager . addCTOModel ( base_cto , 'base.cto' ) ;
269
+ let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto' , MapDeclaration ) ;
270
+ decl . validate ( ) ;
271
+ } ) ;
257
272
} ) ;
258
273
259
274
describe ( '#validate failure scenarios - Map Key' , ( ) => {
260
275
261
- it ( 'should throw if ast contains illegal Map Key Property ' , ( ) => {
276
+ it ( 'should throw if ast contains illegal Map Key Type ' , ( ) => {
262
277
( ( ) => {
263
278
new MapDeclaration ( modelFile , {
264
279
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -273,42 +288,42 @@ describe('MapDeclaration', () => {
273
288
} ) . should . throw ( IllegalModelException ) ;
274
289
} ) ;
275
290
276
- it ( 'should throw if ast contains illegal Map Key Property - Concept' , ( ) => {
291
+ it ( 'should throw if ast contains illegal Map Key Type - Concept' , ( ) => {
277
292
( ( ) => {
278
293
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.badkey.declaration.concept.cto' , MapDeclaration ) ;
279
294
decl . validate ( ) . should . throw ( IllegalModelException ) ;
280
295
} ) ;
281
296
} ) ;
282
297
283
- it ( 'should throw if ast contains illegal Map Key Property - Scalar Long' , ( ) => {
298
+ it ( 'should throw if ast contains illegal Map Key Type - Scalar Long' , ( ) => {
284
299
( ( ) => {
285
300
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.long.cto' , MapDeclaration ) ;
286
301
decl . validate ( ) ;
287
302
} ) ;
288
303
} ) ;
289
304
290
- it ( 'should throw if ast contains illegal Map Key Property - Scalar Integer' , ( ) => {
305
+ it ( 'should throw if ast contains illegal Map Key Type - Scalar Integer' , ( ) => {
291
306
( ( ) => {
292
307
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.integer.cto' , MapDeclaration ) ;
293
308
decl . validate ( ) . should . throw ( IllegalModelException ) ;
294
309
} ) ;
295
310
} ) ;
296
311
297
- it ( 'should throw if ast contains illegal Map Key Property - Scalar Double' , ( ) => {
312
+ it ( 'should throw if ast contains illegal Map Key Type - Scalar Double' , ( ) => {
298
313
( ( ) => {
299
314
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.double.cto' , MapDeclaration ) ;
300
315
decl . validate ( ) . should . throw ( IllegalModelException ) ;
301
316
} ) ;
302
317
} ) ;
303
318
304
- it ( 'should throw if ast contains illegal Map Key Property - Scalar Boolean' , ( ) => {
319
+ it ( 'should throw if ast contains illegal Map Key Type - Scalar Boolean' , ( ) => {
305
320
( ( ) => {
306
321
let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.boolean.cto' , MapDeclaration ) ;
307
322
decl . validate ( ) . should . throw ( IllegalModelException ) ;
308
323
} ) ;
309
324
} ) ;
310
325
311
- it ( 'should throw if ast contains illegal Map Key Property - Boolean' , ( ) => {
326
+ it ( 'should throw if ast contains illegal Map Key Type - Boolean' , ( ) => {
312
327
( ( ) => {
313
328
new MapDeclaration ( modelFile , {
314
329
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -323,7 +338,7 @@ describe('MapDeclaration', () => {
323
338
} ) . should . throw ( IllegalModelException ) ;
324
339
} ) ;
325
340
326
- it ( 'should throw if ast contains illegal Map Key Property - Integer' , ( ) => {
341
+ it ( 'should throw if ast contains illegal Map Key Type - Integer' , ( ) => {
327
342
( ( ) => {
328
343
new MapDeclaration ( modelFile , {
329
344
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -338,7 +353,7 @@ describe('MapDeclaration', () => {
338
353
} ) . should . throw ( IllegalModelException ) ;
339
354
} ) ;
340
355
341
- it ( 'should throw if ast contains illegal Map Key Property - Long' , ( ) => {
356
+ it ( 'should throw if ast contains illegal Map Key Type - Long' , ( ) => {
342
357
( ( ) => {
343
358
new MapDeclaration ( modelFile , {
344
359
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -353,7 +368,7 @@ describe('MapDeclaration', () => {
353
368
} ) . should . throw ( IllegalModelException ) ;
354
369
} ) ;
355
370
356
- it ( 'should throw if ast contains illegal Map Key Property - Double' , ( ) => {
371
+ it ( 'should throw if ast contains illegal Map Key Type - Double' , ( ) => {
357
372
( ( ) => {
358
373
new MapDeclaration ( modelFile , {
359
374
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -368,7 +383,7 @@ describe('MapDeclaration', () => {
368
383
} ) . should . throw ( IllegalModelException ) ;
369
384
} ) ;
370
385
371
- it ( 'should throw if ast contains illegal Map Key Property - Enum' , ( ) => {
386
+ it ( 'should throw if ast contains illegal Map Key Type - Enum' , ( ) => {
372
387
( ( ) => {
373
388
new MapDeclaration ( modelFile , {
374
389
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
@@ -386,6 +401,15 @@ describe('MapDeclaration', () => {
386
401
} ) ;
387
402
} ) . should . throw ( IllegalModelException ) ;
388
403
} ) ;
404
+
405
+ it ( 'should throw when map key is imported and is an illegal Map Key Type' , ( ) => {
406
+ ( ( ) => {
407
+ const base_cto = fs . readFileSync ( 'test/data/parser/mapdeclaration/base.cto' , 'utf-8' ) ;
408
+ introspectUtils . modelManager . addCTOModel ( base_cto , 'base.cto' ) ;
409
+ let decl = introspectUtils . loadLastDeclaration ( 'test/data/parser/mapdeclaration/mapdeclaration.badkey.imported.thing.cto' , MapDeclaration ) ;
410
+ decl . validate ( ) . should . throw ( IllegalModelException ) ;
411
+ } ) ;
412
+ } ) ;
389
413
} ) ;
390
414
391
415
describe ( '#validate failure scenarios - Map Value' , ( ) => {
@@ -489,7 +513,7 @@ describe('MapDeclaration', () => {
489
513
} ) ;
490
514
491
515
describe ( '#getKey' , ( ) => {
492
- it ( 'should return the map key property ' , ( ) => {
516
+ it ( 'should return the Map Key Type ' , ( ) => {
493
517
let clz = new MapDeclaration ( modelFile , {
494
518
$class : 'concerto.metamodel@1.0.0.MapDeclaration' ,
495
519
name : 'MapPermutation1' ,
0 commit comments