Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions packages/composer-common/lib/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ class ClassDeclaration {
*
* @return {boolean} true if the class may be pointed to by a relationship
*/
isSystemRelationshipTarget() {
return this.isRelationshipTarget();
}

/**
* Returns true if this class is a system type
*
* @return {boolean} true if the class is part of the system namespace
*/
isSystemType() {
return ModelUtil.getSystemNamespace() === this.modelFile.getNamespace();
}
Expand Down
20 changes: 17 additions & 3 deletions packages/composer-common/test/businessnetworkdefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ describe('BusinessNetworkDefinition', () => {
businessNetwork.aclManager.getAclRules().should.have.length(4);
businessNetwork.queryManager.getQueries().should.have.length(6);
const intro = businessNetwork.getIntrospector();
intro.getClassDeclarations().length.should.equal(29);
// remove system types and make sure the 25 model types are presents
let classDecl = intro.getClassDeclarations().filter( (element) => {
return !element.isSystemType();
});
classDecl.length.should.equal(25);
const sm = businessNetwork.getScriptManager();
sm.getScripts().length.should.equal(2);
});
Expand All @@ -126,7 +130,13 @@ describe('BusinessNetworkDefinition', () => {
Object.keys(businessNetwork.scriptManager.scripts).should.have.length(2);

const intro = businessNetwork.getIntrospector();
intro.getClassDeclarations().length.should.equal(29);

// remove system types and make sure the 25 model types are presents
let classDecl = intro.getClassDeclarations().filter( (element) => {
return !element.isSystemType();
});

classDecl.length.should.equal(25);
const sm = businessNetwork.getScriptManager();
sm.getScripts().length.should.equal(2);
});
Expand All @@ -153,7 +163,11 @@ describe('BusinessNetworkDefinition', () => {
Object.keys(businessNetwork.scriptManager.scripts).should.have.length(2);

const intro = businessNetwork.getIntrospector();
intro.getClassDeclarations().length.should.equal(17);
// remove system types and make sure the 25 model types are presents
let classDecl = intro.getClassDeclarations().filter( (element) => {
return !element.isSystemType();
});
classDecl.length.should.equal(13);
businessNetwork.getModelManager().getModelFiles().length.should.equal(3);
const sm = businessNetwork.getScriptManager();
sm.getScripts().length.should.equal(2);
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-common/test/codegen/jsonschemavisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('JSONSchemaVisitor', () => {
'org.acme.base.MyTransactionEx.json',
'org.acme.base.UnitedStatesAddress.json'
];
sinon.assert.callCount(mockFileWriter.openFile, expectedFiles.length);

let jsonSchemas = {};

expectedFiles.forEach((expectedFile) => {
Expand Down
1 change: 0 additions & 1 deletion packages/composer-common/test/codegen/loopbackvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ describe('LoopbackVisitor', () => {
];
}
schemas.should.have.lengthOf(expectedFiles.length);
sinon.assert.callCount(mockFileWriter.openFile, expectedFiles.length);

expectedFiles.forEach((expectedFile) => {
sinon.assert.calledWith(mockFileWriter.openFile, expectedFile);
Expand Down
6 changes: 5 additions & 1 deletion packages/composer-common/test/introspect/introspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const fs = require('fs');
const chai = require('chai');
chai.use(require('chai-things'));
const sinon = require('sinon');
require('chai').should();

describe('Introspector', () => {

Expand Down Expand Up @@ -51,7 +52,10 @@ describe('Introspector', () => {

modelManager.addModelFile(modelBase, 'model-base.cto');
const introspector = new Introspector(modelManager);
introspector.getClassDeclarations().length.should.equal(17);
let classDecl = introspector.getClassDeclarations().filter( (element) => {
return !element.isSystemType();
});
classDecl.length.should.equal(13);
});
});

Expand Down
11 changes: 9 additions & 2 deletions packages/composer-common/test/models/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const Factory = require('../../lib/factory');
const ModelManager = require('../../lib/modelmanager');
const ModelUtil = require('../../lib/modelutil');
const RelationshipDeclaration = require('../../lib/introspect/relationshipdeclaration');
const Serializer = require('../../lib/serializer');
const TypeNotFoundException = require('../../lib/typenotfoundexception');
Expand Down Expand Up @@ -326,7 +327,10 @@ describe('Test Model', function(){
let modelFile = modelManager.getModelFile('org.acme');
modelFile.isLocalType('MyParticipant').should.equal(false);
modelFile.isImportedType('MyParticipant').should.equal(true);
modelFile.getImports().length.should.equal(5);
let imprts = modelFile.getImports().filter( (element) => {
return !element.startsWith(ModelUtil.getSystemNamespace());
});
imprts.length.should.equal(1);
modelFile.getImports().includes('concerto.MyParticipant').should.equal(true);
});
});
Expand Down Expand Up @@ -360,7 +364,10 @@ describe('Test Model', function(){
let modelFile = modelManager.getModelFile('stdlib.business');
modelFile.isLocalType('Business').should.equal(true);
modelFile.isImportedType('Person').should.equal(true);
modelFile.getImports().length.should.equal(6);
let imprts = modelFile.getImports().filter( (element) => {
return !element.startsWith(ModelUtil.getSystemNamespace());
});
imprts.length.should.equal(2);
});
});
});