Introduced Dsl DslProperty with String or Pattern passing
This commit is contained in:
@@ -20,8 +20,8 @@ class WiremockToDslConverter {
|
||||
request {
|
||||
${request.method ? "method \"\"\"$request.method\"\"\"" : ""}
|
||||
${request.url ? "url \"\"\"$request.url\"\"\"" : ""}
|
||||
${request.urlPattern ? "urlPattern \"\"\"${escapeJava(request.urlPattern)}\"\"\"" : ""}
|
||||
${request.urlPath ? "urlPath \"\"\"$request.urlPath\"\"\"" : ""}
|
||||
${request.urlPattern ? "url \$(client(java.util.regex.Pattern.compile('${escapeJava(request.urlPattern)}')), server(''))" : ""}
|
||||
${request.urlPath ? "url \"\"\"$request.urlPath\"\"\"" : ""}
|
||||
${
|
||||
request.headers ? """headers {
|
||||
${
|
||||
|
||||
@@ -13,7 +13,7 @@ class DslToWiremockClientConverterSpec extends Specification {
|
||||
io.coderate.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method('PUT')
|
||||
urlPattern \$(client('/[0-9]{2}'), server('/12'))
|
||||
url \$(client(~/\\/[0-9]{2}/), server('/12'))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
|
||||
@@ -11,7 +11,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"urlPattern": "/[0-9]{2}",
|
||||
"url": "/path",
|
||||
"headers" : {
|
||||
"Accept": {
|
||||
"matches": "text/.*"
|
||||
@@ -44,7 +44,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPattern '/[0-9]{2}'
|
||||
url '/path'
|
||||
headers {
|
||||
header('Accept').matches('text/.*')
|
||||
header('etag').doesNotMatch('abcd.*')
|
||||
@@ -101,7 +101,7 @@ class WiremockToDslConverterSpec extends Specification {
|
||||
GroovyDsl expectedGroovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'DELETE'
|
||||
urlPattern '/credit-card-verification-data/[0-9]+'
|
||||
url $(client(~/\/credit-card-verification-data\/[0-9]+/), server(''))
|
||||
headers {
|
||||
header('Content-Type').equalTo('application/vnd.mymoid-adapter.v2+json; charset=UTF-8')
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.coderate.accurest.builder
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.transform.PackageScope
|
||||
import io.coderate.accurest.dsl.GroovyDsl
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
*/
|
||||
@@ -34,7 +31,7 @@ class SpockMethodBodyBuilder {
|
||||
blockBuilder.addLine('when:').startBlock()
|
||||
blockBuilder.addLine('def response = given().spec(request)')
|
||||
blockBuilder.indent()
|
||||
blockBuilder.addLine(".${stubDefinition.request.method.serverValue.toLowerCase()}(\"$stubDefinition.request.urlPattern.serverValue\")")
|
||||
blockBuilder.addLine(".${stubDefinition.request.method. serverValue.toLowerCase()}(\"$stubDefinition.request.url.serverValue\")")
|
||||
blockBuilder.unindent().endBlock().addEmptyLine()
|
||||
|
||||
blockBuilder.addLine('then:').startBlock()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package io.coderate.accurest.dsl
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
import io.coderate.accurest.dsl.internal.ClientRequest
|
||||
import io.coderate.accurest.dsl.internal.Request
|
||||
import io.coderate.accurest.dsl.internal.ServerRequest
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@CompileStatic
|
||||
@PackageScope
|
||||
@@ -22,13 +22,15 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
|
||||
}
|
||||
|
||||
private Map<String, Object> buildRequestContent(ClientRequest request) {
|
||||
return [method : request?.method?.clientValue,
|
||||
url : request?.url?.clientValue,
|
||||
urlPattern: request?.urlPattern?.clientValue,
|
||||
urlPath : request?.urlPath?.clientValue,
|
||||
return ([method : request?.method?.clientValue,
|
||||
headers : buildClientHeadersSection(request.headers),
|
||||
body : request?.body?.clientValue
|
||||
].findAll { it.value }
|
||||
] << appendUrl(request)).findAll { it.value }
|
||||
}
|
||||
|
||||
private Map<String, Object> appendUrl(ClientRequest clientRequest) {
|
||||
Object url = clientRequest?.url?.clientValue
|
||||
return url instanceof Pattern ? [urlPattern: ((Pattern)url).pattern()] : [url: url]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package io.coderate.accurest.dsl.internal
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
@@ -7,13 +6,11 @@ import groovy.transform.TypeChecked
|
||||
|
||||
@TypeChecked
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@ToString(includePackage = false)
|
||||
@ToString(includePackage = false, includeNames = true)
|
||||
class Request extends Common {
|
||||
|
||||
DslProperty method
|
||||
DslProperty url
|
||||
DslProperty urlPattern
|
||||
DslProperty urlPath
|
||||
Url url
|
||||
Headers headers
|
||||
Body body
|
||||
|
||||
@@ -23,8 +20,6 @@ class Request extends Common {
|
||||
Request(Request request) {
|
||||
this.method = request.method
|
||||
this.url = request.url
|
||||
this.urlPattern = request.urlPattern
|
||||
this.urlPath = request.urlPath
|
||||
this.headers = request.headers
|
||||
this.body = request.body
|
||||
}
|
||||
@@ -38,19 +33,11 @@ class Request extends Common {
|
||||
}
|
||||
|
||||
void url(String url) {
|
||||
this.url = toDslProperty(url)
|
||||
this.url = new Url(url)
|
||||
}
|
||||
|
||||
void url(DslProperty url) {
|
||||
this.url = toDslProperty(url)
|
||||
}
|
||||
|
||||
void urlPattern(String urlPattern) {
|
||||
this.urlPattern = toDslProperty(urlPattern)
|
||||
}
|
||||
|
||||
void urlPattern(DslProperty urlPattern) {
|
||||
this.urlPattern = toDslProperty(urlPattern)
|
||||
this.url = new Url(url)
|
||||
}
|
||||
|
||||
void headers(@DelegatesTo(Headers) Closure closure) {
|
||||
@@ -59,14 +46,6 @@ class Request extends Common {
|
||||
closure()
|
||||
}
|
||||
|
||||
void urlPath(String urlPath) {
|
||||
this.urlPath = toDslProperty(urlPath)
|
||||
}
|
||||
|
||||
void urlPath(DslProperty urlPath) {
|
||||
this.urlPath = toDslProperty(urlPath)
|
||||
}
|
||||
|
||||
void body(Map<String, Object> body) {
|
||||
this.body = new Body(convertObjectsToDslProperties(body))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.coderate.accurest.dsl.internal
|
||||
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
|
||||
@ToString(includePackage = false, includeFields = true, includeNames = true)
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
class Url extends DslProperty {
|
||||
|
||||
Url(DslProperty bodyAsValue) {
|
||||
super(bodyAsValue.clientValue, bodyAsValue.serverValue)
|
||||
}
|
||||
|
||||
Url(String bodyAsValue) {
|
||||
super(bodyAsValue)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package io.codearte.accurest.dsl
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import io.coderate.accurest.dsl.GroovyDsl
|
||||
import io.coderate.accurest.dsl.WiremockRequestStubStrategy
|
||||
import io.coderate.accurest.dsl.WiremockStubStrategy
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.Specification
|
||||
|
||||
class WiremockGroovyDslSpec extends Specification {
|
||||
@@ -14,7 +12,7 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method('GET')
|
||||
urlPattern $(client('/[0-9]{2}'), server('/12'))
|
||||
url $(client(~/\/[0-9]{2}/), server('/12'))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
@@ -65,7 +63,7 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method('GET')
|
||||
urlPattern $(client('/[0-9]{2}'), server('/12'))
|
||||
url $(client(~/\/[0-9]{2}/), server('/12'))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
@@ -113,7 +111,7 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method('GET')
|
||||
urlPattern $(client('/[0-9]{2}'), server('/12'))
|
||||
url $(client(~/\/[0-9]{2}/), server('/12'))
|
||||
body("""\
|
||||
{
|
||||
"name": "Jan"
|
||||
@@ -195,8 +193,8 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
urlPattern $(
|
||||
client('/^[0-9]{2}$'),
|
||||
url $(
|
||||
client(~/\/^[0-9]{2}$/),
|
||||
server('/12')
|
||||
)
|
||||
}
|
||||
@@ -209,21 +207,6 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
''')
|
||||
}
|
||||
|
||||
def "should generate stub with urlPath for client side"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
urlPath('/12')
|
||||
}
|
||||
}
|
||||
expect:
|
||||
new WiremockRequestStubStrategy(groovyDsl).buildClientRequestContent() == new JsonSlurper().parseText('''
|
||||
{
|
||||
"urlPath":"/12"
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def "should generate stub with some headers section for client side"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
|
||||
Reference in New Issue
Block a user