Skip to content

Commit

Permalink
refactor(test): move validation checks for duplicate class to model file
Browse files Browse the repository at this point in the history
Signed-off-by: Ertugrul Karademir <[email protected]>
  • Loading branch information
ekarademir committed Jan 29, 2024
1 parent 112cbe1 commit bb29d0b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
38 changes: 0 additions & 38 deletions packages/concerto-core/test/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
(() => {
Expand All @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions packages/concerto-core/test/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
});

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb29d0b

Please sign in to comment.