2

我有一个如下所示的 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 中做错了吗?身体的“有效载荷”部分是否正确表达?

4

1 回答 1

1

有效负载看起来不对...请注意,它正在将有效负载视为一个String值而不是一个Map. 我想将有效负载更改为正确的就足够了,事情应该会再次起作用!

于 2017-09-25T18:06:15.743 回答