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 465df6461d..880628b29c 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 @@ -90,6 +90,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 f369cc1761..d7c7a861c0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,14 @@ import repackaged.nl.flotsam.xeger.Xeger import java.util.regex.Pattern +/** + * Represents an output for messaging. Used for verifying + * the body and headers that are sent. + * + * @author Marcin Grzejszczak + * @author Tim Ysewyn + * @since 1.0.0 + */ @TypeChecked @EqualsAndHashCode @ToString(includePackage = false, includeNames = true) @@ -88,6 +96,10 @@ class OutputMessage extends Common { return new DslProperty(value, server.serverValue) } + DslProperty $(ServerDslProperty server) { + return value(server) + } + void testMatchers(@DelegatesTo(ResponseBodyMatchers) Closure closure) { this.matchers = new ResponseBodyMatchers() closure.delegate = this.matchers 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}/) + } +}