使用 Cucumber 在 Hyperledger Composer 中测试概念类型
Testing a Concept type in Hypledger Composer with Cucumber
如果您有地址概念(如 here 所示),那么您将如何编写黄瓜功能来说明资产上所需的地址概念?我看到如何使用 factory.newConcept() 在 mocha.js 示例中做到这一点,但是是否可以使用黄瓜来完成它?
And I have added the following assets of type org.acme.Address
| addressId | street1 | city | state | zipcode |
| AddressA | 123 West 3rd | Anywhere | Texas | 12345 |
| AddressB | 123 West 3rd | Anywhere | Texas | 12345 |
And I have added the following assets of type org.acme.Delivery
| loadId | start | end |
| 1 | AddressA | AddressB |
| 2 | AddressA | AddressB |
模型定义:
concept Address {
o String street1
o String street2 optional
o String city
o String state
o String zipcode
o Double latitude optional
o Double longitude optional
}
asset Delivery identified by loadId {
o String loadId
o Address start
o Address end
}
我曾尝试在起始列中传递参数的哈希值,但没有成功并收到错误
ValidationException: Model violation in instance org.acme.Delivery#1
class org.acme.Address has value addressConcept expected a Resource or
a Concept.
使用 Cucumber 测试复杂数据时,需要使用 JSON 而不是数据 table 格式。这里有一个例子:
Scenario: given I have added the following asset
Given I have added the following asset
"""
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"}
"""
Then I should have the following asset
"""
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"}
"""
无论您在何处看到数据 table,您都应该能够提供 JSON——包括数组:
Scenario: given I have added the following assets
Given I have added the following assets
"""
[
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"},
{"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"bob@email.com", "value":"20"}
]
"""
Then I should have the following assets
"""
[
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"},
{"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"bob@email.com", "value":"20"}
]
"""
Simon 的回答很好,但实际上并没有回答所问的问题(尽管它以一种迂回的方式回答)。
如果可以的话,我想尝试一下(我假设 org.acme
是命名空间):
你需要的小黄瓜是这样的:
Scenario: given I have added the following asset
Given I have added the following asset
"""
{"$class":"org.acme.Delivery", "loadId":"1", "start":{"$class":"org.acme.Address", "addressId":"AddressA", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}, "end":{"$class":"org.acme.Address", "addressId":"AddressB", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}}
"""
Then I have added the following asset
"""
{"$class":"org.acme.Delivery", "loadId":"1", "start":{"$class":"org.acme.Address", "addressId":"AddressA", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}, "end":{"$class":"org.acme.Address", "addressId":"AddressB", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}}
"""
请注意使用标准 JSON 嵌套语法的 nested 地址对象。
同样,我认为 Simon 的回答很好,但如果您不是 JSON 专家,将他的回答(针对完全不同的场景)扩展到被问到的问题可能具有挑战性。
除了开始地址和结束地址相同这一事实(并且 12345 在德克萨斯州不是有效的邮政编码)之外,这应该回答了所问的确切问题。
--jsp
如果您有地址概念(如 here 所示),那么您将如何编写黄瓜功能来说明资产上所需的地址概念?我看到如何使用 factory.newConcept() 在 mocha.js 示例中做到这一点,但是是否可以使用黄瓜来完成它?
And I have added the following assets of type org.acme.Address
| addressId | street1 | city | state | zipcode |
| AddressA | 123 West 3rd | Anywhere | Texas | 12345 |
| AddressB | 123 West 3rd | Anywhere | Texas | 12345 |
And I have added the following assets of type org.acme.Delivery
| loadId | start | end |
| 1 | AddressA | AddressB |
| 2 | AddressA | AddressB |
模型定义:
concept Address {
o String street1
o String street2 optional
o String city
o String state
o String zipcode
o Double latitude optional
o Double longitude optional
}
asset Delivery identified by loadId {
o String loadId
o Address start
o Address end
}
我曾尝试在起始列中传递参数的哈希值,但没有成功并收到错误
ValidationException: Model violation in instance org.acme.Delivery#1 class org.acme.Address has value addressConcept expected a Resource or a Concept.
使用 Cucumber 测试复杂数据时,需要使用 JSON 而不是数据 table 格式。这里有一个例子:
Scenario: given I have added the following asset
Given I have added the following asset
"""
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"}
"""
Then I should have the following asset
"""
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"}
"""
无论您在何处看到数据 table,您都应该能够提供 JSON——包括数组:
Scenario: given I have added the following assets
Given I have added the following assets
"""
[
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"},
{"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"bob@email.com", "value":"20"}
]
"""
Then I should have the following assets
"""
[
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"},
{"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"bob@email.com", "value":"20"}
]
"""
Simon 的回答很好,但实际上并没有回答所问的问题(尽管它以一种迂回的方式回答)。
如果可以的话,我想尝试一下(我假设 org.acme
是命名空间):
你需要的小黄瓜是这样的:
Scenario: given I have added the following asset
Given I have added the following asset
"""
{"$class":"org.acme.Delivery", "loadId":"1", "start":{"$class":"org.acme.Address", "addressId":"AddressA", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}, "end":{"$class":"org.acme.Address", "addressId":"AddressB", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}}
"""
Then I have added the following asset
"""
{"$class":"org.acme.Delivery", "loadId":"1", "start":{"$class":"org.acme.Address", "addressId":"AddressA", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}, "end":{"$class":"org.acme.Address", "addressId":"AddressB", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}}
"""
请注意使用标准 JSON 嵌套语法的 nested 地址对象。
同样,我认为 Simon 的回答很好,但如果您不是 JSON 专家,将他的回答(针对完全不同的场景)扩展到被问到的问题可能具有挑战性。
除了开始地址和结束地址相同这一事实(并且 12345 在德克萨斯州不是有效的邮政编码)之外,这应该回答了所问的确切问题。
--jsp