Added the missing $() convenience method for messaging contracts (#623)

Fixes gh-619

(cherry picked from commit 4cf6e19)
This commit is contained in:
Tim Ysewyn
2018-04-18 23:19:00 +02:00
committed by Marcin Grzejszczak
parent 5dbac1f210
commit bfb5495ae7
4 changed files with 57 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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}/)
}
}

View File

@@ -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}/)
}
}