Merged upstream, fixed tests
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
package io.codearte.accurest.dsl
|
||||
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import io.codearte.accurest.dsl.internal.ClientRequest
|
||||
@@ -7,8 +6,6 @@ import io.codearte.accurest.dsl.internal.Request
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import static groovy.json.StringEscapeUtils.escapeJava
|
||||
|
||||
@TypeChecked
|
||||
@PackageScope
|
||||
class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
|
||||
@@ -41,10 +38,10 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
|
||||
return [:]
|
||||
}
|
||||
if (containsRegex(body)) {
|
||||
return [bodyPatterns: [matches: parseBody(body)]]
|
||||
return [bodyPatterns: [[matches: parseBody(body)]]]
|
||||
}
|
||||
|
||||
return [bodyPatterns: [equalTo: parseBody(body)]]
|
||||
return [bodyPatterns: [[equalTo: parseBody(body)]]]
|
||||
}
|
||||
|
||||
boolean containsRegex(Object bodyObject) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package io.codearte.accurest.dsl
|
||||
import groovy.json.JsonSlurper
|
||||
import spock.lang.Specification
|
||||
|
||||
class WiremockGroovyDslSpec extends Specification {
|
||||
class WiremockGroovyDslSpec extends WiremockSpec {
|
||||
|
||||
def 'should convert groovy dsl stub to wiremock stub for the client side'() {
|
||||
given:
|
||||
@@ -48,6 +47,8 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
}
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with Body as String to wiremock stub for the client side'() {
|
||||
@@ -91,6 +92,8 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
}
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
}
|
||||
|
||||
def 'should convert groovy dsl stub with simple Body as String to wiremock stub for the client side'() {
|
||||
@@ -141,12 +144,14 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
}
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
}
|
||||
|
||||
|
||||
def 'should convert groovy dsl stub with regexp Body as String to wiremock stub for the client side'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method('GET')
|
||||
url $(client(regex('/[0-9]{2}')), server('/12'))
|
||||
@@ -170,28 +175,30 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
String wiremockStub = new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"urlPattern": "/[0-9]{2}",
|
||||
"bodyPatterns": {
|
||||
"matches":"{\\"personalId\\":\\"^[0-9]{11}$\\"}"
|
||||
}
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches":"{\\"personalId\\":\\"^[0-9]{11}$\\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"body": {
|
||||
"name": "Jan"
|
||||
},
|
||||
"body": "{\\"name\\":\\"Jan\\"}",
|
||||
"headers": {
|
||||
"Content-Type": "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWiremockStub(wiremockStub)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.codearte.accurest.dsl
|
||||
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping
|
||||
import spock.lang.Specification
|
||||
|
||||
class WiremockSpec extends Specification {
|
||||
|
||||
void stubMappingIsValidWiremockStub(String mappingDefinition) {
|
||||
StubMapping.buildFrom(mappingDefinition)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,6 +89,7 @@ project(':accurest-core') {
|
||||
compile 'commons-io:commons-io:2.4'
|
||||
testCompile 'cglib:cglib-nodep:2.2'
|
||||
testCompile 'org.objenesis:objenesis:2.1'
|
||||
testCompile 'com.github.tomakehurst:wiremock:1.53'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user