use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithBothNamespaceAndCriteria.
@Test(description = "Test .listServices(Namespace, Criteria) method")
public void testListServicesWithBothNamespaceAndCriteria() 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);
Map<String, String> oneLabel = createOneLabelHashMap();
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabels(oneLabel)).thenReturn(baseOperation);
Mockito.when(baseOperation.list()).thenReturn(createServiceListWithBothNamespaceAndCriteria());
List<Endpoint> endpoints = sdKubernetes.listServices("dev", oneLabel);
Assert.assertEquals(endpoints.size(), 2);
}
use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithoutCLusterIPAndExternalName.
@Test(description = "Test .listServices() method without ClusterIPs and ExternalNamesURLs")
public void testListServicesWithoutCLusterIPAndExternalName() 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(createServiceList());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertEquals(endpoints.size(), 5);
Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithNamespace.
@Test(description = "Test .listServices(Namespace) method")
public void testListServicesWithNamespace() 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);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceListWithNamespace());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices("dev");
Assert.assertEquals(endpoints.size(), 4);
}
use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateIngressResourceForInvalidResource.
@Test
public void testCreateIngressResourceForInvalidResource() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
Mockito.when(scalableResource.get()).thenReturn(null);
HasMetadata invalidMetadata = Mockito.mock(Deployment.class);
List<HasMetadata> ingressResources = new ArrayList<>();
ingressResources.add(invalidMetadata);
Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), getDeploymentResources(), ingressResources);
Service service = createService(openShiftClient, nonNamespaceOperation);
Deployment deployment = createDeployment(openShiftClient, nonNamespaceOperation, scalableResource);
Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment);
API api = SampleTestObjectCreator.createDefaultAPI().build();
try {
kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
} catch (ContainerBasedGatewayException e) {
Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
}
}
use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateIngressResourceForKubernetesException.
@Test
public void testCreateIngressResourceForKubernetesException() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), getDeploymentResources(), getIngressResources());
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
Mockito.when(scalableResource.get()).thenReturn(null);
Service service = createService(openShiftClient, nonNamespaceOperation);
Deployment deployment = createDeployment(openShiftClient, nonNamespaceOperation, scalableResource);
Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment);
ScalableResource scalableResourceIngress = Mockito.mock(ScalableResource.class);
String ingressName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withName(ingressName)).thenReturn(scalableResourceIngress);
Mockito.when(scalableResourceIngress.get()).thenThrow(KubernetesClientException.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
try {
kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
} catch (ContainerBasedGatewayException e) {
Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
}
}
Aggregations