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