Class KubernetesMockServer
- java.lang.Object
-
- io.fabric8.mockwebserver.DefaultMockServer
-
- io.fabric8.kubernetes.client.server.mock.KubernetesMockServer
-
- All Implemented Interfaces:
CustomResourceAware
,Resetable
,MockServer
public class KubernetesMockServer extends DefaultMockServer implements Resetable, CustomResourceAware
-
-
Constructor Summary
Constructors Constructor Description KubernetesMockServer()
KubernetesMockServer(boolean useHttps)
KubernetesMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
KubernetesMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps)
KubernetesMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps, io.fabric8.kubernetes.client.VersionInfo versionInfo)
KubernetesMockServer(MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearExpectations()
Removes all recorded expectations.io.fabric8.kubernetes.client.NamespacedKubernetesClient
createClient()
io.fabric8.kubernetes.client.NamespacedKubernetesClient
createClient(io.fabric8.kubernetes.client.http.HttpClient.Factory factory)
io.fabric8.kubernetes.client.NamespacedKubernetesClient
createClient(Consumer<io.fabric8.kubernetes.client.KubernetesClientBuilder> kubernetesClientBuilderCustomizer)
Creates a client using the cusotmizedKubernetesClientBuilder
provided in theConsumer
parameter.void
destroy()
void
expectCustomResource(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext rdc)
Ensure that the server will supply anAPIResourceList
containing anAPIResource
representing theCustomResourceDefinitionContext
from the apis/group/version endpoint.String[]
getRootPaths()
void
init()
void
init(InetAddress address, int port)
protected io.fabric8.kubernetes.client.Config
initConfig()
void
onStart()
void
reset()
return the resource to its initial statevoid
setUnsupported(String... unsupported)
Used to exclude support for the given apiGroups.void
setVersionInfo(io.fabric8.kubernetes.client.VersionInfo versionInfo)
Replace the currentVersionInfo
instance.-
Methods inherited from class io.fabric8.mockwebserver.DefaultMockServer
expect, getHostName, getLastRequest, getPort, getRequestCount, getSelfSignedCertificate, shutdown, start, start, start, takeRequest, takeRequest, toProxyAddress, url
-
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
-
-
-
-
Constructor Detail
-
KubernetesMockServer
public KubernetesMockServer()
-
KubernetesMockServer
public KubernetesMockServer(boolean useHttps)
-
KubernetesMockServer
public KubernetesMockServer(MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
-
KubernetesMockServer
public KubernetesMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, boolean useHttps)
-
KubernetesMockServer
public KubernetesMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps)
-
KubernetesMockServer
public KubernetesMockServer(Context context, MockWebServer server, Map<ServerRequest,Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps, io.fabric8.kubernetes.client.VersionInfo versionInfo)
-
-
Method Detail
-
onStart
public void onStart()
- Specified by:
onStart
in interfaceMockServer
-
init
public void init()
-
init
public void init(InetAddress address, int port)
-
destroy
public void destroy()
-
getRootPaths
public String[] getRootPaths()
-
createClient
public io.fabric8.kubernetes.client.NamespacedKubernetesClient createClient()
-
createClient
public io.fabric8.kubernetes.client.NamespacedKubernetesClient createClient(io.fabric8.kubernetes.client.http.HttpClient.Factory factory)
-
createClient
public io.fabric8.kubernetes.client.NamespacedKubernetesClient createClient(Consumer<io.fabric8.kubernetes.client.KubernetesClientBuilder> kubernetesClientBuilderCustomizer)
Creates a client using the cusotmizedKubernetesClientBuilder
provided in theConsumer
parameter.The function is invoked using an initial
Config
instance that is initialized with the mock server's URL and theTlsVersion
to use.The following snippet shows how you can use this method in your tests:
@BeforeEach void setUp() { server = new KubernetesMockServer(); server.start(); client = server.createClient(b -> {/* customize builder */})); } }
- Parameters:
kubernetesClientBuilderCustomizer
- Consumer function to enable further customization of the provided KubernetesClientBuilder.- Returns:
- a NamespacedKubernetesClient instance from the provided configuration.
-
setVersionInfo
public final void setVersionInfo(io.fabric8.kubernetes.client.VersionInfo versionInfo)
Replace the currentVersionInfo
instance.- Parameters:
versionInfo
- the new VersionInfo.
-
setUnsupported
public void setUnsupported(String... unsupported)
Used to exclude support for the given apiGroups.
Each is a simple expression of the form: group[/version]
where * is a wildcard.
For example to exclude all openshift support, you would specify openshift.io
To exclude a specific apiVersion, you would fully specify route.openshift.io/v1NOTE this affects calls to
Client.hasApiGroup(String, boolean)
andClient.supports(Class)
. Other calls to get the full root path or other api group metadata will not return valid results in mock scenarios.- Parameters:
unsupported
- apiGroup patterns
-
clearExpectations
public void clearExpectations()
Removes all recorded expectations.
-
initConfig
protected io.fabric8.kubernetes.client.Config initConfig()
-
reset
public void reset()
Description copied from interface:Resetable
return the resource to its initial state
-
expectCustomResource
public void expectCustomResource(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext rdc)
Ensure that the server will supply anAPIResourceList
containing anAPIResource
representing theCustomResourceDefinitionContext
from the apis/group/version endpoint.This is useful when testing calls through the
KubernetesClient.genericKubernetesResources(String, String)
entry point.If this is a crud server, the custom resource will be added to the set of previously added resources and the resources inferred from custom resource definitions that have been added.
If this server is not crud, this call will add a single expectation for the given resource. Direct handling of multiple resources for a given api group/version has not yet been added.
- Specified by:
expectCustomResource
in interfaceCustomResourceAware
- Parameters:
rdc
- the resource definition context
-
-