Enabling creation of delayed stub responses.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.codearte.accurest.wiremock
|
||||
|
||||
import org.skyscreamer.jsonassert.JSONAssert
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
|
||||
class DslToWireMockClientConverterSpec extends Specification {
|
||||
@@ -28,6 +29,30 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
''', json, false)
|
||||
}
|
||||
|
||||
@Issue("196")
|
||||
def "should creation of delayed stub responses be possible"() {
|
||||
given:
|
||||
def converter = new DslToWireMockClientConverter()
|
||||
and:
|
||||
String dslBody = """
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "/test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
fixedDelayMilliseconds 1000
|
||||
}
|
||||
}
|
||||
"""
|
||||
when:
|
||||
String json = converter.convertContent(dslBody)
|
||||
then:
|
||||
JSONAssert.assertEquals('''
|
||||
{"request":{"method":"GET","url":"/test"},"response":{"status":200, "fixedDelayMilliseconds":1000}}
|
||||
''', json, false)
|
||||
}
|
||||
|
||||
def "should convert DSL file with a nested list to WireMock JSON"() {
|
||||
given:
|
||||
|
||||
@@ -31,6 +31,7 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
|
||||
.withStatus(response.status.clientValue as Integer)
|
||||
appendHeaders(builder)
|
||||
appendBody(builder)
|
||||
appendResponseDelayTime(builder)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
@@ -53,5 +54,11 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
private void appendResponseDelayTime(ResponseDefinitionBuilder builder) {
|
||||
if (response.delay) {
|
||||
builder.withFixedDelay(response.delay.clientValue as Integer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import groovy.transform.TypeChecked
|
||||
class Response extends Common {
|
||||
|
||||
DslProperty status
|
||||
DslProperty delay
|
||||
Headers headers
|
||||
Body body
|
||||
|
||||
@@ -49,6 +50,10 @@ class Response extends Common {
|
||||
this.body = new Body(bodyAsValue)
|
||||
}
|
||||
|
||||
void fixedDelayMilliseconds(int timeInMilliseconds) {
|
||||
this.delay = toDslProperty(timeInMilliseconds)
|
||||
}
|
||||
|
||||
void assertThatSidesMatch(OptionalProperty stubSide, Object testSide) {
|
||||
throw new IllegalStateException("Optional can be used only in the test side of the response!")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user