Merge branch '1.0.x'

This commit is contained in:
Marcin Grzejszczak
2017-01-10 18:47:53 +01:00
4 changed files with 47 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import groovy.transform.Canonical
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
/**
* Matching strategy of dynamic parts of the body.
*
@@ -11,6 +12,7 @@ import groovy.transform.ToString
* @since 1.0.3
*/
@CompileStatic
@ToString(includeFields = true, includePackage = false)
class BodyMatchers {
private final RegexPatterns regexPatterns = new RegexPatterns()
private final List<BodyMatcher> jsonPathRegexMatchers = []
@@ -43,9 +45,24 @@ class BodyMatchers {
assert regex
return new MatchingTypeValue(MatchingType.REGEX, regex)
}
boolean equals(o) {
if (this.is(o)) return true
if (this.getClass() != o.class) return false
BodyMatchers that = (BodyMatchers) o
List<BodyMatcher> thisMatchers = this.jsonPathRegexMatchers
List<BodyMatcher> thatMatchers = that.jsonPathRegexMatchers
if (thisMatchers.size() != thatMatchers.size()) return false
if (new HashSet<>(thisMatchers) != new HashSet(thatMatchers)) return false
return true
}
int hashCode() {
return (this.jsonPathRegexMatchers != null ? this.jsonPathRegexMatchers.hashCode() : 0)
}
}
@ToString
@ToString(includePackage = false)
@EqualsAndHashCode
@Canonical
@CompileStatic
@@ -83,6 +100,8 @@ class JsonPathBodyMatcher implements BodyMatcher {
* Matching type with corresponding values
*/
@Canonical
@ToString(includePackage = false)
@EqualsAndHashCode
class MatchingTypeValue {
MatchingType type

View File

@@ -17,14 +17,19 @@
package org.springframework.cloud.contract.spec.internal
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import java.util.regex.Pattern
/**
* Contains most common regular expression patterns
*
* @since 1.0.0
*/
@CompileStatic
@EqualsAndHashCode
@ToString(includePackage = false)
class RegexPatterns {
// tag::regexps[]

View File

@@ -11,24 +11,26 @@ import groovy.transform.ToString
* @since 1.0.3
*/
@CompileStatic
@EqualsAndHashCode
@ToString(includePackage = false)
@ToString(includePackage = false, includeSuper = true)
class ResponseBodyMatchers extends BodyMatchers {
MatchingTypeValue byType() {
return new MatchingTypeValue(MatchingType.TYPE)
return new MatchingTypeValue(type: MatchingType.TYPE)
}
MatchingTypeValue byType(@DelegatesTo(MatchingTypeValueHolder) Closure closure) {
MatchingTypeValueHolder matchingTypeValue = new MatchingTypeValueHolder()
closure.delegate = matchingTypeValue
return closure() as MatchingTypeValue
closure()
return matchingTypeValue.matchingTypeValue
}
}
@CompileStatic
@ToString(includePackage = false)
@EqualsAndHashCode
class MatchingTypeValueHolder {
MatchingTypeValue matchingTypeValue = new MatchingTypeValue()
MatchingTypeValue matchingTypeValue = new MatchingTypeValue(type: MatchingType.TYPE)
MatchingTypeValue minOccurrence(int number) {
this.matchingTypeValue.minTypeOccurrence = number