Package io.fabric8.mockwebserver
Interface MockServer
-
- All Known Implementing Classes:
DefaultMockServer
public interface MockServer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default 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.default voidonShutdown()This method is called right after shutdown.default voidonStart()This method is called right before start.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.
-
-
-
Method Detail
-
onStart
default void onStart()
This method is called right before start. Override it to add extra initialization.
-
onShutdown
default void onShutdown()
This method is called right after shutdown. Override it to add extra cleanup.
-
getPort
int getPort()
The port for theMockWebServer.- Returns:
- the MockWebServer port.
-
getHostName
String getHostName()
The host name for theMockWebServer.- Returns:
- the MockWebServer host name;
-
toProxyAddress
Proxy toProxyAddress()
Returns aProxyfor theMockWebServerwith the current HostName and Port.- Returns:
- a Proxy for the MockWebServer.
-
getSelfSignedCertificate
io.vertx.core.net.SelfSignedCertificate getSelfSignedCertificate()
Returns theSelfSignedCertificatefor the Mock Web Server.- Returns:
- the SelfSignedCertificate for the MockWebServer.
-
url
String url(String path)
Returns a String URL for connecting to this server.- Parameters:
path- the request path, such as "/".
-
expect
MockServerExpectation expect()
Returns aMockServerExpectationto set the expectations.- Returns:
- the MockServerExpectation builder.
-
getRequestCount
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.
-
takeRequest
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.- Returns:
- the head of the request queue
- Throws:
InterruptedException
-
takeRequest
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.- 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
RecordedRequest getLastRequest() throws InterruptedException
Returns the last (most recent) HTTP request processed by theMockWebServer. n.b. This method clears the request queue.- Returns:
- the most recent RecordedRequest or null if none was processed.
- Throws:
InterruptedException
-
-