Package io.fabric8.mockwebserver
Class DefaultMockServer
- java.lang.Object
-
- io.fabric8.mockwebserver.DefaultMockServer
-
- All Implemented Interfaces:
MockServer
public class DefaultMockServer extends Object implements MockServer
-
-
Constructor Summary
Constructors Constructor Description DefaultMockServer()DefaultMockServer(boolean useHttps)DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps)DefaultMockServer(MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MockServerExpectationexpect()Returns aMockServerExpectationto set the expectations.StringgetHostName()The host name for theMockWebServer.RecordedRequestgetLastRequest()Returns the last (most recent) HTTP request processed by theMockWebServer.intgetPort()The port for theMockWebServer.intgetRequestCount()Returns the number of HTTP requests received thus far by this server.io.vertx.core.net.SelfSignedCertificategetSelfSignedCertificate()Returns theSelfSignedCertificatefor the Mock Web Server.voidreset()voidshutdown()voidstart()voidstart(int port)voidstart(InetAddress inetAddress, int port)RecordedRequesttakeRequest()Awaits the next HTTP request, removes it, and returns it.RecordedRequesttakeRequest(long timeout, TimeUnit unit)Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it, and returns it.ProxytoProxyAddress()Returns aProxyfor theMockWebServerwith the current HostName and Port.Stringurl(String path)Returns a String URL for connecting to this server.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.fabric8.mockwebserver.MockServer
onShutdown, onStart
-
-
-
-
Constructor Detail
-
DefaultMockServer
public DefaultMockServer()
-
DefaultMockServer
public DefaultMockServer(boolean useHttps)
-
DefaultMockServer
public DefaultMockServer(MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
-
DefaultMockServer
public DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
-
DefaultMockServer
public DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps)
-
-
Method Detail
-
start
public final void start()
-
start
public final void start(int port)
-
start
public final void start(InetAddress inetAddress, int port)
-
shutdown
public final void shutdown()
-
reset
public void reset()
-
url
public String url(String path)
Returns a String URL for connecting to this server.- Specified by:
urlin interfaceMockServer- Parameters:
path- the request path, such as "/".
-
getPort
public int getPort()
The port for theMockWebServer.- Specified by:
getPortin interfaceMockServer- Returns:
- the MockWebServer port.
-
getHostName
public String getHostName()
The host name for theMockWebServer.- Specified by:
getHostNamein interfaceMockServer- Returns:
- the MockWebServer host name;
-
toProxyAddress
public Proxy toProxyAddress()
Returns aProxyfor theMockWebServerwith the current HostName and Port.- Specified by:
toProxyAddressin interfaceMockServer- Returns:
- a Proxy for the MockWebServer.
-
getSelfSignedCertificate
public io.vertx.core.net.SelfSignedCertificate getSelfSignedCertificate()
Returns theSelfSignedCertificatefor the Mock Web Server.- Specified by:
getSelfSignedCertificatein interfaceMockServer- Returns:
- the SelfSignedCertificate for the MockWebServer.
-
expect
public MockServerExpectation expect()
Returns aMockServerExpectationto set the expectations.- Specified by:
expectin interfaceMockServer- Returns:
- the MockServerExpectation builder.
-
getRequestCount
public int getRequestCount()
Returns the number of HTTP requests received thus far by this server. This may exceed the number of HTTP connections when connection reuse is in practice.- Specified by:
getRequestCountin interfaceMockServer
-
takeRequest
public RecordedRequest takeRequest() throws InterruptedException
Awaits the next HTTP request, removes it, and returns it. Callers should use this to verify the request was sent as intended. This method will block until the request is available, possibly forever.- Specified by:
takeRequestin interfaceMockServer- Returns:
- the head of the request queue
- Throws:
InterruptedException
-
takeRequest
public RecordedRequest takeRequest(long timeout, TimeUnit unit) throws InterruptedException
Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it, and returns it. Callers should use this to verify the request was sent as intended within the given time.- Specified by:
takeRequestin interfaceMockServer- Parameters:
timeout- how long to wait before giving up, in units ofunitunit- aTimeUnitdetermining how to interpret thetimeoutparameter- Returns:
- the head of the request queue
- Throws:
InterruptedException
-
getLastRequest
public RecordedRequest getLastRequest() throws InterruptedException
Returns the last (most recent) HTTP request processed by theMockWebServer. n.b. This method clears the request queue.- Specified by:
getLastRequestin interfaceMockServer- Returns:
- the most recent RecordedRequest or null if none was processed.
- Throws:
InterruptedException
-
-