Search in sources :

Example 41 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method existenceCheckThrows.

@Test
public void existenceCheckThrows(TestContext context) {
    T resource = resource();
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenThrow(ex);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.createOrUpdate(resource).setHandler(ar -> {
        assertTrue(ar.failed());
        assertEquals(ex, ar.cause());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 42 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method deletionThrows.

@Test
public void deletionThrows(TestContext context) {
    T resource = resource();
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource);
    when(mockResource.delete()).thenThrow(ex);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.reconcile(resource.getMetadata().getNamespace(), resource.getMetadata().getName(), null).setHandler(ar -> {
        assertTrue(ar.failed());
        assertEquals(ex, ar.cause());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 43 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method deleteWhenResourceDoesNotExistIsANop.

@Test
public void deleteWhenResourceDoesNotExistIsANop(TestContext context) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.reconcile(resource.getMetadata().getNamespace(), resource.getMetadata().getName(), null).setHandler(ar -> {
        assertTrue(ar.succeeded());
        verify(mockResource).get();
        verify(mockResource, never()).delete();
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 44 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method successfulDeletion.

@Test
public void successfulDeletion(TestContext context) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.reconcile(resource.getMetadata().getNamespace(), resource.getMetadata().getName(), null).setHandler(ar -> {
        if (ar.failed())
            ar.cause().printStackTrace();
        assertTrue(ar.succeeded());
        verify(mockResource).delete();
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Aggregations

NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)28 Resource (io.fabric8.kubernetes.client.dsl.Resource)22 Test (org.junit.Test)19 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)13 Async (io.vertx.ext.unit.Async)13 Map (java.util.Map)12 Service (io.fabric8.kubernetes.api.model.Service)8 API (org.wso2.carbon.apimgt.core.models.API)8 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)7 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)5 URL (java.net.URL)5 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)5 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1