org.mockserver.client.proxy
Class ProxyClient

java.lang.Object
  extended by org.mockserver.client.AbstractClient
      extended by org.mockserver.client.proxy.ProxyClient

public class ProxyClient
extends AbstractClient

Author:
jamesdbloom

Field Summary
 
Fields inherited from class org.mockserver.client.AbstractClient
contextPath, expectationSerializer, host, httpRequestSerializer, logger, nettyHttpClient, port, verificationSequenceSerializer, verificationSerializer
 
Constructor Summary
ProxyClient(String host, int port)
          Start the client communicating to a the proxy at the specified host and port for example: ProxyClient mockServerClient = new ProxyClient("localhost", 1080);
ProxyClient(String host, int port, String contextPath)
          Start the client communicating to the proxy at the specified host and port and contextPath for example: ProxyClient mockServerClient = new ProxyClient("localhost", 1080, "/proxy");
 
Method Summary
 ProxyClient clear(HttpRequest httpRequest)
          Clear all recorded requests that match the httpRequest parameter
 ProxyClient dumpToLogAsJava()
          Output Java code for creating all requests / responses as Expectations to the log.
 ProxyClient dumpToLogAsJava(HttpRequest httpRequest)
          Output Java code for creating matching requests and their responses as Expectations to the log.
 ProxyClient dumpToLogAsJSON()
          Pretty-print the json for all requests / responses as Expectations to the log.
 ProxyClient dumpToLogAsJSON(HttpRequest httpRequest)
          Pretty-print the json for matching requests and their responses as Expectations to the log.
 boolean isRunning()
          Returns whether the proxy is running
 ProxyClient reset()
          Reset the proxy by clearing recorded requests
 Expectation[] retrieveAsExpectations(HttpRequest httpRequest)
          Retrieve the recorded requests that match the httpRequest parameter as expectations, use null for the parameter to retrieve all requests
 String retrieveAsJSON(HttpRequest httpRequest)
          Retrieve the recorded requests that match the httpRequest parameter as a JSON array, use null for the parameter to retrieve all requests
 ProxyClient stop()
          Stop the proxy gracefully (only support for Netty and Vert.X versions, not supported for WAR version)
 ProxyClient stop(boolean ignoreFailure)
           
 ProxyClient verify(HttpRequest... httpRequests)
          Verify a list of requests have been sent in the order specified for example: mockServerClient .verify( request() .withPath("/first_request") .withBody("some_request_body"), request() .withPath("/second_request") .withBody("some_request_body") );
 ProxyClient verify(HttpRequest httpRequest, VerificationTimes times)
          Verify a request has been sent for example: mockServerClient .verify( request() .withPath("/some_path") .withBody("some_request_body"), VerificationTimes.exactly(3) ); VerificationTimes supports multiple static factory methods: once() - verify the request was only received once exactly(n) - verify the request was only received exactly n times atLeast(n) - verify the request was only received at least n times
 
Methods inherited from class org.mockserver.client.AbstractClient
calculatePath, formatErrorMessage, sendRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyClient

public ProxyClient(String host,
                   int port)
Start the client communicating to a the proxy at the specified host and port for example: ProxyClient mockServerClient = new ProxyClient("localhost", 1080);

Parameters:
host - the host for the MockServer to communicate with
port - the port for the MockServer to communicate with

ProxyClient

public ProxyClient(String host,
                   int port,
                   String contextPath)
Start the client communicating to the proxy at the specified host and port and contextPath for example: ProxyClient mockServerClient = new ProxyClient("localhost", 1080, "/proxy");

Parameters:
host - the host for the proxy to communicate with
port - the port for the proxy to communicate with
contextPath - the context path that the proxy war is deployed to
Method Detail

dumpToLogAsJSON

public ProxyClient dumpToLogAsJSON()
Pretty-print the json for all requests / responses as Expectations to the log. They are printed into a dedicated log called mockserver_request.log


dumpToLogAsJSON

public ProxyClient dumpToLogAsJSON(HttpRequest httpRequest)
Pretty-print the json for matching requests and their responses as Expectations to the log. They are printed into a dedicated log called mockserver_request.log

Parameters:
httpRequest - the http request that is matched against when deciding what to log if null all requests are logged

dumpToLogAsJava

public ProxyClient dumpToLogAsJava()
Output Java code for creating all requests / responses as Expectations to the log. They are printed into a dedicated log called mockserver_request.log


dumpToLogAsJava

public ProxyClient dumpToLogAsJava(HttpRequest httpRequest)
Output Java code for creating matching requests and their responses as Expectations to the log. They are printed into a dedicated log called mockserver_request.log

Parameters:
httpRequest - the http request that is matched against when deciding what to log if null all requests are logged

isRunning

public boolean isRunning()
Returns whether the proxy is running


stop

public ProxyClient stop()
Stop the proxy gracefully (only support for Netty and Vert.X versions, not supported for WAR version)


stop

public ProxyClient stop(boolean ignoreFailure)

reset

public ProxyClient reset()
Reset the proxy by clearing recorded requests


clear

public ProxyClient clear(HttpRequest httpRequest)
Clear all recorded requests that match the httpRequest parameter

Parameters:
httpRequest - the http request that is matched against when deciding whether to clear recorded requests

verify

public ProxyClient verify(HttpRequest... httpRequests)
                   throws AssertionError
Verify a list of requests have been sent in the order specified for example: mockServerClient .verify( request() .withPath("/first_request") .withBody("some_request_body"), request() .withPath("/second_request") .withBody("some_request_body") );

Parameters:
httpRequests - the http requests that must be matched for this verification to pass
Throws:
AssertionError - if the request has not been found

verify

public ProxyClient verify(HttpRequest httpRequest,
                          VerificationTimes times)
                   throws AssertionError
Verify a request has been sent for example: mockServerClient .verify( request() .withPath("/some_path") .withBody("some_request_body"), VerificationTimes.exactly(3) ); VerificationTimes supports multiple static factory methods: once() - verify the request was only received once exactly(n) - verify the request was only received exactly n times atLeast(n) - verify the request was only received at least n times

Parameters:
httpRequest - the http request that must be matched for this verification to pass
times - the number of times this request must be matched
Throws:
AssertionError - if the request has not been found

retrieveAsExpectations

public Expectation[] retrieveAsExpectations(HttpRequest httpRequest)
Retrieve the recorded requests that match the httpRequest parameter as expectations, use null for the parameter to retrieve all requests

Parameters:
httpRequest - the http request that is matched against when deciding whether to return each expectation, use null for the parameter to retrieve for all requests
Returns:
an array of all expectations that have been recorded by the proxy

retrieveAsJSON

public String retrieveAsJSON(HttpRequest httpRequest)
Retrieve the recorded requests that match the httpRequest parameter as a JSON array, use null for the parameter to retrieve all requests

Parameters:
httpRequest - the http request that is matched against when deciding whether to return each expectation, use null for the parameter to retrieve for all requests
Returns:
a JSON array of all expectations that have been recorded by the proxy


Copyright © 2015. All rights reserved.