Add request headers validation
This commit is contained in:
parent
9670cd6d7e
commit
c97ce11837
6 changed files with 48 additions and 5 deletions
|
@ -441,19 +441,49 @@ class MockServerIntegrationTest extends Specification {
|
|||
port: 9999,
|
||||
predicate: '''{xml -> xml.name() == 'request'}''',
|
||||
response: '''{xml -> "<goodResponse/>"}''',
|
||||
responseHeaders: '''{ xml -> [input:"${xml.name()}"]}'''
|
||||
responseHeaders: '''{ xml -> ['Input-Name':"${xml.name()}"]}'''
|
||||
))
|
||||
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint')
|
||||
restPost.entity = new StringEntity('<request/>', ContentType.create("text/xml", "UTF-8"))
|
||||
when:
|
||||
CloseableHttpResponse response = client.execute(restPost)
|
||||
then:
|
||||
response.allHeaders.findAll { it.name == 'Input' && it.value == 'request' }
|
||||
response.allHeaders.findAll { it.name.toLowerCase() == 'input-name' && it.value == 'request' }
|
||||
GPathResult restPostResponse = Util.extractXmlResponse(response)
|
||||
restPostResponse.name() == 'goodResponse'
|
||||
}
|
||||
|
||||
//TODO def "should dispatch rest mock with post method and request headers"(){}
|
||||
def "should add mock that accepts only when certain headers exists"() {
|
||||
given:
|
||||
controlServerClient.addMock(new AddMockRequestData(
|
||||
name: 'testRest',
|
||||
path: '/testEndpoint',
|
||||
port: 9999,
|
||||
response: '''{xml -> "<goodResponse/>"}''',
|
||||
requestHeaders: '''{ hs -> hs['user-agent']?.startsWith('Mozilla') &&
|
||||
hs.pragma == 'no-cache'}'''
|
||||
))
|
||||
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint')
|
||||
restPost.entity = new StringEntity('<request/>', ContentType.create("text/xml", "UTF-8"))
|
||||
restPost.addHeader('User-Agent', 'Mozilla/5.0')
|
||||
restPost.addHeader('Pragma', 'no-cache')
|
||||
HttpPost badRestPost = new HttpPost('http://localhost:9999/testEndpoint')
|
||||
badRestPost.entity = new StringEntity('<request/>', ContentType.create("text/xml", "UTF-8"))
|
||||
badRestPost.addHeader('Pragma', 'no-cache')
|
||||
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 get method and query params"(){}
|
||||
//TODO def "should dispatch rest mock with get 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