use of io.fabric8.kubernetes.api.model.Service in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateDeploymentResourceForInvalidResource.
@Test
public void testCreateDeploymentResourceForInvalidResource() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
HasMetadata invalidMetadata = Mockito.mock(Service.class);
List<HasMetadata> deploymentResources = new ArrayList<>();
deploymentResources.add(invalidMetadata);
Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), deploymentResources);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
Mockito.when(scalableResource.get()).thenReturn(null);
Service service = createService(openShiftClient, nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service);
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.kubernetes.api.model.Service 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.api.model.Service 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.api.model.Service in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testInitWhileExternalTokenFileNameGiven.
@Test(description = "Test init method with external service account token file name")
public void testInitWhileExternalTokenFileNameGiven() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
try {
sdKubernetes.initImpl(createImplParametersMap("TestK8Token"));
} catch (ServiceDiscoveryException e) {
Assert.assertEquals(e.getCause().getMessage(), "File to decrypt does not exist");
}
}
Aggregations