Refactor tests
This commit is contained in:
parent
5db690c434
commit
dfc0332d5a
8 changed files with 233 additions and 2 deletions
|
@ -0,0 +1,56 @@
|
|||
package pl.touk.mockserver.client
|
||||
|
||||
import groovy.util.slurpersupport.GPathResult
|
||||
import org.apache.http.client.methods.CloseableHttpResponse
|
||||
import org.apache.http.client.methods.HttpPost
|
||||
import org.apache.http.entity.ContentType
|
||||
import org.apache.http.entity.StringEntity
|
||||
import org.apache.http.impl.client.CloseableHttpClient
|
||||
import org.apache.http.impl.client.HttpClients
|
||||
|
||||
class ControlServerClient {
|
||||
private final String address
|
||||
private final CloseableHttpClient client = HttpClients.createDefault()
|
||||
|
||||
ControlServerClient(String host, int port) {
|
||||
address = "http://$host:$port/serverControl"
|
||||
}
|
||||
|
||||
boolean addMock(AddMockRequestData addMockRequestData){
|
||||
HttpPost addMockPost = new HttpPost(address)
|
||||
addMockPost.entity = buildAddMockRequest(addMockRequestData)
|
||||
CloseableHttpResponse response = client.execute(addMockPost)
|
||||
GPathResult responseXml = Util.extractXmlResponse(response)
|
||||
return responseXml.name() == 'mockAdded'
|
||||
}
|
||||
|
||||
int removeMock(String name){
|
||||
HttpPost removeMockPost = new HttpPost(address)
|
||||
removeMockPost.entity = buildRemoveMockRequest(new RemoveMockRequestData(name:name))
|
||||
CloseableHttpResponse response = client.execute(removeMockPost)
|
||||
GPathResult responseXml = Util.extractXmlResponse(response)
|
||||
return responseXml.name() == 'mockRemoved' ? responseXml.text() as int:-1
|
||||
}
|
||||
|
||||
|
||||
private StringEntity buildRemoveMockRequest(RemoveMockRequestData data){
|
||||
return new StringEntity("""\
|
||||
<removeMock>
|
||||
<name>${data.name}</name>
|
||||
</removeMock>
|
||||
""",ContentType.create("text/xml", "UTF-8"))
|
||||
}
|
||||
|
||||
private StringEntity buildAddMockRequest(AddMockRequestData data){
|
||||
return new StringEntity("""\
|
||||
<addMock>
|
||||
<name>${data.name}</name>
|
||||
<path>${data.path}</path>
|
||||
<port>${data.port}</port>
|
||||
<predicate>${data.predicate}</predicate>
|
||||
<response>${data.response}</response>
|
||||
<soap>${data.soap}</soap>
|
||||
</addMock>
|
||||
""",ContentType.create("text/xml", "UTF-8"))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue