Search in sources :

Example 11 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createDeployment.

/**
 * Create Deployment resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 * @param scalableResource      ScalableResource instance
 */
private Deployment createDeployment(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
    String deploymentName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_DEPLOYMENT_SUFFIX;
    Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(deploymentName)).thenReturn(scalableResource);
    Deployment deployment = Mockito.mock(Deployment.class, Mockito.RETURNS_DEEP_STUBS);
    return deployment;
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Example 12 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient 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;
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation)

Example 13 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createIngress.

/**
 * Create Ingress resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 * @param scalableResource      ScalableResource instance
 */
private Ingress createIngress(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
    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(scalableResource);
    Ingress ingress = Mockito.mock(Ingress.class, Mockito.RETURNS_DEEP_STUBS);
    return ingress;
}
Also used : Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress)

Example 14 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testGetResourcesFromTemplateWhenResourceIsEmpty.

@Test
public void testGetResourcesFromTemplateWhenResourceIsEmpty() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    List<HasMetadata> serviceResources = new ArrayList<>();
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(serviceResources);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.NO_RESOURCE_LOADED_FROM_DEFINITION);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 15 with OpenShiftClient

use of io.fabric8.openshift.client.OpenShiftClient in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateServiceResourceForKubernetesClientException.

@Test
public void testCreateServiceResourceForKubernetesClientException() 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());
    NonNamespaceOperation nonNamespaceOperationService = Mockito.mock(NonNamespaceOperation.class);
    BaseOperation baseOperationService = Mockito.mock(BaseOperation.class);
    String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
    Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperationService);
    Mockito.when(nonNamespaceOperationService.withName(serviceName)).thenReturn(baseOperationService);
    Mockito.when(baseOperationService.get()).thenThrow(KubernetesClientException.class);
    API api = SampleTestObjectCreator.createDefaultAPI().context("").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);
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Aggregations

OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)92 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)31 IOException (java.io.IOException)31 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)23 FileNotFoundException (java.io.FileNotFoundException)21 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)20 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)20 Test (org.junit.Test)17 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)16 JSONObject (org.json.JSONObject)16 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)15 Route (io.fabric8.openshift.api.model.Route)14 Service (io.fabric8.kubernetes.api.model.Service)12 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)12 API (org.wso2.carbon.apimgt.core.models.API)12 Controller (io.fabric8.kubernetes.api.Controller)11 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)10 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)9 BeforeTest (org.testng.annotations.BeforeTest)9