java.lang.Object
org.mockserver.client.MockServerClient.Builder
- Enclosing class:
- MockServerClient
Fluent builder for
MockServerClient.
Covers every dimension exposed by the MockServerClient constructors and
with... setters:
configuration(ClientConfiguration)/configuration(Configuration)host(String)(default"localhost")port(int)(default1080)contextPath(String)(default empty)portFuture(CompletableFuture)(mutually exclusive with host/port/contextPath)secure(boolean)— TLS, delegates toMockServerClient.withSecure(boolean)proxyConfiguration(ProxyConfiguration)— delegates toMockServerClient.withProxyConfiguration(ProxyConfiguration)controlPlaneJWT(String)/controlPlaneJWT(Supplier)— delegates toMockServerClient.withControlPlaneJWT(Supplier)controlPlaneBasicAuthentication(String, String)— delegates toMockServerClient.withControlPlaneBasicAuthentication(String, String)requestOverride(HttpRequest)— delegates toMockServerClient.withRequestOverride(HttpRequest)
build() is called, at which
point it selects the matching constructor and applies the configured setters, so the
resulting client is identical to one built directly. Validation (for example, the
empty-host check) is inherited from the constructors and surfaces from build().-
Method Summary
Modifier and TypeMethodDescriptionbuild()Build theMockServerClient, selecting the matching constructor and applying the configuredwith...setters.configuration(org.mockserver.configuration.ClientConfiguration configuration) Use the givenClientConfiguration.configuration(org.mockserver.configuration.Configuration configuration) Use the givenConfiguration, wrapped as aClientConfiguration(the same conversion theMockServerClient(Configuration, ...)constructors perform).contextPath(String contextPath) The context path that the MockServer war is deployed to.controlPlaneBasicAuthentication(String username, String password) HTTP Basic credentials for control plane authentication.controlPlaneJWT(String controlPlaneJWT) A fixed JWT for control plane authorisation.controlPlaneJWT(Supplier<String> controlPlaneJWTSupplier) A JWT supplier for control plane authorisation.The host of the MockServer to communicate with.port(int port) The port of the MockServer to communicate with.portFuture(CompletableFuture<Integer> portFuture) Resolve the port lazily from aCompletableFuture, for use when the MockServer port is not yet known at client-construction time.proxyConfiguration(org.mockserver.proxyconfiguration.ProxyConfiguration proxyConfiguration) Route communication to MockServer via a proxy.requestOverride(org.mockserver.model.HttpRequest requestOverride) A request override applied to every control plane request.secure(boolean secure) Whether to communicate with MockServer over TLS.
-
Method Details
-
configuration
public MockServerClient.Builder configuration(org.mockserver.configuration.ClientConfiguration configuration) Use the givenClientConfiguration. Whennullthe client falls back to the default configuration, matching the constructors' behaviour. -
configuration
public MockServerClient.Builder configuration(org.mockserver.configuration.Configuration configuration) Use the givenConfiguration, wrapped as aClientConfiguration(the same conversion theMockServerClient(Configuration, ...)constructors perform). -
host
The host of the MockServer to communicate with. Defaults to"localhost". -
port
The port of the MockServer to communicate with. Defaults to1080. -
contextPath
The context path that the MockServer war is deployed to. Defaults to empty. -
portFuture
Resolve the port lazily from aCompletableFuture, for use when the MockServer port is not yet known at client-construction time. This is mutually exclusive withhost(String),port(int)andcontextPath(String): the future-based constructor always communicates withlocalhostusing an empty context path. -
secure
Whether to communicate with MockServer over TLS. Delegates toMockServerClient.withSecure(boolean). -
proxyConfiguration
public MockServerClient.Builder proxyConfiguration(org.mockserver.proxyconfiguration.ProxyConfiguration proxyConfiguration) Route communication to MockServer via a proxy. Delegates toMockServerClient.withProxyConfiguration(ProxyConfiguration). -
controlPlaneJWT
A fixed JWT for control plane authorisation. Delegates toMockServerClient.withControlPlaneJWT(String). -
controlPlaneJWT
A JWT supplier for control plane authorisation. Delegates toMockServerClient.withControlPlaneJWT(Supplier). -
controlPlaneBasicAuthentication
HTTP Basic credentials for control plane authentication. Delegates toMockServerClient.withControlPlaneBasicAuthentication(String, String). -
requestOverride
A request override applied to every control plane request. Delegates toMockServerClient.withRequestOverride(HttpRequest). -
build
Build theMockServerClient, selecting the matching constructor and applying the configuredwith...setters. Constructor validation (such as the empty-host check) surfaces from here.- Throws:
IllegalArgumentException- ifportFuture(CompletableFuture)is combined with an explicit host, port or context path, or if a constructor rejects the supplied values
-