diff --git a/packages/composer-tests-integration/scripts/run-integration-tests.sh b/packages/composer-tests-integration/scripts/run-integration-tests.sh index dd5cb688b6..243f733dba 100755 --- a/packages/composer-tests-integration/scripts/run-integration-tests.sh +++ b/packages/composer-tests-integration/scripts/run-integration-tests.sh @@ -52,6 +52,7 @@ rm -rf ./my-bus-net # a business network created from generator rm -rf ./tutorial-network # business network created from generator in dev tut rm -f ./networkadmin.card rm -f ./composer-report-* +rm -rf ./my-angular-app rm -rf ./my-loopback-app # remove anything already there @@ -217,6 +218,7 @@ for INTEST in $(echo ${INTEST} | tr "," " "); do rm -rf ${HOME}/.npmrc rm -f ./networkadmin.card rm -f ./composer-report-* + rm -rf ./my-angular-app rm -rf ./my-loopback-app if [ "${DOCKER_FILE}" != "" ]; then cd ../composer-runtime-hlfv1 diff --git a/packages/generator-hyperledger-composer/generators/loopback/index.js b/packages/generator-hyperledger-composer/generators/loopback/index.js index 11f7f1ffd3..948da88876 100644 --- a/packages/generator-hyperledger-composer/generators/loopback/index.js +++ b/packages/generator-hyperledger-composer/generators/loopback/index.js @@ -22,8 +22,19 @@ const optionOrPrompt = require('yeoman-option-or-prompt'); const Util = require('../util'); const version = require('../../package.json').version; const yeoman = require('yeoman-generator'); + +let businessNetworkConnectionOptions = undefined; + module.exports = class extends yeoman.Base { + /** + * Set the business network connection options. + * @param {*} options The business network connection options. + */ + static setBusinessNetworkConnectionOptions(options) { + businessNetworkConnectionOptions = options; + } + /** * Constructor. */ @@ -158,7 +169,7 @@ module.exports = class extends yeoman.Base { // Get the business network definition. if (this.liveNetwork) { - const businessNetworkConnection = new BusinessNetworkConnection(); + const businessNetworkConnection = new BusinessNetworkConnection(businessNetworkConnectionOptions); this.businessNetworkDefinition = await businessNetworkConnection.connect(this.cardName); await businessNetworkConnection.disconnect(); } else { @@ -174,7 +185,8 @@ module.exports = class extends yeoman.Base { const classDeclarations = introspector.getClassDeclarations().filter((classDeclaration) => { return !classDeclaration.isAbstract() && !classDeclaration.isSystemType() && - !classDeclaration.isEvent(); + !classDeclaration.isEvent() && + !classDeclaration.isEnum(); }); // Copy the skeleton project into place. diff --git a/packages/generator-hyperledger-composer/test/data/carAuction.bna b/packages/generator-hyperledger-composer/test/data/carAuction.bna index 5ea89f64a5..0cfaf997be 100644 Binary files a/packages/generator-hyperledger-composer/test/data/carAuction.bna and b/packages/generator-hyperledger-composer/test/data/carAuction.bna differ diff --git a/packages/generator-hyperledger-composer/test/loopback.js b/packages/generator-hyperledger-composer/test/loopback.js index d01db4e4a5..4303b75068 100644 --- a/packages/generator-hyperledger-composer/test/loopback.js +++ b/packages/generator-hyperledger-composer/test/loopback.js @@ -17,7 +17,8 @@ const { AdminConnection } = require('composer-admin'); const assert = require('yeoman-assert'); const fs = require('fs'); -const { BusinessNetworkDefinition, IdCard } = require('composer-common'); +const { BusinessNetworkDefinition, IdCard, NetworkCardStoreManager } = require('composer-common'); +const generator = require('../generators/loopback'); const helpers = require('yeoman-test'); const path = require('path'); const rewire = require('rewire'); @@ -60,6 +61,7 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', before(async () => { if (liveNetwork) { + const cardStore = NetworkCardStoreManager.getCardStore({ type: 'composer-wallet-inmemory' }); const blockchainNetworkCard = new IdCard({ userName : 'admin', enrollmentSecret : 'adminpw' @@ -67,10 +69,10 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', 'x-type' : 'embedded', name : 'generatorProfile' }); - const adminConnection = new AdminConnection({ wallet: { type: 'composer-wallet-inmemory' }}); + const adminConnection = new AdminConnection({ cardStore }); await adminConnection.importCard('admin@blockchain-network', blockchainNetworkCard); await adminConnection.connect('admin@blockchain-network'); - const businessNetworkArchive = fs.readFileSync(path.resolve(__dirname + '/data/', 'digitalPropertyNetwork.bna')); + const businessNetworkArchive = fs.readFileSync(path.resolve(__dirname + '/data/', 'carAuction.bna')); const businessNetworkDefinition = await BusinessNetworkDefinition.fromArchive(businessNetworkArchive); await adminConnection.install(businessNetworkDefinition); await adminConnection.start(businessNetworkDefinition.getName(), businessNetworkDefinition.getVersion(), { @@ -79,19 +81,29 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', enrollmentSecret : 'adminpw' }] }); + const businessNetworkCard = new IdCard({ + userName : 'admin', + enrollmentSecret: 'adminpw', + businessNetwork : 'carauction-network' + }, { + 'x-type' : 'embedded', + name : 'generatorProfile' + }); + await adminConnection.importCard('admin@carauction-network', businessNetworkCard); + generator.setBusinessNetworkConnectionOptions({ cardStore }); } }); before(() => { const prompts = { liveNetwork, - appName: 'digitalPropertyNetwork', - appDescription: 'A digitalPropertyNetwork application', + appName: 'loopback-carauction', + appDescription: 'A LoopBack application for car auctions', authorName: 'TestUser', authorEmail: 'TestUser@TestApp.com', license: 'Apache-2.0', - fileName: (path.join(__dirname, '/data/digitalPropertyNetwork.bna')), - cardName: 'admin@digitalproperty-network' + fileName: (path.join(__dirname, '/data/carAuction.bna')), + cardName: 'admin@carauction-network' }; if (liveNetwork) { delete prompts.fileName; @@ -99,7 +111,7 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', return helpers.run(path.resolve(__dirname, '../generators/loopback')) .inTmpDir((dir) => { tmpDir = dir; - appDir = path.join(tmpDir, 'digitalPropertyNetwork'); + appDir = path.join(tmpDir, 'loopback-carauction'); }) .withOptions({ skipInstall: true }) .withPrompts(prompts) @@ -165,14 +177,18 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', return builtInModelFiles.indexOf(fileName) === -1; }); fileNames.should.deep.equal([ - 'LandTitle.js', - 'LandTitle.json', - 'Person.js', - 'Person.json', - 'RegisterPropertyForSale.js', - 'RegisterPropertyForSale.json', - 'SalesAgreement.js', - 'SalesAgreement.json', + 'Auctioneer.js', + 'Auctioneer.json', + 'CloseBidding.js', + 'CloseBidding.json', + 'Member.js', + 'Member.json', + 'Offer.js', + 'Offer.json', + 'Vehicle.js', + 'Vehicle.json', + 'VehicleListing.js', + 'VehicleListing.json' ]); files.forEach((file) => { if (file.endsWith('.js')) { @@ -187,7 +203,7 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', sinon.assert.calledWith(mockComposer.restrictModelMethods, mockModel); } else { const modelJSON = require(file); - modelJSON.options.composer.namespace.should.equal('net.biz.digitalPropertyNetwork'); + modelJSON.options.composer.namespace.should.equal('org.acme.vehicle.auction'); } }); }); @@ -215,7 +231,7 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', const datasources = require(file); datasources.should.deep.equal({ composer: { - card: 'admin@digitalproperty-network', + card: 'admin@carauction-network', connector: 'loopback-connector-composer', name: 'composer', namespaces: false @@ -250,19 +266,27 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', dataSource: 'composer', public: false }, - LandTitle: { + Auctioneer: { + dataSource: 'composer', + public: true + }, + CloseBidding: { + dataSource: 'composer', + public: true + }, + Member: { dataSource: 'composer', public: true }, - SalesAgreement: { + Offer: { dataSource: 'composer', public: true }, - Person: { + Vehicle: { dataSource: 'composer', public: true }, - RegisterPropertyForSale: { + VehicleListing: { dataSource: 'composer', public: true } @@ -273,9 +297,9 @@ describe('hyperledger-composer:loopback for generating a LoopBack application', const file = path.join(appDir, 'package.json'); assert.file(file); const packageJSON = require(file); - packageJSON.name.should.equal('digitalPropertyNetwork'); + packageJSON.name.should.equal('loopback-carauction'); packageJSON.version.should.equal('1.0.0'); - packageJSON.description.should.equal('A digitalPropertyNetwork application'); + packageJSON.description.should.equal('A LoopBack application for car auctions'); packageJSON.license.should.equal('Apache-2.0'); packageJSON.author.should.equal('TestUser '); packageJSON.engines.should.deep.equal({