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 61c6b7c29b..478b61f5de 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 @@ -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: 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!") }