Merge branch '2.1.x'
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.cloud.contract.verifier.builder;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy;
|
||||
import org.springframework.cloud.contract.spec.internal.Request;
|
||||
@@ -47,9 +48,7 @@ class JaxRsRequestHeadersWhen implements When {
|
||||
.filter(header -> !headerToIgnore(header)).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Header header = iterator.next();
|
||||
String text = ".header(\"" + header.getName() + "\", "
|
||||
+ this.bodyParser.quotedLongText(MapConverter
|
||||
.getTestSideValuesForNonBody(header.getServerValue()))
|
||||
String text = ".header(\"" + header.getName() + "\", " + headerValue(header)
|
||||
+ ")";
|
||||
if (iterator.hasNext()) {
|
||||
this.blockBuilder.addLine(text);
|
||||
@@ -60,6 +59,15 @@ class JaxRsRequestHeadersWhen implements When {
|
||||
}
|
||||
}
|
||||
|
||||
private String headerValue(Header header) {
|
||||
Object headerServerValue = header.getServerValue();
|
||||
if (headerServerValue instanceof ExecutionProperty) {
|
||||
return ((ExecutionProperty) headerServerValue).getExecutionCommand();
|
||||
}
|
||||
return this.bodyParser.quotedLongText(
|
||||
MapConverter.getTestSideValuesForNonBody(header.getServerValue()));
|
||||
}
|
||||
|
||||
private boolean headerToIgnore(Header header) {
|
||||
return contentTypeOrAccept(header) || headerOfAbsentType(header);
|
||||
}
|
||||
|
||||
@@ -3161,4 +3161,45 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
"junit" | { properties.testFramework = TestFramework.JUNIT }
|
||||
"junit5" | { properties.testFramework = TestFramework.JUNIT5 }
|
||||
}
|
||||
|
||||
@Issue('#1252')
|
||||
def 'should call execute in headers instead of quoting it [#methodBuilderName]'() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method PUT()
|
||||
url '/frauds/name'
|
||||
headers {
|
||||
header(authorization(), value(client(anyNonBlankString()), server(execute("toString()"))))
|
||||
|
||||
}
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
headers {
|
||||
header(contentType(), "${fromRequest().header(contentType())}")
|
||||
}
|
||||
}
|
||||
}
|
||||
methodBuilder()
|
||||
when:
|
||||
String test = singleTestGenerator(contractDsl)
|
||||
then:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, test)
|
||||
then:
|
||||
!test.contains('''"toString()"''')
|
||||
!test.contains("""'toString()'""")
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"spock" | { properties.testFramework = TestFramework.SPOCK }
|
||||
"testng" | { properties.testFramework = TestFramework.TESTNG }
|
||||
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
|
||||
"jaxrs-spock" | {
|
||||
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
|
||||
}
|
||||
"jaxrs" | {
|
||||
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
|
||||
}
|
||||
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user