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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations