Skip to content

Commit

Permalink
feat(map): add test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Casey <[email protected]>
  • Loading branch information
jonathan-casey committed Oct 19, 2023
1 parent 02dfcdb commit 72baa6b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 13 deletions.
20 changes: 20 additions & 0 deletions packages/concerto-core/test/data/parser/mapdeclaration/base.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace [email protected]

concept Thing {
o String name
}

scalar Time extends DateTime
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace [email protected]

import [email protected].{Thing}

map Dictionary {
o Thing
o String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace [email protected]

import [email protected]

map Dictionary {
o Time
o String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace [email protected]

import [email protected]

map Dictionary {
o String
o Thing
}
50 changes: 37 additions & 13 deletions packages/concerto-core/test/introspect/mapdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ParserUtil = require('./parserutility');

const ModelManager = require('../../lib/modelmanager');
const Util = require('../composer/composermodelutility');
const fs = require('fs');

const sinon = require('sinon');
const expect = require('chai').expect;
Expand All @@ -46,7 +47,7 @@ describe('MapDeclaration', () => {

describe('#constructor', () => {

it('should throw if ast contains no Map Key Property', () => {
it('should throw if ast contains no Map Key Type', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand Down Expand Up @@ -162,6 +163,13 @@ describe('MapDeclaration', () => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodkey.scalar.string.cto', MapDeclaration);
decl.validate();
});

it('should validate when map key is imported and is of valid map key type', () => {
const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8');
introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto');
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodkey.imported.scalar.cto', MapDeclaration);
decl.validate();
});
});

describe('#validate success scenarios - Map Value', () => {
Expand Down Expand Up @@ -254,11 +262,18 @@ describe('MapDeclaration', () => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.primitive.long.cto', MapDeclaration);
decl.validate();
});

it('should validate when map value is imported and is of valid map key type', () => {
const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8');
introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto');
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto', MapDeclaration);
decl.validate();
});
});

describe('#validate failure scenarios - Map Key', () => {

it('should throw if ast contains illegal Map Key Property', () => {
it('should throw if ast contains illegal Map Key Type', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand All @@ -273,42 +288,42 @@ describe('MapDeclaration', () => {
}).should.throw(IllegalModelException);
});

it('should throw if ast contains illegal Map Key Property - Concept', () => {
it('should throw if ast contains illegal Map Key Type - Concept', () => {
(() => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.declaration.concept.cto', MapDeclaration);
decl.validate().should.throw(IllegalModelException);
});
});

it('should throw if ast contains illegal Map Key Property - Scalar Long', () => {
it('should throw if ast contains illegal Map Key Type - Scalar Long', () => {
(() => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.long.cto', MapDeclaration);
decl.validate();
});
});

it('should throw if ast contains illegal Map Key Property - Scalar Integer', () => {
it('should throw if ast contains illegal Map Key Type - Scalar Integer', () => {
(() => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.integer.cto', MapDeclaration);
decl.validate().should.throw(IllegalModelException);
});
});

it('should throw if ast contains illegal Map Key Property - Scalar Double', () => {
it('should throw if ast contains illegal Map Key Type - Scalar Double', () => {
(() => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.double.cto', MapDeclaration);
decl.validate().should.throw(IllegalModelException);
});
});

it('should throw if ast contains illegal Map Key Property - Scalar Boolean', () => {
it('should throw if ast contains illegal Map Key Type - Scalar Boolean', () => {
(() => {
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.boolean.cto', MapDeclaration);
decl.validate().should.throw(IllegalModelException);
});
});

it('should throw if ast contains illegal Map Key Property - Boolean', () => {
it('should throw if ast contains illegal Map Key Type - Boolean', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand All @@ -323,7 +338,7 @@ describe('MapDeclaration', () => {
}).should.throw(IllegalModelException);
});

it('should throw if ast contains illegal Map Key Property - Integer', () => {
it('should throw if ast contains illegal Map Key Type - Integer', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand All @@ -338,7 +353,7 @@ describe('MapDeclaration', () => {
}).should.throw(IllegalModelException);
});

it('should throw if ast contains illegal Map Key Property - Long', () => {
it('should throw if ast contains illegal Map Key Type - Long', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand All @@ -353,7 +368,7 @@ describe('MapDeclaration', () => {
}).should.throw(IllegalModelException);
});

it('should throw if ast contains illegal Map Key Property - Double', () => {
it('should throw if ast contains illegal Map Key Type - Double', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand All @@ -368,7 +383,7 @@ describe('MapDeclaration', () => {
}).should.throw(IllegalModelException);
});

it('should throw if ast contains illegal Map Key Property - Enum', () => {
it('should throw if ast contains illegal Map Key Type - Enum', () => {
(() => {
new MapDeclaration(modelFile, {
$class: '[email protected]',
Expand All @@ -386,6 +401,15 @@ describe('MapDeclaration', () => {
});
}).should.throw(IllegalModelException);
});

it('should throw when map key is imported and is an illegal Map Key Type', () => {
(() => {
const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8');
introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto');
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.imported.thing.cto', MapDeclaration);
decl.validate().should.throw(IllegalModelException);
});
});
});

describe('#validate failure scenarios - Map Value', () => {
Expand Down Expand Up @@ -489,7 +513,7 @@ describe('MapDeclaration', () => {
});

describe('#getKey', () => {
it('should return the map key property', () => {
it('should return the Map Key Type', () => {
let clz = new MapDeclaration(modelFile, {
$class: '[email protected]',
name: 'MapPermutation1',
Expand Down

0 comments on commit 72baa6b

Please sign in to comment.