Merge branch '2.1.x'

This commit is contained in:
Marcin Grzejszczak
2019-11-15 13:42:20 +01:00
3 changed files with 84 additions and 9 deletions

View File

@@ -34,21 +34,18 @@ class MockMvcAsyncWhen implements When, MockMvcAcceptor {
@Override
public MethodVisitor<When> apply(SingleContractMetadata metadata) {
Response response = metadata.getContract().getResponse();
if (response.getAsync()) {
this.blockBuilder.addIndented(".when().async()");
}
addAsync();
if (response.getDelay() != null) {
String delay = ".timeout(" + response.getDelay().getServerValue() + ")";
if (response.getAsync()) {
this.blockBuilder.append(delay);
}
else {
this.blockBuilder.addIndented(delay);
}
this.blockBuilder.append(delay);
}
return this;
}
private void addAsync() {
this.blockBuilder.addIndented(".when().async()");
}
@Override
public boolean accept(SingleContractMetadata metadata) {
boolean accept = acceptType(this.generatedClassMetaData, metadata);

View File

@@ -365,6 +365,7 @@ class YamlToContracts {
async()
}
if (yamlContract.response.fixedDelayMilliseconds) {
async()
fixedDelayMilliseconds(yamlContract.response.fixedDelayMilliseconds)
}
bodyMatchers {

View File

@@ -1756,6 +1756,83 @@ response:
}
}
@Issue("#1262")
def "should work with the timeout flag for groovy [#methodBuilderName]"() {
given:
Contract contractDsl = Contract.make {
request {
method(GET())
url("/hello")
}
response {
status(200)
fixedDelayMilliseconds(5000)
}
}
methodBuilder()
when:
String test = singleTestGenerator(contractDsl)
then:
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
and:
test.contains("timeout")
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder
"spock" | {
properties.testFramework = TestFramework.SPOCK
}
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
}
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
}
@Issue("#1262")
def "should work with the timeout flag for yaml [#methodBuilderName]"() {
given:
String yaml = '''\
request:
method: GET
url: /hello
queryParameters:
name: LuLu
response:
status: 200
fixedDelayMilliseconds: 5000
body: "Hello LuLu"
async: true
'''
File tmpFile = File.createTempFile("foo", ".yml")
tmpFile.createNewFile()
tmpFile.text = yaml
Contract contractDsl = new YamlContractConverter().convertFrom(tmpFile).
first()
methodBuilder()
when:
String test = singleTestGenerator(contractDsl)
then:
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
and:
test.contains("timeout")
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder
"spock" | {
properties.testFramework = TestFramework.SPOCK
}
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
}
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
}
@Issue("#1049")
def "should work with body having new lines [#methodBuilderName]"() {
given: