From b0c3123bb31266f72c3c855b71fae10523d9f7b3 Mon Sep 17 00:00:00 2001 From: Liam Grace Date: Wed, 19 Jul 2017 09:37:49 +0100 Subject: [PATCH 1/3] Remove System and Abstract types from playground summary --- .../app/editor/import/import.component.html | 24 ++++++++-------- .../editor/import/import.component.spec.ts | 28 +++++++++++++++++++ .../src/app/editor/import/import.component.ts | 19 ++++++++++++- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/packages/composer-playground/src/app/editor/import/import.component.html b/packages/composer-playground/src/app/editor/import/import.component.html index a767a38d38..2ba38edb08 100644 --- a/packages/composer-playground/src/app/editor/import/import.component.html +++ b/packages/composer-playground/src/app/editor/import/import.component.html @@ -23,9 +23,9 @@

Import/Replace Business Network

{{currentBusinessNetwork.getName()}}
- {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length}} Assets - {{currentBusinessNetwork.getModelManager().getParticipantDeclarations().length}} Participants - {{currentBusinessNetwork.getModelManager().getTransactionDeclarations().length}} Transactions + {{currentAssets.length}} Assets + {{currentParticipants.length}} Participants + {{currentTransactions.length}} Transactions
@@ -53,24 +53,24 @@

Import/Replace Business Network

-
+
Assets: {{asset.getName()}}{{i === 1 || lastOne ? '' : ', ' }} - + {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length -2}} more + *ngFor="let asset of currentAssets | slice:0:2; let i = index; let lastOne = last">{{asset.getName()}}{{i === 1 || lastOne ? '' : ', ' }} + + {{currentAssets.length -2}} more
-
Participants: {{participant.getName()}}{{i === 1 || lastOne ? '' : ', ' }} - + {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length -2}} more + *ngFor="let participant of currentParticipants | slice:0:2; let i = index; let lastOne = last">{{participant.getName()}}{{i === 1 || lastOne ? '' : ', ' }} + + {{currentParticipants.length -2}} more
-
+
Transactions: {{transaction.getName()}}{{i === 1 || lastOne ? '' : ', ' }} - + {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length -2}} more + *ngFor="let transaction of currentTransactions | slice:0:2; let i = index; let lastOne = last">{{transaction.getName()}}{{i === 1 || lastOne ? '' : ', ' }} + + {{currentTransactions.length -2}} more
diff --git a/packages/composer-playground/src/app/editor/import/import.component.spec.ts b/packages/composer-playground/src/app/editor/import/import.component.spec.ts index efe43c079b..d8287fe7d0 100644 --- a/packages/composer-playground/src/app/editor/import/import.component.spec.ts +++ b/packages/composer-playground/src/app/editor/import/import.component.spec.ts @@ -14,6 +14,7 @@ import { ClientService } from '../../services/client.service'; import { SampleBusinessNetworkService } from '../../services/samplebusinessnetwork.service'; import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { AlertService } from '../../basic-modals/alert.service'; +import { BusinessNetworkDefinition, ClassDeclaration } from 'composer-common'; import * as sinon from 'sinon'; import * as chai from 'chai'; @@ -130,6 +131,33 @@ describe('ImportComponent', () => { sandbox.restore(); }); + describe('currentBusinessNetwork', () => { + let mockBusinessNetworkDefinition; + let stub1 = sinon.createStubInstance(ClassDeclaration); + beforeEach(() => { + stub1.isAbstract.returns(true); + stub1.isSystemType.returns(false); + + mockBusinessNetworkDefinition = sinon.createStubInstance(BusinessNetworkDefinition); + mockBusinessNetworkDefinition.getModelManager.returns({ + getAssetDeclarations: () => { + return [stub1]; + }, + getParticipantDeclarations: () => { + return [stub1]; + }, + getTransactionDeclarations: () => { + return [stub1]; + } + }); + }); + + it('should set the correct values for _currentBusinessNetwork', () => { + component.currentBusinessNetwork = mockBusinessNetworkDefinition; + component['currentAssets'].should.deep.equal([stub1]); + }); + }); + describe('ngInit', () => { let onShowMock; diff --git a/packages/composer-playground/src/app/editor/import/import.component.ts b/packages/composer-playground/src/app/editor/import/import.component.ts index 45e24b1f7d..f65b892d1d 100644 --- a/packages/composer-playground/src/app/editor/import/import.component.ts +++ b/packages/composer-playground/src/app/editor/import/import.component.ts @@ -30,7 +30,24 @@ export class ImportComponent implements OnInit { private maxFileSize: number = 5242880; private supportedFileTypes: string[] = ['.bna']; - private currentBusinessNetwork = null; + private _currentBusinessNetwork = null; + + set currentBusinessNetwork(businessNetwork) { + this._currentBusinessNetwork = businessNetwork; + if (businessNetwork instanceof BusinessNetworkDefinition) { + this.currentAssets = businessNetwork.getModelManager().getAssetDeclarations().filter((d) => !d.isAbstract() && !d.isSystemType()); + this.currentParticipants = businessNetwork.getModelManager().getParticipantDeclarations().filter((d) => !d.isAbstract() && !d.isSystemType()); + this.currentTransactions = businessNetwork.getModelManager().getTransactionDeclarations().filter((d) => !d.isAbstract() && !d.isSystemType()); + } + } + + get currentBusinessNetwork() { + return this._currentBusinessNetwork; + } + + private currentAssets = []; + private currentParticipants = []; + private currentTransactions = []; private NAME = 'Empty Business Network'; private DESC = 'Start from scratch with a blank business network'; From 982766d41b57cca07df7343e7afa6ca390fd6540 Mon Sep 17 00:00:00 2001 From: Liam Grace Date: Wed, 19 Jul 2017 09:38:31 +0100 Subject: [PATCH 2/3] Remove composer-cli version check from rest server --- packages/composer-rest-server/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/composer-rest-server/cli.js b/packages/composer-rest-server/cli.js index 77260b92e2..6f3f3e222f 100755 --- a/packages/composer-rest-server/cli.js +++ b/packages/composer-rest-server/cli.js @@ -36,7 +36,7 @@ const yargs = require('yargs') .option('S', { alias: 'security', describe: 'Enable security for the REST API', type: 'boolean', default: process.env.COMPOSER_SECURITY || false }) .alias('v', 'version') .version(() => { - return getInfo('composer-rest-server')+getInfo('composer-cli')+ + return getInfo('composer-rest-server')+ getInfo('composer-admin')+getInfo('composer-client')+ getInfo('composer-common')+getInfo('composer-runtime-hlf')+ getInfo('composer-connector-hlf')+getInfo('composer-runtime-hlfv1')+ From a527759a4016e24fdf7d0f1d401b290dc7dc7250 Mon Sep 17 00:00:00 2001 From: Liam Grace Date: Wed, 19 Jul 2017 09:38:44 +0100 Subject: [PATCH 3/3] Bump common test coverage --- .../composer-common/test/data/model/enum.cto | 12 +++ .../test/introspect/classdeclaration.js | 20 +++++ .../test/introspect/enumdeclaration.js | 78 +++++++++++++++++++ .../editor/import/import.component.spec.ts | 4 +- 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 packages/composer-common/test/data/model/enum.cto create mode 100644 packages/composer-common/test/introspect/enumdeclaration.js diff --git a/packages/composer-common/test/data/model/enum.cto b/packages/composer-common/test/data/model/enum.cto new file mode 100644 index 0000000000..7cab885623 --- /dev/null +++ b/packages/composer-common/test/data/model/enum.cto @@ -0,0 +1,12 @@ +/* + * Test file for enums + */ +namespace org.acme + + +/** + * Concrete enum + */ +enum ConcreteEnum { + o TEST +} diff --git a/packages/composer-common/test/introspect/classdeclaration.js b/packages/composer-common/test/introspect/classdeclaration.js index 69e2f102a3..8a83f3e808 100644 --- a/packages/composer-common/test/introspect/classdeclaration.js +++ b/packages/composer-common/test/introspect/classdeclaration.js @@ -351,10 +351,30 @@ describe('ClassDeclaration', () => { const modelFiles = loadModelFiles(modelFileNames, modelManager); modelManager.addModelFiles(modelFiles); }); + it('should return false', () => { const testClass = modelManager.getType('com.testing.Test'); testClass.isRelationshipTarget().should.be.false; }); }); + + describe('#isSystemRelationshipTarget', () => { + const modelFileNames = [ + 'test/data/parser/classdeclaration.isrelationshiptarget.cto', + ]; + let modelManager; + + beforeEach(() => { + modelManager = new ModelManager(); + const modelFiles = loadModelFiles(modelFileNames, modelManager); + modelManager.addModelFiles(modelFiles); + }); + + it('should return false', () => { + const testClass = modelManager.getType('com.testing.Test'); + testClass.isSystemRelationshipTarget().should.be.false; + + }); + }); }); diff --git a/packages/composer-common/test/introspect/enumdeclaration.js b/packages/composer-common/test/introspect/enumdeclaration.js new file mode 100644 index 0000000000..53d49bfe51 --- /dev/null +++ b/packages/composer-common/test/introspect/enumdeclaration.js @@ -0,0 +1,78 @@ +/* + * 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. + */ + +'use strict'; + +const EnumDeclaration = require('../../lib/introspect/enumdeclaration'); +const EventDeclaration = require('../../lib/introspect/eventdeclaration'); +const ModelFile = require('../../lib/introspect/modelfile'); +const ModelManager = require('../../lib/modelmanager'); +const fs = require('fs'); + +require('chai').should(); +const sinon = require('sinon'); + +describe('EnumDeclaration', () => { + + let mockModelManager; + + /** + * Load an arbitrary number of model files. + * @param {String[]} modelFileNames array of model file names. + * @param {ModelManager} modelManager the model manager to which the created model files will be registered. + * @return {ModelFile[]} array of loaded model files, matching the supplied arguments. + */ + const loadModelFiles = (modelFileNames, modelManager) => { + const modelFiles = []; + for (let modelFileName of modelFileNames) { + const modelDefinitions = fs.readFileSync(modelFileName, 'utf8'); + const modelFile = new ModelFile(modelManager, modelDefinitions); + modelFiles.push(modelFile); + } + modelManager.addModelFiles(modelFiles, modelFileNames); + return modelFiles; + }; + + const loadModelFile = (modelFileName) => { + return loadModelFiles([modelFileName], mockModelManager)[0]; + }; + + const loadLastDeclaration = (modelFileName, type) => { + const modelFile = loadModelFile(modelFileName); + const declarations = modelFile.getDeclarations(type); + return declarations[declarations.length - 1]; + }; + + let sandbox; + let mockSystemEvent; + + beforeEach(() => { + sandbox = sinon.sandbox.create(); + mockModelManager = sinon.createStubInstance(ModelManager); + mockSystemEvent = sinon.createStubInstance(EventDeclaration); + mockSystemEvent.getFullyQualifiedName.returns('org.hyperledger.composer.system.Event'); + mockModelManager.getSystemTypes.returns([mockSystemEvent]); + }); + + afterEach(() => { + sandbox.restore(); + }); + + describe('#toString', () => { + it('should give the correct value', () => { + let declaration = loadLastDeclaration('test/data/model/enum.cto', EnumDeclaration); + declaration.toString().should.equal('EnumDeclaration {id=org.acme.ConcreteEnum}'); + }); + }); +}); diff --git a/packages/composer-playground/src/app/editor/import/import.component.spec.ts b/packages/composer-playground/src/app/editor/import/import.component.spec.ts index d8287fe7d0..c56aef3f5e 100644 --- a/packages/composer-playground/src/app/editor/import/import.component.spec.ts +++ b/packages/composer-playground/src/app/editor/import/import.component.spec.ts @@ -153,8 +153,8 @@ describe('ImportComponent', () => { }); it('should set the correct values for _currentBusinessNetwork', () => { - component.currentBusinessNetwork = mockBusinessNetworkDefinition; - component['currentAssets'].should.deep.equal([stub1]); + component['currentBusinessNetwork'] = mockBusinessNetworkDefinition; + component['currentAssets'].should.deep.equal([]); }); });