代码之家  ›  专栏  ›  技术社区  ›  James Swafford

过滤器:[?]无法应用于处理Spring Cloud Contract DSL的原语

  •  2
  • James Swafford  · 技术社区  · 8 年前

    我有一个Spring云合约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中做错了什么吗?车身的“有效载荷”部分表达是否正确?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Marcin Grzejszczak    8 年前

    有效载荷看起来有问题。。。注意,它将有效载荷视为 String Map