Add mock list

This commit is contained in:
Dominik Adam Przybysz 2014-12-13 21:12:56 +01:00
parent 88bb4f3067
commit ba63d36fa0
7 changed files with 120 additions and 14 deletions

View file

@ -2,6 +2,7 @@ package pl.touk.mockserver.client
import groovy.util.slurpersupport.GPathResult
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
import org.apache.http.entity.StringEntity
@ -64,4 +65,14 @@ class ControlServerClient {
</addMock>
""", ContentType.create("text/xml", "UTF-8"))
}
List<RegisteredMock> listMocks() {
HttpGet get = new HttpGet(address)
CloseableHttpResponse response = client.execute(get)
GPathResult xml = Util.extractXmlResponse(response)
if(xml.name() == 'mocks'){
return xml.mock.collect {new RegisteredMock(it.name.text(), it.path.text(), it.port.text() as int)}
}
return []
}
}

View file

@ -0,0 +1,20 @@
package pl.touk.mockserver.client
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.TypeChecked
@CompileStatic
@TypeChecked
@EqualsAndHashCode
class RegisteredMock {
final String name
final String path
final int port
RegisteredMock(String name, String path, int port) {
this.name = name
this.path = path
this.port = port
}
}

View file

@ -222,10 +222,10 @@ class MockServerIntegrationTest extends Specification {
secondXmlResponse.name() == 'goodResponseRest2'
where:
secondPort | secondPath | name
9999 | 'test1' | 'the same port and path'
9998 | 'test1' | 'the same path and another port'
9999 | 'test2' | 'the same port and another path'
9998 | 'test2' | 'another port and path'
9999 | 'test1' | 'the same port and path'
9998 | 'test1' | 'the same path and another port'
9999 | 'test2' | 'the same port and another path'
9998 | 'test2' | 'another port and path'
}
@Unroll
@ -570,6 +570,48 @@ class MockServerIntegrationTest extends Specification {
restPostResponse.name == 'goodResponse-1'
}
def "should get list mocks"() {
given:
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest2',
path: 'testEndpoint',
port: 9998
))
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest4',
path: 'testEndpoint',
port: 9999
))
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest3',
path: 'testEndpoint2',
port: 9999
))
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest5',
path: 'testEndpoint',
port: 9999
))
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest6',
path: 'testEndpoint2',
port: 9999
))
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest',
path: 'testEndpoint',
port: 9999
))
controlServerClient.removeMock('testRest5')
expect:
controlServerClient.listMocks() == [
new RegisteredMock('testRest', 'testEndpoint', 9999),
new RegisteredMock('testRest2', 'testEndpoint', 9998),
new RegisteredMock('testRest3', 'testEndpoint2', 9999),
new RegisteredMock('testRest4', 'testEndpoint', 9999),
new RegisteredMock('testRest6', 'testEndpoint2', 9999)
]
}
//TODO def "should get mock report"(){}
//TODO def "should get list mocks"(){}
}