Class KubernetesMockServer

    • Constructor Summary

      Constructors 
      Constructor Description
      KubernetesMockServer()  
      KubernetesMockServer​(boolean useHttps)  
      KubernetesMockServer​(io.fabric8.mockwebserver.Context context, io.fabric8.mockwebserver.MockWebServer server, Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses, boolean useHttps)  
      KubernetesMockServer​(io.fabric8.mockwebserver.Context context, io.fabric8.mockwebserver.MockWebServer server, Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses, io.fabric8.mockwebserver.http.Dispatcher dispatcher, boolean useHttps)  
      KubernetesMockServer​(io.fabric8.mockwebserver.Context context, io.fabric8.mockwebserver.MockWebServer server, Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses, io.fabric8.mockwebserver.http.Dispatcher dispatcher, boolean useHttps, io.fabric8.kubernetes.client.VersionInfo versionInfo)  
      KubernetesMockServer​(io.fabric8.mockwebserver.MockWebServer server, Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.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 customized KubernetesClientBuilder provided in the Consumer parameter.
      void destroy()  
      void expectCustomResource​(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext rdc)
      Ensure that the server will supply an APIResourceList containing an APIResource representing the CustomResourceDefinitionContext 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 state
      void setUnsupported​(String... unsupported)
      Used to exclude support for the given apiGroups.
      void setVersionInfo​(io.fabric8.kubernetes.client.VersionInfo versionInfo)
      Replace the current VersionInfo 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 interface io.fabric8.mockwebserver.MockServer

        onShutdown
    • Constructor Detail

      • KubernetesMockServer

        public KubernetesMockServer()
      • KubernetesMockServer

        public KubernetesMockServer​(boolean useHttps)
      • KubernetesMockServer

        public KubernetesMockServer​(io.fabric8.mockwebserver.MockWebServer server,
                                    Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses,
                                    boolean useHttps)
      • KubernetesMockServer

        public KubernetesMockServer​(io.fabric8.mockwebserver.Context context,
                                    io.fabric8.mockwebserver.MockWebServer server,
                                    Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses,
                                    boolean useHttps)
      • KubernetesMockServer

        public KubernetesMockServer​(io.fabric8.mockwebserver.Context context,
                                    io.fabric8.mockwebserver.MockWebServer server,
                                    Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses,
                                    io.fabric8.mockwebserver.http.Dispatcher dispatcher,
                                    boolean useHttps)
      • KubernetesMockServer

        public KubernetesMockServer​(io.fabric8.mockwebserver.Context context,
                                    io.fabric8.mockwebserver.MockWebServer server,
                                    Map<io.fabric8.mockwebserver.ServerRequest,​Queue<io.fabric8.mockwebserver.ServerResponse>> responses,
                                    io.fabric8.mockwebserver.http.Dispatcher dispatcher,
                                    boolean useHttps,
                                    io.fabric8.kubernetes.client.VersionInfo versionInfo)
    • Method Detail

      • onStart

        public void onStart()
        Specified by:
        onStart in interface io.fabric8.mockwebserver.MockServer
      • 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 customized KubernetesClientBuilder provided in the Consumer parameter.

        The function is invoked using an initial Config instance that is initialized with the mock server's URL and the TlsVersion 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 current VersionInfo 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/v1

        NOTE this affects calls to Client.hasApiGroup(String, boolean) and Client.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
        Specified by:
        reset in interface Resetable
        Overrides:
        reset in class io.fabric8.mockwebserver.DefaultMockServer
      • expectCustomResource

        public void expectCustomResource​(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext rdc)
        Ensure that the server will supply an APIResourceList containing an APIResource representing the CustomResourceDefinitionContext 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 interface CustomResourceAware
        Parameters:
        rdc - the resource definition context