Revert "Merge branch 'master' into 2.0.x"

This reverts commit 63a1981f54, reversing
changes made to 0cca942e86.
This commit is contained in:
Marcin Grzejszczak
2017-12-20 16:31:52 +01:00
parent f69a2f63d0
commit 822dd4b732
200 changed files with 3075 additions and 1690 deletions

View File

@@ -1,7 +1,5 @@
package org.springframework.cloud.contract.spec.internal
import java.util.regex.Pattern
import groovy.transform.Canonical
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
@@ -48,12 +46,6 @@ class BodyMatchers {
return new MatchingTypeValue(MatchingType.REGEX, regex)
}
// Backward compatibility with RegexPatterns
MatchingTypeValue byRegex(Pattern regex) {
assert regex
return new MatchingTypeValue(MatchingType.REGEX, regex)
}
MatchingTypeValue byEquality() {
return new MatchingTypeValue(MatchingType.EQUALITY, null)
}

View File

@@ -113,11 +113,6 @@ class Common {
return Pattern.compile(regex)
}
// Backward compatibility with RegexPatterns
Pattern regex(Pattern regex) {
return regex
}
OptionalProperty optional(Object object) {
return new OptionalProperty(object)
}

View File

@@ -36,8 +36,7 @@ abstract class PatternValueDslProperty<T extends DslProperty> {
protected abstract T createProperty(Pattern pattern, Object generatedValue)
T anyAlphaUnicode() {
return createAndValidateProperty(RegexPatterns.ONLY_ALPHA_UNICODE,
RandomStringGenerator.randomString(20))
return createAndValidateProperty(RegexPatterns.ONLY_ALPHA_UNICODE, randomString(20))
}
T anyNumber() {
@@ -89,16 +88,26 @@ abstract class PatternValueDslProperty<T extends DslProperty> {
}
T anyNonBlankString() {
return createAndValidateProperty(RegexPatterns.NON_BLANK,
RandomStringGenerator.randomString(20))
return createAndValidateProperty(RegexPatterns.NON_BLANK, randomString(20))
}
T anyNonEmptyString() {
return createAndValidateProperty(RegexPatterns.NON_EMPTY,
RandomStringGenerator.randomString(20))
return createAndValidateProperty(RegexPatterns.NON_EMPTY, randomString(20))
}
T anyOf(String... values){
return createAndValidateProperty(RegexPatterns.anyOf(values), values[0])
}
private static String randomString(int length) {
char[] characterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()
Random random = new Random()
char[] result = new char[length]
for (int i = 0; i < result.length; i++) {
// picks a random index out of character set > random character
int randomCharIndex = random.nextInt(characterSet.length)
result[i] = characterSet[randomCharIndex]
}
return new String(result)
}
}

View File

@@ -1,17 +0,0 @@
package org.springframework.cloud.contract.spec.internal;
import java.util.Random;
class RandomStringGenerator {
static String randomString(int length) {
char[] characterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
Random random = new Random();
char[] result = new char[length];
for (int i = 0; i < result.length; i++) {
// picks a random index out of character set > random character
int randomCharIndex = random.nextInt(characterSet.length);
result[i] = characterSet[randomCharIndex];
}
return new String(result);
}
}

View File

@@ -52,60 +52,60 @@ class RegexPatterns {
return Pattern.compile(values.collect({"^$it\$"}).join("|"))
}
Pattern onlyAlphaUnicode() {
return ONLY_ALPHA_UNICODE
String onlyAlphaUnicode() {
return ONLY_ALPHA_UNICODE.pattern()
}
Pattern number() {
return NUMBER
String number() {
return NUMBER.pattern()
}
Pattern anyBoolean() {
return TRUE_OR_FALSE
String anyBoolean() {
return TRUE_OR_FALSE.pattern()
}
Pattern ipAddress() {
return IP_ADDRESS
String ipAddress() {
return IP_ADDRESS.pattern()
}
Pattern hostname() {
return HOSTNAME_PATTERN
String hostname() {
return HOSTNAME_PATTERN.pattern()
}
Pattern email() {
return EMAIL
String email() {
return EMAIL.pattern()
}
Pattern url() {
return URL
String url() {
return URL.pattern()
}
Pattern uuid(){
return UUID
String uuid(){
return UUID.pattern()
}
Pattern isoDate() {
return ANY_DATE
String isoDate() {
return ANY_DATE.pattern()
}
Pattern isoDateTime() {
return ANY_DATE_TIME
String isoDateTime() {
return ANY_DATE_TIME.pattern()
}
Pattern isoTime() {
return ANY_TIME
String isoTime() {
return ANY_TIME.pattern()
}
Pattern iso8601WithOffset() {
return ISO8601_WITH_OFFSET
String iso8601WithOffset() {
return ISO8601_WITH_OFFSET.pattern()
}
Pattern nonEmpty() {
return NON_EMPTY
String nonEmpty() {
return NON_EMPTY.pattern()
}
Pattern nonBlank() {
return NON_BLANK
String nonBlank() {
return NON_BLANK.pattern()
}
// end::regexps[]

View File

@@ -18,13 +18,15 @@ package org.springframework.cloud.contract.spec.internal
import spock.lang.Specification
import java.util.regex.Pattern
class RegexPatternsSpec extends Specification {
RegexPatterns regexPatterns = new RegexPatterns()
def "should generate a regex for ip address [#textToMatch] that is a match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.ipAddress().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.ipAddress()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'123.123.123.123' || true
@@ -33,7 +35,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex for hostname [#textToMatch] that is a match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.hostname().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.hostname()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'https://asd.com' || true
@@ -46,7 +48,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex for email [#textToMatch] that is a match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.email().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.email()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'asd@asd.com' || true
@@ -57,7 +59,7 @@ class RegexPatternsSpec extends Specification {
// @see http://formvalidation.io/validators/uri/
def "should generate a regex for url [#textToMatch] that is a match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.url().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.url()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'ftp://asd.com:9090/asd/a?a=b' || true
@@ -128,7 +130,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex for a number [#textToMatch] that is a match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.number().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.number()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'1' || true
@@ -140,7 +142,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex for a uuid [#textToMatch] that is a match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.uuid().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.uuid()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
UUID.randomUUID().toString() || true
@@ -153,7 +155,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex with date [#textToMatch] in YYYY-MM-DD format that should match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.isoDate().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.isoDate()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
"2014-03-01" || true
@@ -171,7 +173,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex with datetime [#textToMatch] in YYYY-MM-DDTHH:mm:ss format that should match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.isoDateTime().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.isoDateTime()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
"2014-03-01T12:23:45" || true
@@ -196,7 +198,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex with time [#textToMatch] in HH:mm:ss format that should match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.isoTime().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.isoTime()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
"12:23:45" || true
@@ -212,7 +214,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex with iso8601DateTimeWithTimezone [#textToMatch] in YYYY-MM-DDTHH:mm:ss.SSSZZ format that should match [#shouldMatch]"(){
expect:
shouldMatch == regexPatterns.iso8601WithOffset().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.iso8601WithOffset()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'2014-03-01T12:23:45Z' || true
@@ -225,7 +227,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex for a non blank string [#textToMatch] that should match [#shouldMatch]"(){
expect:
shouldMatch == regexPatterns.nonBlank().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.nonBlank()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'Not Empty' || true
@@ -239,7 +241,7 @@ class RegexPatternsSpec extends Specification {
def "should generate a regex for a non empty string [#textToMatch] that should match [#shouldMatch]"() {
expect:
shouldMatch == regexPatterns.nonEmpty().matcher(textToMatch).matches()
shouldMatch == Pattern.compile(regexPatterns.nonEmpty()).matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'Not Empty' || true