Skip to content

Commit

Permalink
feat(alias-import): added test case for introspector (#882)
Browse files Browse the repository at this point in the history
* feat(alias-import): added test case for introspector

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(alias import):Pr fix

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(alias import):Pr fixes

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(alias import): Pr changes

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(import alias): Field renamed

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(alias-import): additional check to verify alias import

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(alias-import): Types updated

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

* feat(alias-import): reverting change-log file

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>

---------

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>
Co-authored-by: Jaskeerat Singh Saluja <[email protected]>
  • Loading branch information
salujajaskeerat and Jaskeerat Singh Saluja authored Aug 27, 2024
1 parent 425fc18 commit fea4c91
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/concerto-core/lib/basemodelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class BaseModelManager {
* @param {boolean} [options.metamodelValidation] - When true, modelfiles will be validated
* @param {boolean} [options.addMetamodel] - When true, the Concerto metamodel is added to the model manager
* @param {boolean} [options.enableMapType] - When true, the Concerto Map Type feature is enabled
* @param {boolean} [options.enableAliasedType] - When true, the Concerto Aliasing feature is enabled
* @param {boolean} [options.importAliasing] - When true, the Concerto Aliasing feature is enabled
* @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager
*/
constructor(options, processFile) {
Expand All @@ -98,7 +98,7 @@ class BaseModelManager {
// TODO Remove on release of MapType
// Supports both env var and property based flag
this.enableMapType = !!options?.enableMapType;
this.enableAliasedType = !!options?.enableAliasedType;
this.importAliasing = !!options?.importAliasing;

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

/**
* Checks if the import aliasing feature is enabled.
* @returns {boolean} true if the enableAliasedType has been set
* @returns {boolean} true if the importAliasing has been set
*/
isAliasedTypeEnabled() {
return this.enableAliasedType;
return this.importAliasing;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ class ModelFile extends Decorated {
);
} else {
if (imp.aliasedTypes) {
throw new Error('Aliasing disabled, set enableAliasType to true');
throw new Error('Aliasing disabled, set importAliasing to true');
}
imp.types.forEach((type) => {
this.importShortNames.set(type,`${imp.namespace}.${type}`);
Expand Down
27 changes: 27 additions & 0 deletions packages/concerto-core/test/introspect/introspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const chai = require('chai');
chai.use(require('chai-things'));
const sinon = require('sinon');
require('chai').should();
const ParserUtil = require('./parserutility');

describe('Introspector', () => {

Expand Down Expand Up @@ -80,6 +81,32 @@ describe('Introspector', () => {
const introspector = new Introspector(modelManager);
introspector.getClassDeclaration('org.acme.base.Person').should.not.be.null;
});

it('should be able to handle the aliased imported types', () => {
// create and populate the ModelManager with a model file
const modelManager = new ModelManager({ importAliasing: true });
Util.addComposerModel(modelManager);
modelManager.should.not.be.null;

const model1 = `
namespace org.example.ext
asset MyAsset2 identified by assetId {
o String assetId
}`;
const model2 = `
namespace org.acme
import org.example.ext.{MyAsset2 as m}
asset MyAsset identified by assetId {
o String assetId
o m[] arr
}`;
let modelFile1 = ParserUtil.newModelFile(modelManager, model1);
modelManager.addModelFile(modelFile1);
let modelFile2 = ParserUtil.newModelFile(modelManager, model2);
const introspector = new Introspector(modelManager);
modelFile2.resolveImport('m').should.equal('org.example.ext.MyAsset2');
introspector.getClassDeclaration('org.example.ext.MyAsset2').should.not.be.null;
});
});

describe('#getModelManager', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-core/test/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ describe('ModelFile', () => {
describe('#aliasedImport', () => {

beforeEach(()=>{
modelManager.enableAliasedType=true;
modelManager.importAliasing=true;
});
it('should resolve aliased name of import type', () => {
const model = `
Expand Down
10 changes: 5 additions & 5 deletions packages/concerto-core/types/lib/basemodelmanager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare class BaseModelManager {
* @param {boolean} [options.metamodelValidation] - When true, modelfiles will be validated
* @param {boolean} [options.addMetamodel] - When true, the Concerto metamodel is added to the model manager
* @param {boolean} [options.enableMapType] - When true, the Concerto Map Type feature is enabled
* @param {boolean} [options.enableAliasedType] - When true, the Concerto Aliasing feature is enabled
* @param {boolean} [options.importAliasing] - When true, the Concerto Aliasing feature is enabled
* @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager
*/
constructor(options?: {
Expand All @@ -33,7 +33,7 @@ declare class BaseModelManager {
metamodelValidation?: boolean;
addMetamodel?: boolean;
enableMapType?: boolean;
enableAliasedType?: boolean;
importAliasing?: boolean;
}, processFile?: any);
processFile: any;
modelFiles: {};
Expand All @@ -47,10 +47,10 @@ declare class BaseModelManager {
metamodelValidation?: boolean;
addMetamodel?: boolean;
enableMapType?: boolean;
enableAliasedType?: boolean;
importAliasing?: boolean;
};
enableMapType: boolean;
enableAliasedType: boolean;
importAliasing: boolean;
metamodelModelFile: any;
/**
* Returns true
Expand All @@ -64,7 +64,7 @@ declare class BaseModelManager {
isStrict(): boolean;
/**
* Checks if the import aliasing feature is enabled.
* @returns {boolean} true if the enableAliasedType has been set
* @returns {boolean} true if the importAliasing has been set
*/
isAliasedTypeEnabled(): boolean;
/**
Expand Down

0 comments on commit fea4c91

Please sign in to comment.