[#10] Fixed header creation for requests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package io.codearte.accurest.wiremock
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import io.coderate.accurest.dsl.GroovyDsl
|
||||
|
||||
@@ -17,21 +18,35 @@ class WiremockToDslConverter {
|
||||
wiremockRequest.headers.each {
|
||||
def assertion = it.value
|
||||
String headerName = it.key as String
|
||||
header(headerName)."$assertion.key"(assertion.value)
|
||||
def entry = assertion.entrySet().first()
|
||||
header(headerName)."$entry.key"(entry.value)
|
||||
}
|
||||
} : null
|
||||
}
|
||||
response {
|
||||
status wiremockResponse.status ? wiremockResponse.status as Integer : null
|
||||
wiremockResponse.body ? body (
|
||||
wiremockResponse.body ? body(
|
||||
wiremockResponse.body as Map
|
||||
) : null
|
||||
wiremockResponse.headers ? headers {
|
||||
wiremockResponse.headers.each {
|
||||
header([(it.key) : it.value])
|
||||
header([(it.key): it.value])
|
||||
}
|
||||
} : null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int main(String[] args) {
|
||||
String rootOfFolderWithStubs = args[0]
|
||||
new File(rootOfFolderWithStubs).eachFileRecurse {
|
||||
try {
|
||||
GroovyDsl stub = fromWiremockStub(it.text)
|
||||
new File(it.parent, it.name.replaceAll('json', 'groovy')).text
|
||||
} catch (Exception e) {
|
||||
System.err.println(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,18 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"urlPattern": "/[0-9]{2}"
|
||||
"urlPattern": "/[0-9]{2}",
|
||||
"headers" : {
|
||||
"Accept": {
|
||||
"matches": "text/.*"
|
||||
},
|
||||
"etag": {
|
||||
"doesNotMatch": "abcd.*"
|
||||
},
|
||||
"X-Custom-Header": {
|
||||
"contains": "2134"
|
||||
}
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
@@ -22,7 +33,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
"created" : "2014-02-02 12:23:43"
|
||||
},
|
||||
"headers": {
|
||||
"Content-Type": "text/plain"
|
||||
"Content-Type": "text/plain",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +43,11 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPattern '/[0-9]{2}'
|
||||
headers {
|
||||
header('Accept').matches('text/.*')
|
||||
header('etag').doesNotMatch('abcd.*')
|
||||
header('X-Custom-Header').contains('2134')
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
@@ -43,6 +59,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user