Skip to content

Commit fea4c91

Browse files
salujajaskeeratJaskeerat Singh Saluja
andauthored
feat(alias-import): added test case for introspector (#882)
* feat(alias-import): added test case for introspector Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(alias import):Pr fix Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(alias import):Pr fixes Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(alias import): Pr changes Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(import alias): Field renamed Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(alias-import): additional check to verify alias import Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(alias-import): Types updated Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> * feat(alias-import): reverting change-log file Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> --------- Signed-off-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local> Co-authored-by: Jaskeerat Singh Saluja <salujajaskeerat@Jaskeerats-MacBook-Pro.local>
1 parent 425fc18 commit fea4c91

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

packages/concerto-core/lib/basemodelmanager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BaseModelManager {
8282
* @param {boolean} [options.metamodelValidation] - When true, modelfiles will be validated
8383
* @param {boolean} [options.addMetamodel] - When true, the Concerto metamodel is added to the model manager
8484
* @param {boolean} [options.enableMapType] - When true, the Concerto Map Type feature is enabled
85-
* @param {boolean} [options.enableAliasedType] - When true, the Concerto Aliasing feature is enabled
85+
* @param {boolean} [options.importAliasing] - When true, the Concerto Aliasing feature is enabled
8686
* @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager
8787
*/
8888
constructor(options, processFile) {
@@ -98,7 +98,7 @@ class BaseModelManager {
9898
// TODO Remove on release of MapType
9999
// Supports both env var and property based flag
100100
this.enableMapType = !!options?.enableMapType;
101-
this.enableAliasedType = !!options?.enableAliasedType;
101+
this.importAliasing = !!options?.importAliasing;
102102

103103
// Cache a copy of the Metamodel ModelFile for use when validating the structure of ModelFiles later.
104104
this.metamodelModelFile = new ModelFile(this, MetaModelUtil.metaModelAst, undefined, MetaModelNamespace);
@@ -126,10 +126,10 @@ class BaseModelManager {
126126

127127
/**
128128
* Checks if the import aliasing feature is enabled.
129-
* @returns {boolean} true if the enableAliasedType has been set
129+
* @returns {boolean} true if the importAliasing has been set
130130
*/
131131
isAliasedTypeEnabled() {
132-
return this.enableAliasedType;
132+
return this.importAliasing;
133133
}
134134

135135
/**

packages/concerto-core/lib/introspect/modelfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ class ModelFile extends Decorated {
789789
);
790790
} else {
791791
if (imp.aliasedTypes) {
792-
throw new Error('Aliasing disabled, set enableAliasType to true');
792+
throw new Error('Aliasing disabled, set importAliasing to true');
793793
}
794794
imp.types.forEach((type) => {
795795
this.importShortNames.set(type,`${imp.namespace}.${type}`);

packages/concerto-core/test/introspect/introspector.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const chai = require('chai');
2424
chai.use(require('chai-things'));
2525
const sinon = require('sinon');
2626
require('chai').should();
27+
const ParserUtil = require('./parserutility');
2728

2829
describe('Introspector', () => {
2930

@@ -80,6 +81,32 @@ describe('Introspector', () => {
8081
const introspector = new Introspector(modelManager);
8182
introspector.getClassDeclaration('org.acme.base.Person').should.not.be.null;
8283
});
84+
85+
it('should be able to handle the aliased imported types', () => {
86+
// create and populate the ModelManager with a model file
87+
const modelManager = new ModelManager({ importAliasing: true });
88+
Util.addComposerModel(modelManager);
89+
modelManager.should.not.be.null;
90+
91+
const model1 = `
92+
namespace org.example.ext
93+
asset MyAsset2 identified by assetId {
94+
o String assetId
95+
}`;
96+
const model2 = `
97+
namespace org.acme
98+
import org.example.ext.{MyAsset2 as m}
99+
asset MyAsset identified by assetId {
100+
o String assetId
101+
o m[] arr
102+
}`;
103+
let modelFile1 = ParserUtil.newModelFile(modelManager, model1);
104+
modelManager.addModelFile(modelFile1);
105+
let modelFile2 = ParserUtil.newModelFile(modelManager, model2);
106+
const introspector = new Introspector(modelManager);
107+
modelFile2.resolveImport('m').should.equal('org.example.ext.MyAsset2');
108+
introspector.getClassDeclaration('org.example.ext.MyAsset2').should.not.be.null;
109+
});
83110
});
84111

85112
describe('#getModelManager', () => {

packages/concerto-core/test/introspect/modelfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ describe('ModelFile', () => {
611611
describe('#aliasedImport', () => {
612612

613613
beforeEach(()=>{
614-
modelManager.enableAliasedType=true;
614+
modelManager.importAliasing=true;
615615
});
616616
it('should resolve aliased name of import type', () => {
617617
const model = `

packages/concerto-core/types/lib/basemodelmanager.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare class BaseModelManager {
2424
* @param {boolean} [options.metamodelValidation] - When true, modelfiles will be validated
2525
* @param {boolean} [options.addMetamodel] - When true, the Concerto metamodel is added to the model manager
2626
* @param {boolean} [options.enableMapType] - When true, the Concerto Map Type feature is enabled
27-
* @param {boolean} [options.enableAliasedType] - When true, the Concerto Aliasing feature is enabled
27+
* @param {boolean} [options.importAliasing] - When true, the Concerto Aliasing feature is enabled
2828
* @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager
2929
*/
3030
constructor(options?: {
@@ -33,7 +33,7 @@ declare class BaseModelManager {
3333
metamodelValidation?: boolean;
3434
addMetamodel?: boolean;
3535
enableMapType?: boolean;
36-
enableAliasedType?: boolean;
36+
importAliasing?: boolean;
3737
}, processFile?: any);
3838
processFile: any;
3939
modelFiles: {};
@@ -47,10 +47,10 @@ declare class BaseModelManager {
4747
metamodelValidation?: boolean;
4848
addMetamodel?: boolean;
4949
enableMapType?: boolean;
50-
enableAliasedType?: boolean;
50+
importAliasing?: boolean;
5151
};
5252
enableMapType: boolean;
53-
enableAliasedType: boolean;
53+
importAliasing: boolean;
5454
metamodelModelFile: any;
5555
/**
5656
* Returns true
@@ -64,7 +64,7 @@ declare class BaseModelManager {
6464
isStrict(): boolean;
6565
/**
6666
* Checks if the import aliasing feature is enabled.
67-
* @returns {boolean} true if the enableAliasedType has been set
67+
* @returns {boolean} true if the importAliasing has been set
6868
*/
6969
isAliasedTypeEnabled(): boolean;
7070
/**

0 commit comments

Comments
 (0)