Usage of fixedTimeoutMillis requires async()

fixes gh-1262
This commit is contained in:
Marcin Grzejszczak
2019-11-15 13:35:17 +01:00
parent 9906508593
commit 2f03472659
3 changed files with 67 additions and 0 deletions

View File

@@ -175,6 +175,7 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
bb.addLine('.when().async()')
}
if (response.delay) {
bb.addLine('.when().async()')
bb.addLine(".timeout(${response.delay.serverValue})")
}
}

View File

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

View File

@@ -1473,6 +1473,71 @@ response:
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
}
@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)
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
then:
String test = blockBuilder.toString()
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
test.contains('''timeout''')
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder
"MockMvcSpockMethodBuilder" | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
}
@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()
MethodBodyBuilder builder = methodBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
then:
String test = blockBuilder.toString()
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
test.contains('''timeout''')
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder
"MockMvcSpockMethodBuilder" | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
}
@Issue("#1049")
def "should work with body having new lines [#methodBuilderName]"() {
given: