forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
composer-common/lib/introspect unit tests (hyperledger-archives#1507)
* Added assetdeclaration unit test * composer-common/lib/introspect unit tests
- Loading branch information
Liam Grace
authored
Jul 7, 2017
1 parent
f993330
commit c5fdad2
Showing
18 changed files
with
408 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/composer-common/test/data/parser/assetdeclaration.systypename.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace com.testing | ||
|
||
asset Asset identified by id { | ||
o String id | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/composer-common/test/data/parser/classdeclaration.isrelationshiptarget.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace com.testing | ||
concept Test { | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/composer-common/test/data/parser/classdeclaration.noidentifier.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace com.testing | ||
|
||
transaction Transaction { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/composer-common/test/data/parser/eventdeclaration.systypename.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace com.testing | ||
|
||
event Event identified by eventId{ | ||
o String eventId | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/composer-common/test/data/parser/participantdeclaration.systypename.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace com.testing | ||
|
||
participant Participant identified by participantId { | ||
o String participantId | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/composer-common/test/data/parser/participantdeclaration.valid.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace com.testing | ||
|
||
participant P identified by pId { | ||
o String pId | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/composer-common/test/data/parser/relationshipdeclaration.missingtype.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace com.testing | ||
|
||
asset A identified by AId { | ||
o String AId | ||
--> Testing test | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/composer-common/test/introspect/participantdeclaration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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 ParticipantDeclaration = require('../../lib/introspect/participantdeclaration'); | ||
const ClassDeclaration = require('../../lib/introspect/classdeclaration'); | ||
const ModelFile = require('../../lib/introspect/modelfile'); | ||
const ModelManager = require('../../lib/modelmanager'); | ||
const fs = require('fs'); | ||
|
||
require('chai').should(); | ||
const sinon = require('sinon'); | ||
|
||
describe('ParticipantDeclaration', () => { | ||
|
||
let mockModelManager; | ||
let mockClassDeclaration; | ||
let mockSystemParticipant; | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
mockModelManager = sinon.createStubInstance(ModelManager); | ||
mockSystemParticipant = sinon.createStubInstance(ParticipantDeclaration); | ||
mockSystemParticipant.getFullyQualifiedName.returns('org.hyperledger.composer.system.Participant'); | ||
mockModelManager.getSystemTypes.returns([mockSystemParticipant]); | ||
mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); | ||
mockModelManager.getType.returns(mockClassDeclaration); | ||
mockClassDeclaration.getProperties.returns([]); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
let loadParticipantDeclaration = (modelFileName) => { | ||
let modelDefinitions = fs.readFileSync(modelFileName, 'utf8'); | ||
let modelFile = new ModelFile(mockModelManager, modelDefinitions); | ||
let assets = modelFile.getParticipantDeclarations(); | ||
assets.should.have.lengthOf(1); | ||
|
||
return assets[0]; | ||
}; | ||
|
||
describe('#constructor', () => { | ||
|
||
it('should throw if modelFile not specified', () => { | ||
(() => { | ||
new ParticipantDeclaration(null, {}); | ||
}).should.throw(/required/); | ||
}); | ||
|
||
it('should throw if ast not specified', () => { | ||
let mockModelFile = sinon.createStubInstance(ModelFile); | ||
(() => { | ||
new ParticipantDeclaration(mockModelFile, null); | ||
}).should.throw(/required/); | ||
}); | ||
|
||
}); | ||
|
||
describe('#isRelationshipTarget', () => { | ||
it('should return true', () => { | ||
let p = loadParticipantDeclaration('test/data/parser/participantdeclaration.valid.cto'); | ||
p.isRelationshipTarget().should.be.true; | ||
}); | ||
}); | ||
|
||
describe('#getSystemType', () => { | ||
it('should return Participant', () => { | ||
let p = loadParticipantDeclaration('test/data/parser/participantdeclaration.valid.cto'); | ||
p.getSystemType().should.equal('Participant'); | ||
}); | ||
}); | ||
|
||
describe('#validate', () => { | ||
it('should throw error if system type and name Participant', () => { | ||
let p = loadParticipantDeclaration('test/data/parser/participantdeclaration.systypename.cto'); | ||
(() => { | ||
p.validate(); | ||
}).should.throw(/Participant is a reserved type name./); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.