2017-07-14 66 views
0

如果您有地址概念(如演示here),那麼如何編寫黃瓜功能來解釋資產上的所需地址概念?我看到如何使用factory.newConcept()的mocha.js示例來做到這一點,但是可以使用黃瓜來實現這一點嗎?使用黃瓜在Hypledger Composer中測試概念類型

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:型號違反實例org.acme.Delivery#1 class org.acme.Address具有值的addressConcept期望資源或 概念。

回答

2

使用Cucumber測試複雜數據時,您需要使用JSON而不是數據表格式。這裏有一個例子:

https://github.com/hyperledger/composer/blob/master/packages/composer-cucumber-steps/features/assets.feature#L14

Scenario: given I have added the following asset 
    Given I have added the following asset 
     """ 
     {"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"[email protected]", "value":"10"} 
     """ 
    Then I should have the following asset 
     """ 
     {"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"[email protected]", "value":"10"} 
     """ 

只要你看到一個數據表,你應該能夠提供JSON代替 - 包括數組:

https://github.com/hyperledger/composer/blob/master/packages/composer-cucumber-steps/features/assets.feature#L34

Scenario: given I have added the following assets 
    Given I have added the following assets 
     """ 
     [ 
      {"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"[email protected]", "value":"10"}, 
      {"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"[email protected]", "value":"20"} 
     ] 
     """ 
    Then I should have the following assets 
     """ 
     [ 
      {"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"[email protected]", "value":"10"}, 
      {"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"[email protected]", "value":"20"} 
     ] 
     """ 
+0

謝謝西蒙。你是非常有幫助和豐富的知識! – jgraft

0

西蒙的回答是好的,但實際上並沒有回答被問到的問題(儘管它在某種程度上是這樣做的)。

如果我可以,我想帶刺(我假設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嵌套語法的地址對象。

同樣,我認爲Simon的回答很好,但如果你不是JSON專家,那麼將他的答案(完全不同的場景)延伸到被問到的問題可能會有挑戰性。

除了開始和結束地址相同(並且12345在德克薩斯州不是有效的郵政編碼)這一事實之外,這應該回答所問的確切問題。

--jsp