fix for issue #47 - add async options on request when new async flag set (#277)

* fix for issue #47 - add async options on request when new async flag set

* don't add async to initial request declaration and switch spaces to tabs for all changes.
This commit is contained in:
Matt Reynolds
2016-05-16 16:06:37 -06:00
committed by Marcin Grzejszczak
parent f19a451fae
commit 7d2f01aad2
4 changed files with 45 additions and 5 deletions

View File

@@ -88,7 +88,11 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
@Override
protected String getInputString(Request request) {
return 'ResponseOptions response = given().spec(request)'
def inputString = 'ResponseOptions response = given().spec(request)'
if (response.async){
inputString = inputString + '.when().async()'
}
return inputString
}
@Override

View File

@@ -71,7 +71,11 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
@Override
protected String getInputString(Request request) {
return 'def response = given().spec(request)'
def inputString = 'def response = given().spec(request)'
if (response.async){
inputString = inputString + '.when().async()'
}
return inputString
}
@Override

View File

@@ -14,6 +14,7 @@ class Response extends Common {
DslProperty delay
Headers headers
Body body
boolean async
Response() {
}
@@ -54,6 +55,10 @@ class Response extends Common {
this.delay = toDslProperty(timeInMilliseconds)
}
public void async() {
this.async = true
}
void assertThatSidesMatch(OptionalProperty stubSide, Object testSide) {
throw new IllegalStateException("Optional can be used only in the test side of the response!")
}
@@ -75,4 +80,4 @@ class ClientResponse extends Response {
ClientResponse(Response request) {
super(request)
}
}
}

View File

@@ -1263,6 +1263,33 @@ World.'''"""
"MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
"MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue('47')
def "should generate async body when async flag set in response"() {
given:
GroovyDsl contractDsl = GroovyDsl.make {
request {
method 'GET'
url '/test'
}
response {
status 200
async()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
test.contains(bodyDefinitionString)
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder | bodyDefinitionString
"MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '.when().async()'
"MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.when().async()'
}
def "should generate proper test code with array of primitives using #methodBuilderName"() {
given:
@@ -1280,7 +1307,7 @@ World.'''"""
}
]
}
''')
''')
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -1343,4 +1370,4 @@ World.'''"""
}
}
// end::dsl_example[]
}
}