Merge branch 'master' into feature/#16-real-support-for-JUnit-new

This commit is contained in:
Olga Maciaszek-Sharma
2016-02-23 14:10:31 +01:00
3 changed files with 36 additions and 0 deletions

View File

@@ -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,29 @@ class DslToWireMockClientConverterSpec extends Specification {
''', json, false)
}
@Issue("196")
def "should creation of delayed stub responses be possible"() {
given:
def converter = new DslToWireMockClientConverter()
and:
File file = tmpFolder.newFile("dsl-delay.groovy")
file.write("""
io.codearte.accurest.dsl.GroovyDsl.make {
request {
}
response {
status 200
fixedDelayMilliseconds 1000
}
}
""")
when:
String json = converter.convertContent("test", new Contract(file.toPath(), false, 0, null))
then:
JSONAssert.assertEquals('''
{"request":{},"response":{"status":200,"fixedDelayMilliseconds":1000}}
''', json, false)
}
def "should convert DSL file with a nested list to WireMock JSON"() {
given:

View File

@@ -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)
}
}
}

View File

@@ -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!")
}