Do not unescapeJavascript when output header patterns (#568)

* This causes all backslashes to be stripped from the regular
   expression
This commit is contained in:
Mendel Feygelson
2018-03-06 14:01:30 -06:00
committed by Marcin Grzejszczak
parent fba058fe1e
commit 2ef24470c5
2 changed files with 32 additions and 3 deletions

View File

@@ -220,8 +220,7 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
}
protected String createHeaderComparison(Pattern headerValue) {
String escapedHeader = convertUnicodeEscapesIfRequired("$headerValue")
return "matches(\"$escapedHeader\");"
return "matches(\"$headerValue\");"
}
private String patternText(Pattern value) {

View File

@@ -27,7 +27,7 @@ import spock.lang.Specification
class MessagingMethodBodyBuilderSpec extends Specification {
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
def "should work for triggered based messaging with Spock"() {
given:
// tag::trigger_method_dsl[]
@@ -499,6 +499,36 @@ Contract.make {
stripped(test) == stripped(expectedMsg)
}
@Issue("567")
def "should generate tests with message headers containing regular expression with backslashes for JUnit"() {
given:
def contractDsl =
org.springframework.cloud.contract.spec.Contract.make {
label 'trigger_event'
input {
triggeredBy('requestIsCalled()')
}
outputMessage {
sentTo 'topic.rateablequote'
headers {
header('processId', value(producer(regex('\\d+')), consumer('123')))
}
body([
eventId: value(producer(regex('\\d+')), consumer('1'))
])
}
}
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
test.contains('assertThat(response.getHeader("processId").toString()).matches("\\d+");')
}
@Issue("336")
def "should generate tests with message headers containing regular expression for Spock"() {
given: