Search in sources :

Example 6 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 7 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method getIngressResources.

/**
 * Get ingress resources
 *
 * @return List<HasMetadata> list of ingress resources
 */
private List<HasMetadata> getIngressResources() {
    HasMetadata ingressMetadata = Mockito.mock(Ingress.class);
    List<HasMetadata> ingressResources = new ArrayList<>();
    ingressResources.add(ingressMetadata);
    return ingressResources;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList)

Example 8 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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 9 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateServiceResourceForInvalidResource.

@Test
public void testCreateServiceResourceForInvalidResource() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    HasMetadata invalidMetadata = Mockito.mock(Deployment.class);
    List<HasMetadata> serviceResources = new ArrayList<>();
    serviceResources.add(invalidMetadata);
    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.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
    }
}
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 10 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)10 ArrayList (java.util.ArrayList)7 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)7 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)4 Test (org.junit.Test)4 API (org.wso2.carbon.apimgt.core.models.API)4 Service (io.fabric8.kubernetes.api.model.Service)3 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)2 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)2 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)2 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)1