Add preserveHistory option for mock

This commit is contained in:
Dominik Przybysz 2015-12-28 14:11:02 +01:00
parent 7a13cb2ce5
commit 3599300191
5 changed files with 71 additions and 38 deletions

View file

@ -1071,7 +1071,8 @@ class MockServerIntegrationTest extends Specification {
imports: [
new ImportAlias(alias: 'aaa', fullClassName: 'bbb'),
new ImportAlias(alias: 'ccc', fullClassName: 'bla')
]
],
preserveHistory: true
))
remoteMockServer.removeMock('testRest5')
when:
@ -1082,7 +1083,7 @@ class MockServerIntegrationTest extends Specification {
then:
List<MockReport> mockReport = remoteMockServer.listMocks()
mockReport.size() == 5
assertMockReport(mockReport[0], [name: 'testRest', path: 'testEndpoint', port: 9999, predicate: '{ _ -> true }', response: '''{ _ -> '' }''', responseHeaders: '{ _ -> [:] }', soap: false, statusCode: 200, method: Method.POST, schema: 'schema2.xsd'])
assertMockReport(mockReport[0], [name: 'testRest', path: 'testEndpoint', port: 9999, predicate: '{ _ -> true }', response: '''{ _ -> '' }''', responseHeaders: '{ _ -> [:] }', soap: false, statusCode: 200, method: Method.POST, schema: 'schema2.xsd', preserveHistory: true])
assertMockReport(mockReport[1], [name: 'testRest2', path: 'testEndpoint', port: 9998, predicate: '''{ req -> req.xml.name() == 'request1'}''', response: '''{ req -> '<response/>' }''', responseHeaders: '{ _ -> [a: "b"] }', soap: false, statusCode: 200, method: Method.POST])
assertMockReport(mockReport[2], [name: 'testRest3', path: 'testEndpoint2', port: 9999, predicate: '{ _ -> true }', response: '''{ _ -> '' }''', responseHeaders: '{ _ -> [:] }', soap: false, statusCode: 200, method: Method.POST])
assertMockReport(mockReport[3], [name: 'testRest4', path: 'testEndpoint', port: 9999, predicate: '{ _ -> true }', response: '''{ _ -> '' }''', responseHeaders: '{ _ -> [:] }', soap: true, statusCode: 204, method: Method.PUT])
@ -1091,4 +1092,26 @@ class MockServerIntegrationTest extends Specification {
mockReport[0].imports.find { it.alias == 'ccc' }?.fullClassName == 'bla'
}
def "should add mock without history"() {
expect:
remoteMockServer.addMock(new AddMock(
name: 'testRest',
path: 'testEndpoint',
port: 9999,
predicate: '''{req -> req.xml.name() == 'request'}''',
response: '''{req -> "<goodResponseRest-${req.xml.name()}/>"}''',
soap: false,
preserveHistory: false
))
when:
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint')
restPost.entity = new StringEntity('<request/>', ContentType.create("text/xml", "UTF-8"))
CloseableHttpResponse response = client.execute(restPost)
then:
GPathResult restPostResponse = Util.extractXmlResponse(response)
restPostResponse.name() == 'goodResponseRest-request'
expect:
remoteMockServer.removeMock('testRest')?.size() == 0
}
}