use of io.fabric8.patch.Service in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testInitWhileExternalTokenFileNameNotGiven.
@Test(description = "Test init method when external service account token file name is NOT given")
public void testInitWhileExternalTokenFileNameNotGiven() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
try {
sdKubernetes.initImpl(createImplParametersMap(""));
} catch (ServiceDiscoveryException e) {
// since pod's token is then searched, this is exception msg we get
Assert.assertEquals(e.getCause().getMessage(), "Error while reading file /var/run/secrets/kubernetes.io/serviceaccount/token");
}
}
use of io.fabric8.patch.Service in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method createMalformedServiceList.
/**
* Create ServiceList with the given port type, but without a loadBalancer ingress
*
* @param portType http or https or a wrong port to check behavior
* @return ServiceList containing one service of LoadBalancer type
*/
private ServiceList createMalformedServiceList(String portType) {
ServicePort port = new ServicePortBuilder().withName(portType).withPort(80).withNodePort(30005).build();
Service malformedService5 = new ServiceBuilder().withNewMetadata().withName("service5").withNamespace("prod").and().withNewSpec().withType("LoadBalancer").withClusterIP("1.1.1.5").withPorts(port).and().withNewStatus().withNewLoadBalancer().endLoadBalancer().and().build();
List<Service> servicesList = new ArrayList<>();
servicesList.add(malformedService5);
return new ServiceListBuilder().withItems(servicesList).build();
}
use of io.fabric8.patch.Service 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.patch.Service 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);
}
}
use of io.fabric8.patch.Service in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method createService.
/**
* Create Service resource
*
* @param openShiftClient Openshift client
* @param nonNamespaceOperation NonNamespaceOperation instance
*/
private Service createService(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation) {
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withName(serviceName)).thenReturn(baseOperation);
Mockito.when(baseOperation.get()).thenReturn(null);
Service service = Mockito.mock(Service.class, Mockito.RETURNS_DEEP_STUBS);
return service;
}
Aggregations