use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testRemoveContainerBasedGateway.
@Test
public void testRemoveContainerBasedGateway() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabel(Mockito.anyString(), Mockito.anyString())).thenReturn(baseOperation);
Mockito.when(baseOperation.delete()).thenReturn(true);
Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
API api = SampleTestObjectCreator.createDefaultAPI().build();
kubernetesGateway.removeContainerBasedGateway("label", api);
Mockito.verify(openShiftClient, Mockito.times(2)).services();
Mockito.verify(openShiftClient, Mockito.times(4)).extensions();
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithWrongPortType.
@Test(description = "Test .listServices() while the list has only one service and its port is not http nor https")
public void testListServicesWithWrongPortType() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Include ExternalNames (includeClusterIP not checked)
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createMalformedServiceList("somePort"));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertTrue(endpoints.isEmpty());
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesOfLoadBalancerTypeWithoutIngress.
@Test(description = "Test .listServices() while the list only has a LoadBalancer type service without any ingress")
public void testListServicesOfLoadBalancerTypeWithoutIngress() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Not include ClusterIPs
sdKubernetes.setIncludeClusterIP(false);
// Not include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(false);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createMalformedServiceList("http"));
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertEquals(endpoints.size(), 1);
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation 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);
}
use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServices.
@Test(description = "Test .listServices() method")
public void testListServices() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Include ClusterIPs
sdKubernetes.setIncludeClusterIP(true);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceList());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertEquals(endpoints.size(), 10);
// 2 NodePort URL endpoints
Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
Aggregations