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
12 changes: 12 additions & 0 deletions packages/composer-common/test/data/model/enum.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Test file for enums
*/
namespace org.acme


/**
* Concrete enum
*/
enum ConcreteEnum {
o TEST
}
20 changes: 20 additions & 0 deletions packages/composer-common/test/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

});
});
});
78 changes: 78 additions & 0 deletions packages/composer-common/test/introspect/enumdeclaration.js
Original file line number Diff line number Diff line change
@@ -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}');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ <h1>Import/Replace Business Network</h1>
<div class="file-title">
<div class="title">{{currentBusinessNetwork.getName()}}</div>
<div>
<span>{{currentBusinessNetwork.getModelManager().getAssetDeclarations().length}} Assets</span>
<span>{{currentBusinessNetwork.getModelManager().getParticipantDeclarations().length}} Participants</span>
<span>{{currentBusinessNetwork.getModelManager().getTransactionDeclarations().length}} Transactions</span>
<span>{{currentAssets.length}} Assets</span>
<span>{{currentParticipants.length}} Participants</span>
<span>{{currentTransactions.length}} Transactions</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -53,24 +53,24 @@ <h1>Import/Replace Business Network</h1>
</ul>
</div>
<div>
<div *ngIf="currentBusinessNetwork.getModelManager().getAssetDeclarations().length > 0" class="network-part">
<div *ngIf="currentAssets.length > 0" class="network-part">
<span class="title">Assets:</span>
<span
*ngFor="let asset of currentBusinessNetwork.getModelManager().getAssetDeclarations() | slice:0:2; let i = index; let lastOne = last">{{asset.getName()}}{{i === 1 || lastOne ? '' : ', ' }}</span>
<span *ngIf="currentBusinessNetwork.getModelManager().getAssetDeclarations().length > 2">+ {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length -2}} more</span>
*ngFor="let asset of currentAssets | slice:0:2; let i = index; let lastOne = last">{{asset.getName()}}{{i === 1 || lastOne ? '' : ', ' }}</span>
<span *ngIf="currentAssets.length > 2">+ {{currentAssets.length -2}} more</span>
</div>
<div *ngIf="currentBusinessNetwork.getModelManager().getParticipantDeclarations().length > 0"
<div *ngIf="currentParticipants.length > 0"
class="network-part">
<span class="title">Participants:</span>
<span
*ngFor="let participant of currentBusinessNetwork.getModelManager().getParticipantDeclarations() | slice:0:2; let i = index; let lastOne = last">{{participant.getName()}}{{i === 1 || lastOne ? '' : ', ' }}</span>
<span *ngIf="currentBusinessNetwork.getModelManager().getParticipantDeclarations().length > 2">+ {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length -2}} more</span>
*ngFor="let participant of currentParticipants | slice:0:2; let i = index; let lastOne = last">{{participant.getName()}}{{i === 1 || lastOne ? '' : ', ' }}</span>
<span *ngIf="currentParticipants.length > 2">+ {{currentParticipants.length -2}} more</span>
</div>
<div *ngIf="currentBusinessNetwork.getModelManager().getParticipantDeclarations() >0" class="network-part">
<div *ngIf="currentParticipants >0" class="network-part">
<span class="title">Transactions:</span>
<span
*ngFor="let transaction of currentBusinessNetwork.getModelManager().getParticipantDeclarations() | slice:0:2; let i = index; let lastOne = last">{{transaction.getName()}}{{i === 1 || lastOne ? '' : ', ' }}</span>
<span *ngIf="currentBusinessNetwork.getModelManager().getParticipantDeclarations().length > 2">+ {{currentBusinessNetwork.getModelManager().getAssetDeclarations().length -2}} more</span>
*ngFor="let transaction of currentTransactions | slice:0:2; let i = index; let lastOne = last">{{transaction.getName()}}{{i === 1 || lastOne ? '' : ', ' }}</span>
<span *ngIf="currentTransactions.length > 2">+ {{currentTransactions.length -2}} more</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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([]);
});
});

describe('ngInit', () => {
let onShowMock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-rest-server/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')+
Expand Down