Allows passing of regex type (#832)
without this change if one does $(regex("[0-9]")) we have no knowledge of whether the result should be text or a number. What we do ATM is we always generate a String
with this change once can pass the type of regular expression and we will generate the concrete value of that given type
fixes gh-768
This commit is contained in:
committed by
GitHub
parent
58bf533462
commit
56fbc11f62
@@ -37,6 +37,7 @@ import org.springframework.cloud.contract.spec.internal.BodyMatcher;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.spec.internal.RegexProperty;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils;
|
||||
@@ -133,8 +134,8 @@ class StubRunnerCamelPredicate implements Predicate {
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
|
||||
}
|
||||
else if (dslBody instanceof Pattern && inputMessage instanceof String) {
|
||||
Pattern pattern = (Pattern) dslBody;
|
||||
else if (dslBody instanceof RegexProperty && inputMessage instanceof String) {
|
||||
Pattern pattern = ((RegexProperty) dslBody).getPattern();
|
||||
matches = pattern.matcher((String) inputMessage).matches();
|
||||
bodyUnmatchedLog(dslBody, matches, pattern);
|
||||
} else {
|
||||
@@ -206,8 +207,8 @@ class StubRunnerCamelPredicate implements Predicate {
|
||||
Object value = it.getClientValue();
|
||||
Object valueInHeader = headers.get(name);
|
||||
boolean matches;
|
||||
if (value instanceof Pattern) {
|
||||
Pattern pattern = (Pattern) value;
|
||||
if (value instanceof RegexProperty) {
|
||||
Pattern pattern = ((RegexProperty) value).getPattern();
|
||||
matches = pattern.matcher(valueInHeader.toString()).matches();
|
||||
}
|
||||
else {
|
||||
@@ -225,8 +226,8 @@ class StubRunnerCamelPredicate implements Predicate {
|
||||
}
|
||||
|
||||
private String unmatchedText(Object expectedValue) {
|
||||
return expectedValue instanceof Pattern
|
||||
? "match pattern [" + ((Pattern) expectedValue).pattern() + "]"
|
||||
return expectedValue instanceof RegexProperty
|
||||
? "match pattern [" + ((RegexProperty) expectedValue).pattern() + "]"
|
||||
: "be equal to [" + expectedValue + "]";
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.cloud.contract.spec.internal.BodyMatcher;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.spec.internal.RegexProperty;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils;
|
||||
@@ -151,8 +152,8 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
|
||||
}
|
||||
else if (dslBody instanceof Pattern && inputMessage instanceof String) {
|
||||
Pattern pattern = (Pattern) dslBody;
|
||||
else if (dslBody instanceof RegexProperty && inputMessage instanceof String) {
|
||||
Pattern pattern = ((RegexProperty) dslBody).getPattern();
|
||||
matches = pattern.matcher((String) inputMessage).matches();
|
||||
bodyUnmatchedLog(dslBody, matches, pattern);
|
||||
} else {
|
||||
@@ -224,8 +225,8 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
Object value = it.getClientValue();
|
||||
Object valueInHeader = headers.get(name);
|
||||
boolean matches;
|
||||
if (value instanceof Pattern) {
|
||||
Pattern pattern = (Pattern) value;
|
||||
if (value instanceof RegexProperty) {
|
||||
Pattern pattern = ((RegexProperty) value).getPattern();
|
||||
matches = pattern.matcher(valueInHeader.toString()).matches();
|
||||
}
|
||||
else {
|
||||
@@ -243,8 +244,8 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
}
|
||||
|
||||
private String unmatchedText(Object expectedValue) {
|
||||
return expectedValue instanceof Pattern
|
||||
? "match pattern [" + ((Pattern) expectedValue).pattern() + "]"
|
||||
return expectedValue instanceof RegexProperty
|
||||
? "match pattern [" + ((RegexProperty) expectedValue).pattern() + "]"
|
||||
: "be equal to [" + expectedValue + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.cloud.contract.spec.internal.BodyMatcher;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.spec.internal.RegexProperty;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils;
|
||||
@@ -150,8 +151,8 @@ class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
|
||||
}
|
||||
else if (dslBody instanceof Pattern && inputMessage instanceof String) {
|
||||
Pattern pattern = (Pattern) dslBody;
|
||||
else if (dslBody instanceof RegexProperty && inputMessage instanceof String) {
|
||||
Pattern pattern = ((RegexProperty) dslBody).getPattern();
|
||||
matches = pattern.matcher((String) inputMessage).matches();
|
||||
bodyUnmatchedLog(dslBody, matches, pattern);
|
||||
} else {
|
||||
@@ -223,8 +224,8 @@ class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
Object value = it.getClientValue();
|
||||
Object valueInHeader = headers.get(name);
|
||||
boolean matches;
|
||||
if (value instanceof Pattern) {
|
||||
Pattern pattern = (Pattern) value;
|
||||
if (value instanceof RegexProperty) {
|
||||
Pattern pattern = ((RegexProperty) value).getPattern();
|
||||
matches = pattern.matcher(valueInHeader.toString()).matches();
|
||||
}
|
||||
else {
|
||||
@@ -242,8 +243,8 @@ class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
}
|
||||
|
||||
private String unmatchedText(Object expectedValue) {
|
||||
return expectedValue instanceof Pattern
|
||||
? "match pattern [" + ((Pattern) expectedValue).pattern() + "]"
|
||||
return expectedValue instanceof RegexProperty
|
||||
? "match pattern [" + ((RegexProperty) expectedValue).pattern() + "]"
|
||||
: "be equal to [" + expectedValue + "]";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user