Search in sources :

Example 6 with BaseOperation

use of io.fabric8.kubernetes.client.dsl.base.BaseOperation in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testListServicesWithCriteria.

@Test(description = "Test .listServices(Criteria) method")
public void testListServicesWithCriteria() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    // Include ClusterIPs
    sdKubernetes.setIncludeClusterIP(true);
    // Not include ExternalNames
    sdKubernetes.setIncludeExternalNameTypeServices(false);
    Map<String, String> oneLabel = createOneLabelHashMap();
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
    Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withLabels(oneLabel)).thenReturn(baseOperation);
    Mockito.when(baseOperation.list()).thenReturn(createServiceListWithCriteria());
    Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
    List<Endpoint> endpoints = sdKubernetes.listServices(oneLabel);
    Assert.assertEquals(endpoints.size(), 3);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)5 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)5 Test (org.junit.Test)3 API (org.wso2.carbon.apimgt.core.models.API)3 Service (io.fabric8.kubernetes.api.model.Service)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)1 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)1 URL (java.net.URL)1 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)1