Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alias-import): added test case for introspector #882

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#

Version 3.17.1 {ddc91ebd1ff660b421b60302d1e92271} 2024-06-21
- Added 'enableAliasedType' option to BaseModelManager
- Added 'importAliasing' option to BaseModelManager
- Aliased types mapped to FQN in modelfile

Version 3.16.8 {a23d37a4a92071314ff821f879943364} 2024-07-09
Expand Down
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 @@
* @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 @@
// 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 @@

/**
* 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 Expand Up @@ -269,7 +269,7 @@
if (this.isStrict()) {
throw new MetamodelException(err.message);
} else {
console.warn('Invalid metamodel found. This will throw an exception in a future release. ', err.message);

Check warning on line 272 in packages/concerto-core/lib/basemodelmanager.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 272 in packages/concerto-core/lib/basemodelmanager.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement

Check warning on line 272 in packages/concerto-core/lib/basemodelmanager.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 272 in packages/concerto-core/lib/basemodelmanager.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 272 in packages/concerto-core/lib/basemodelmanager.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 272 in packages/concerto-core/lib/basemodelmanager.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement
}
}

Expand Down
26 changes: 26 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,31 @@ 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);
ParserUtil.newModelFile(modelManager, model2);
const introspector = new Introspector(modelManager);
introspector.getClassDeclaration('org.example.ext.MyAsset2').should.not.be.null;
salujajaskeerat marked this conversation as resolved.
Show resolved Hide resolved
});
});

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
Loading