Add support for path parameters
This commit is contained in:
parent
0bfa0d91b4
commit
d476478192
3 changed files with 29 additions and 4 deletions
|
@ -17,7 +17,7 @@ class ContextExecutor {
|
|||
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
||||
httpServerWraper.createContext(path, {
|
||||
HttpExchange ex ->
|
||||
MockRequest request = new MockRequest(ex.requestBody.text, ex.requestHeaders, ex.requestURI.query)
|
||||
MockRequest request = new MockRequest(ex.requestBody.text, ex.requestHeaders, ex.requestURI)
|
||||
println "Mock received input"
|
||||
for (Mock mock : mocks) {
|
||||
try {
|
||||
|
|
|
@ -13,14 +13,16 @@ class MockRequest {
|
|||
final GPathResult xml
|
||||
final GPathResult soap
|
||||
final Object json
|
||||
final List<String> path
|
||||
|
||||
MockRequest(String text, Headers headers, String query) {
|
||||
MockRequest(String text, Headers headers, URI uri) {
|
||||
this.text = text
|
||||
this.headers = headersToMap(headers)
|
||||
this.query = queryParamsToMap(query)
|
||||
this.query = queryParamsToMap(uri.query)
|
||||
this.xml = inputToXml(text)
|
||||
this.soap = inputToSoap(xml)
|
||||
this.json = inputToJson(text)
|
||||
this.path = uri.path.split('/').findAll()
|
||||
}
|
||||
|
||||
private static GPathResult inputToXml(String text) {
|
||||
|
|
|
@ -612,7 +612,30 @@ class MockServerIntegrationTest extends Specification {
|
|||
new RegisteredMock('testRest4', 'testEndpoint', 9999),
|
||||
new RegisteredMock('testRest6', 'testEndpoint2', 9999)
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
def "should add mock accepts path certain path params"() {
|
||||
given:
|
||||
controlServerClient.addMock(new AddMockRequestData(
|
||||
name: 'testRest',
|
||||
path: 'testEndpoint',
|
||||
port: 9999,
|
||||
predicate: '''{req -> req.path[1] == '15' && req.path[2] == 'comments'}''',
|
||||
response: '''{req -> """{"name":"goodResponse-${req.path[1]}"}"""}'''
|
||||
))
|
||||
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint/15/comments')
|
||||
HttpPost badRestPost = new HttpPost('http://localhost:9999/testEndpoint/test/comments')
|
||||
when:
|
||||
CloseableHttpResponse badResponse = client.execute(badRestPost)
|
||||
then:
|
||||
badResponse.statusLine.statusCode == 404
|
||||
Util.consumeResponse(badResponse)
|
||||
when:
|
||||
CloseableHttpResponse response = client.execute(restPost)
|
||||
then:
|
||||
Object restPostResponse = Util.extractJsonResponse(response)
|
||||
restPostResponse.name == 'goodResponse-15'
|
||||
}
|
||||
|
||||
//TODO def "should get mock report"(){}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue