我有一个Spring Cloud Contract DSL,如下所示:
package contracts.someconsumer.messaging
import org.springframework.cloud.contract.spec.Contract
Contract.make {
label 'my_label'
// input to the contract
input {
// the contract will be triggered by a method
triggeredBy('someMethodThatSendsMessage()')
}
// output message of the contract
outputMessage {
// destination to which the output message will be sent
sentTo 'Consumer.contractTest.VirtualTopic.some_destination'
// the body of the output message
body([
id: value(consumer('11111111-2222-3333-4444-555555555555'),producer(regex(uuid()))),
correlationId: value(producer(regex(uuid()))),
service: 'MY_SERVICE',
payload:
[
email: 'test@example.com'
]
])
}
}
没有"有效载荷"部分一切都很棒。有效载荷,我遇到了这个例外:
com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to primitives. Current context is: {"email":"test@example.com","legalName":"ACME Inc"}
at com.jayway.jsonpath.internal.path.PredicatePathToken.evaluate(PredicatePathToken.java:66) ~[json-path-2.2.0.jar:2.2.0]
at com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:81) ~[json-path-2.2.0.jar:2.2.0]
at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:79) ~[json-path-2.2.0.jar:2.2.0]
at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62) ~[json-path-2.2.0.jar:2.2.0]
生成测试的相关行:
assertThatJson(parsedJson).field("['payload']").field("['email']").isEqualTo("test@example.com");
再多一点信息,这就是序列化消息的样子:
2017-09-21 08:32:03.721 INFO 10716 --- [ main] c.v.sccdemo.producer.InviteServiceImpl : Event: {"id":"e63de44e-6e1a-4c4e-b98b-3c49a49efc9c","destination":"VirtualTopic.some_destination","correlationId":"8efb9740-5651-4068-8a6e-574ae7759552","service":"MY_SERVICE","payload":"{\"email\":\"test@example.com\",\"legalName\":\"ACME Inc\"}","timestamp":1505997123576,"version":"v1"}
我在DSL上做错了吗?是'有效载荷'身体的一部分表达正确吗?
答案 0 :(得分:0)
有效负载看起来不对...请注意,它将有效负载视为Map
值而不是php artisan migrate:install
。我想这足以将有效载荷改为合适的载荷,事情应该再次发挥作用了!