Add query parameters validation
This commit is contained in:
parent
c97ce11837
commit
e9eb6b55e1
6 changed files with 45 additions and 6 deletions
|
@ -13,6 +13,7 @@ class AddMockRequestData {
|
|||
Method method
|
||||
String responseHeaders
|
||||
String requestHeaders
|
||||
String queryParams
|
||||
|
||||
void setPredicate(String predicate) {
|
||||
this.predicate = StringEscapeUtils.escapeXml11(predicate)
|
||||
|
@ -30,6 +31,10 @@ class AddMockRequestData {
|
|||
this.requestHeaders = StringEscapeUtils.escapeXml11(requestHeaders)
|
||||
}
|
||||
|
||||
void setQueryParams(String queryParams) {
|
||||
this.queryParams = StringEscapeUtils.escapeXml11(queryParams)
|
||||
}
|
||||
|
||||
enum Method {
|
||||
POST,
|
||||
GET,
|
||||
|
|
|
@ -62,6 +62,7 @@ class ControlServerClient {
|
|||
${data.method ? "<method>${data.method}</method>" : ''}
|
||||
${data.responseHeaders ? "<responseHeaders>${data.responseHeaders}</responseHeaders>" : ''}
|
||||
${data.requestHeaders ? "<requestHeaders>${data.requestHeaders}</requestHeaders>" : ''}
|
||||
${data.queryParams ? "<queryParams>${data.queryParams}</queryParams>" : ''}
|
||||
</addMock>
|
||||
""", ContentType.create("text/xml", "UTF-8"))
|
||||
}
|
||||
|
|
|
@ -453,7 +453,7 @@ class MockServerIntegrationTest extends Specification {
|
|||
restPostResponse.name() == 'goodResponse'
|
||||
}
|
||||
|
||||
def "should add mock that accepts only when certain headers exists"() {
|
||||
def "should add mock that accepts only when certain request headers exists"() {
|
||||
given:
|
||||
controlServerClient.addMock(new AddMockRequestData(
|
||||
name: 'testRest',
|
||||
|
@ -482,8 +482,31 @@ class MockServerIntegrationTest extends Specification {
|
|||
restPostResponse.name() == 'goodResponse'
|
||||
}
|
||||
|
||||
//TODO def "should dispatch rest mock with get method and query params"(){}
|
||||
//TODO def "should dispatch rest mock with get method and parameters"(){}
|
||||
def "should add mock that accepts only when certain query params exists"() {
|
||||
given:
|
||||
controlServerClient.addMock(new AddMockRequestData(
|
||||
name: 'testRest',
|
||||
path: '/testEndpoint',
|
||||
port: 9999,
|
||||
response: '''{xml -> "<goodResponse/>"}''',
|
||||
queryParams: '''{ qp -> qp['q'] == '15' &&
|
||||
qp.id == '1'}'''
|
||||
))
|
||||
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint?q=15&id=1')
|
||||
HttpPost badRestPost = new HttpPost('http://localhost:9999/testEndpoint?q=15&id=2')
|
||||
when:
|
||||
CloseableHttpResponse badResponse = client.execute(badRestPost)
|
||||
then:
|
||||
GPathResult badRestPostResponse = Util.extractXmlResponse(badResponse)
|
||||
badRestPostResponse.name() == 'invalidInput'
|
||||
when:
|
||||
CloseableHttpResponse response = client.execute(restPost)
|
||||
then:
|
||||
GPathResult restPostResponse = Util.extractXmlResponse(response)
|
||||
restPostResponse.name() == 'goodResponse'
|
||||
}
|
||||
|
||||
//TODO def "should dispatch rest mock with post method and parameters"(){}
|
||||
//TODO def "should dispatch rest mock with post method, response headers and request headers"(){}
|
||||
|
||||
//TODO def "should get mock report"(){}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue