Search in sources :

Example 6 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenLabelsAreNull.

@Test
public void testDeleteAPIWhenLabelsAreNull() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(null).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 7 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testGetContainerBasedGatewayGeneratorForException.

@Test(expected = ContainerBasedGatewayException.class)
public void testGetContainerBasedGatewayGeneratorForException() throws ContainerBasedGatewayException, ConfigurationException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    ContainerBasedGatewayConfiguration containerBasedGatewayConfig = new ContainerBasedGatewayConfiguration();
    containerBasedGatewayConfig.setImplClass("org.wso2.invalid.class.name");
    Mockito.when(configProvider.getConfigurationObject(ContainerBasedGatewayConfiguration.class)).thenReturn(containerBasedGatewayConfig);
    ContainerBasedGatewayConfigBuilder.build(configProvider);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = apiGatewayPublisher.getContainerBasedGatewayGenerator();
    Assert.assertNotNull(containerBasedGatewayGenerator);
}
Also used : ContainerBasedGatewayConfiguration(org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) Test(org.junit.Test)

Example 8 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenAPIDoesNotHaveOwnGateway.

@Test
public void testDeleteAPIWhenAPIDoesNotHaveOwnGateway() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    List<String> labels = new ArrayList<>();
    labels.add("label");
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(false).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 9 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testCreateContainerGateway.

@Test
public void testCreateContainerGateway() throws ContainerBasedGatewayException, ConfigurationException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    apiGatewayPublisher.createContainerBasedGateway("label", api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(1)).createContainerGateway("label", api);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 10 with ContainerBasedGatewayException

use of org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateDeploymentResourceForKubernetesException.

@Test
public void testCreateDeploymentResourceForKubernetesException() 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());
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service);
    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);
    Mockito.when(scalableResource.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);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) 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

ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)18 Test (org.junit.Test)16 API (org.wso2.carbon.apimgt.core.models.API)15 ArrayList (java.util.ArrayList)9 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 Service (io.fabric8.kubernetes.api.model.Service)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)5 Broker (org.wso2.carbon.apimgt.core.api.Broker)5 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)4 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)2 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)1 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)1 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)1 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)1 LocalDateTime (java.time.LocalDateTime)1