Should allow regex in headers message matching. Fixes gh-1382.
This commit is contained in:
@@ -233,8 +233,8 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
Object value = it.getClientValue();
|
||||
Object valueInHeader = headers.get(name);
|
||||
boolean matches;
|
||||
if (value instanceof RegexProperty) {
|
||||
Pattern pattern = ((RegexProperty) value).getPattern();
|
||||
if (value instanceof RegexProperty || value instanceof Pattern) {
|
||||
Pattern pattern = new RegexProperty(value).getPattern();
|
||||
matches = pattern.matcher(valueInHeader.toString()).matches();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -234,8 +234,8 @@ class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
Object value = it.getClientValue();
|
||||
Object valueInHeader = headers.get(name);
|
||||
boolean matches;
|
||||
if (value instanceof RegexProperty) {
|
||||
Pattern pattern = ((RegexProperty) value).getPattern();
|
||||
if (value instanceof RegexProperty || value instanceof Pattern) {
|
||||
Pattern pattern = new RegexProperty(value).getPattern();
|
||||
matches = pattern.matcher(valueInHeader.toString()).matches();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.contract.stubrunner.messaging.integration
|
||||
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
@@ -181,7 +182,8 @@ class StubRunnerIntegrationMessageSelectorSpec extends Specification {
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(dsl)
|
||||
StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(
|
||||
dsl)
|
||||
message.headers >> [
|
||||
foo: 123
|
||||
]
|
||||
@@ -191,4 +193,29 @@ class StubRunnerIntegrationMessageSelectorSpec extends Specification {
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
|
||||
@Issue("1382")
|
||||
def "should return true if header matches regex"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", $(anyUuid()))
|
||||
}
|
||||
messageBody(foo: 123)
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(
|
||||
dsl)
|
||||
message.headers >> [
|
||||
foo: "fbcc2ed3-dbac-47e7-9a4b-c2d55709792c"
|
||||
]
|
||||
message.payload >> [
|
||||
foo: 123
|
||||
]
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.contract.stubrunner.messaging.stream
|
||||
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
@@ -210,7 +211,8 @@ class StubRunnerStreamMessageSelectorSpec extends Specification {
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl)
|
||||
StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(
|
||||
dsl)
|
||||
message.headers >> [
|
||||
foo: 123
|
||||
]
|
||||
@@ -220,4 +222,29 @@ class StubRunnerStreamMessageSelectorSpec extends Specification {
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
|
||||
@Issue("1382")
|
||||
def "should return true if header matches regex"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", $(anyUuid()))
|
||||
}
|
||||
messageBody(foo: 123)
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(
|
||||
dsl)
|
||||
message.headers >> [
|
||||
foo: "fbcc2ed3-dbac-47e7-9a4b-c2d55709792c"
|
||||
]
|
||||
message.payload >> [
|
||||
foo: 123
|
||||
]
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user