diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy index 60801e3950..efa35f27b8 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy +++ b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy @@ -4,6 +4,7 @@ import io.codearte.accurest.file.Contract import org.junit.Rule import org.junit.rules.TemporaryFolder import org.skyscreamer.jsonassert.JSONAssert +import spock.lang.Issue import spock.lang.Specification class DslToWireMockClientConverterSpec extends Specification { @@ -35,6 +36,28 @@ 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 { + } + response { + status 200 + fixedDelayMilliseconds 1000 + } + } +""" + when: + String json = converter.convertContent(dslBody) + then: + JSONAssert.assertEquals(''' +{"request":{},"response":{"status":200,"fixedDelayMilliseconds":1000}} +''', json, false) + } def "should convert DSL file with a nested list to WireMock JSON"() { given: diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy index 3f63e6433c..8dda4777bd 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockResponseStubStrategy.groovy @@ -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) + } + } + } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy index b2546cd5c8..612a092ef1 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/internal/Response.groovy @@ -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!") }