diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy index cbcc62ccc3..6a541b1e2d 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/Input.groovy @@ -95,6 +95,10 @@ class Input extends Common { return new DslProperty(client.clientValue, clientValue) } + DslProperty $(ClientDslProperty client) { + return value(client) + } + @EqualsAndHashCode(includeFields = true, callSuper = true) @ToString(includeSuper = true) static class BodyType extends DslProperty { diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy index 29de6c206c..4e678390de 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/OutputMessage.groovy @@ -97,6 +97,10 @@ class OutputMessage extends Common { return new DslProperty(value, server.serverValue) } + DslProperty $(ServerDslProperty server) { + return value(server) + } + /** * @deprecated Deprecated in favor of bodyMatchers to support other future bodyMatchers too */ diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy new file mode 100644 index 0000000000..5c93855d1a --- /dev/null +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/InputSpec.groovy @@ -0,0 +1,20 @@ +package org.springframework.cloud.contract.spec.internal + +import spock.lang.Specification +/** + * @author Tim Ysewyn + */ +class InputSpec extends Specification { + + def 'should set property when using the $() convenience method'() { + given: + Input input = new Input() + DslProperty property + when: + input.with { + property = $(consumer(regex("[0-9]{5}"))) + } + then: + (property.serverValue as String).matches(/[0-9]{5}/) + } +} diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy new file mode 100644 index 0000000000..2a1da4d1ac --- /dev/null +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/OutputMessageSpec.groovy @@ -0,0 +1,20 @@ +package org.springframework.cloud.contract.spec.internal + +import spock.lang.Specification +/** + * @author Tim Ysewyn + */ +class OutputMessageSpec extends Specification { + + def 'should set property when using the $() convenience method'() { + given: + Input input = new Input() + DslProperty property + when: + input.with { + property = $(consumer(regex("[0-9]{5}"))) + } + then: + (property.serverValue as String).matches(/[0-9]{5}/) + } +}