This commit is contained in:
@@ -24,12 +24,14 @@ class WireMockToDslConverter {
|
||||
def response = wireMockStub.response
|
||||
def bodyPatterns = request.bodyPatterns
|
||||
String urlPattern = request.urlPattern
|
||||
String urlPathPattern = request.urlPathPattern
|
||||
return """\
|
||||
${priority ? "priority ${priority}" : ''}
|
||||
request {
|
||||
${request.method ? "method \"\"\"$request.method\"\"\"" : ""}
|
||||
${request.url ? "url \"\"\"$request.url\"\"\"" : ""}
|
||||
${urlPattern ? "url \$(client(regex('${escapeJava(urlPattern)}')), server('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""}
|
||||
${urlPathPattern ? "urlPath \$(client(regex('${escapeJava(urlPattern)}')), server('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""}
|
||||
${request.urlPath ? "url \"\"\"$request.urlPath\"\"\"" : ""}
|
||||
${
|
||||
request.headers ? """headers {
|
||||
|
||||
@@ -108,13 +108,17 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
private void appendUrl(RequestPattern requestPattern) {
|
||||
Object urlPath = request?.urlPath?.clientValue
|
||||
if (urlPath) {
|
||||
requestPattern.setUrlPath(getStubSideValue(urlPath.toString()).toString())
|
||||
if(urlPath instanceof Pattern) {
|
||||
requestPattern.setUrlPathPattern(getStubSideValue(urlPath.toString()).toString())
|
||||
} else {
|
||||
requestPattern.setUrlPath(getStubSideValue(urlPath.toString()).toString())
|
||||
}
|
||||
}
|
||||
if(!request.url) {
|
||||
return
|
||||
}
|
||||
Object url = getUrlIfGstring(request?.url?.clientValue)
|
||||
if(url instanceof Pattern) {
|
||||
if (url instanceof Pattern) {
|
||||
requestPattern.setUrlPattern(url.pattern())
|
||||
} else {
|
||||
requestPattern.setUrl(url.toString())
|
||||
|
||||
@@ -713,6 +713,47 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
@Issue('#230')
|
||||
def "should generate request with urlPathPattern and queryParameters for client side\
|
||||
when both contains regular expressions"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath($(client(regex("/users/[0-9]+")), server("/users/1"))) {
|
||||
queryParameters {
|
||||
parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("10"))
|
||||
}
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"urlPathPattern": "/users/[0-9]+",
|
||||
"queryParameters": {
|
||||
"search": {
|
||||
"doesNotMatch": "^/[0-9]{2}$"
|
||||
}
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(json)
|
||||
}
|
||||
|
||||
|
||||
def "should generate request with urlPath for client side"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
|
||||
Reference in New Issue
Block a user