diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index 812083444..1faafe052 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -19,10 +19,7 @@ const { MetaModelNamespace } = require('@accordproject/concerto-metamodel'); const IllegalModelException = require('../../lib/introspect/illegalmodelexception'); const ClassDeclaration = require('../../lib/introspect/classdeclaration'); const AssetDeclaration = require('../../lib/introspect/assetdeclaration'); -const EnumDeclaration = require('../../lib/introspect/enumdeclaration'); const ConceptDeclaration = require('../../lib/introspect/conceptdeclaration'); -const ParticipantDeclaration = require('../../lib/introspect/participantdeclaration'); -const TransactionDeclaration = require('../../lib/introspect/transactiondeclaration'); const IntrospectUtils = require('./introspectutils'); const ParserUtil = require('./parserutility'); @@ -87,27 +84,6 @@ describe('ClassDeclaration', () => { }); describe('#validate', () => { - it('should throw when asset name is duplicted in a modelfile', () => { - let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.dupeassetname.cto', AssetDeclaration); - (() => { - asset.validate(); - }).should.throw(/Duplicate class/); - }); - - it('should throw when transaction name is duplicted in a modelfile', () => { - let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.dupetransactionname.cto', TransactionDeclaration); - (() => { - asset.validate(); - }).should.throw(/Duplicate class/); - }); - - it('should throw when participant name is duplicted in a modelfile', () => { - let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.dupeparticipantname.cto', ParticipantDeclaration); - (() => { - asset.validate(); - }).should.throw(/Duplicate class/); - }); - it('should throw when an super type identifier is redeclared', () => { let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.identifierextendsfromsupertype.cto', AssetDeclaration); (() => { @@ -123,20 +99,6 @@ describe('ClassDeclaration', () => { // }).should.throw(/Identifier defined in super class/); //}); - it('should throw when concept name is duplicted in a modelfile', () => { - let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.dupeconceptname.cto', ConceptDeclaration); - (() => { - asset.validate(); - }).should.throw(/Duplicate class/); - }); - - it('should throw when enum name is duplicted in a modelfile', () => { - let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.dupeenumname.cto', EnumDeclaration); - (() => { - asset.validate(); - }).should.throw(/Duplicate class/); - }); - it('should throw when not abstract, not enum and not concept without an identifier', () => { let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.noidentifier.cto', AssetDeclaration); asset.superType = null; diff --git a/packages/concerto-core/test/introspect/modelfile.js b/packages/concerto-core/test/introspect/modelfile.js index baafc77d0..7836d21b2 100644 --- a/packages/concerto-core/test/introspect/modelfile.js +++ b/packages/concerto-core/test/introspect/modelfile.js @@ -24,6 +24,7 @@ const EnumDeclaration = require('../../lib/introspect/enumdeclaration'); const IllegalModelException = require('../../lib/introspect/illegalmodelexception'); const ModelFile = require('../../lib/introspect/modelfile'); const ModelManager = require('../../lib/modelmanager'); +const IntrospectUtils = require('./introspectutils'); const fs = require('fs'); const path = require('path'); @@ -44,10 +45,12 @@ describe('ModelFile', () => { const carLeaseModel = fs.readFileSync(path.resolve(__dirname, '../data/model/carlease.cto'), 'utf8'); let modelManager; let sandbox; + let introspectUtils; beforeEach(() => { modelManager = new ModelManager(); Util.addComposerModel(modelManager); + introspectUtils = new IntrospectUtils(modelManager); sandbox = sinon.createSandbox(); }); @@ -203,6 +206,41 @@ describe('ModelFile', () => { describe('#validate', () => { + it('should throw when asset name is duplicted in a modelfile', () => { + let asset = introspectUtils.loadModelFile('test/data/parser/classdeclaration.dupeassetname.cto'); + (() => { + asset.validate(); + }).should.throw(/Duplicate class/); + }); + + it('should throw when transaction name is duplicted in a modelfile', () => { + let asset = introspectUtils.loadModelFile('test/data/parser/classdeclaration.dupetransactionname.cto'); + (() => { + asset.validate(); + }).should.throw(/Duplicate class/); + }); + + it('should throw when participant name is duplicted in a modelfile', () => { + let asset = introspectUtils.loadModelFile('test/data/parser/classdeclaration.dupeparticipantname.cto'); + (() => { + asset.validate(); + }).should.throw(/Duplicate class/); + }); + + it('should throw when concept name is duplicted in a modelfile', () => { + let asset = introspectUtils.loadModelFile('test/data/parser/classdeclaration.dupeconceptname.cto'); + (() => { + asset.validate(); + }).should.throw(/Duplicate class/); + }); + + it('should throw when enum name is duplicted in a modelfile', () => { + let asset = introspectUtils.loadModelFile('test/data/parser/classdeclaration.dupeenumname.cto'); + (() => { + asset.validate(); + }).should.throw(/Duplicate class/); + }); + it('should throw if an import exists for an invalid namespace', () => { const model = ` namespace org.acme