Search in sources :

Example 26 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation 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 27 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation 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 28 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation 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)

Example 29 with MixedOperation

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

the class StatefulSetOperatorTest method mocker.

@Override
protected void mocker(KubernetesClient mockClient, MixedOperation op) {
    AppsAPIGroupDSL mockExt = mock(AppsAPIGroupDSL.class);
    when(mockExt.statefulSets()).thenReturn(op);
    when(mockClient.apps()).thenReturn(mockExt);
}
Also used : AppsAPIGroupDSL(io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL)

Example 30 with MixedOperation

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

the class K8sImplTest method testList.

@Test
public void testList(TestContext context) {
    Async async = context.async();
    KubernetesClient mockClient = mock(KubernetesClient.class);
    MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> mockConfigMaps = mock(MixedOperation.class);
    when(mockClient.configMaps()).thenReturn(mockConfigMaps);
    when(mockConfigMaps.withLabels(any())).thenReturn(mockConfigMaps);
    when(mockConfigMaps.inNamespace(any())).thenReturn(mockConfigMaps);
    when(mockConfigMaps.list()).thenReturn(new ConfigMapListBuilder().addNewItem().withKind("ConfigMap").withNewMetadata().withName("unrelated").withLabels(Collections.singletonMap("foo", "bar")).endMetadata().withData(Collections.singletonMap("foo", "bar")).endItem().addNewItem().endItem().build());
    K8sImpl k8s = new K8sImpl(vertx, mockClient, new LabelPredicate("foo", "bar"), "default");
    k8s.listMaps(ar -> {
        List<ConfigMap> list = ar.result();
        context.assertFalse(list.isEmpty());
        async.complete();
    });
}
Also used : ConfigMapList(io.fabric8.kubernetes.api.model.ConfigMapList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) ConfigMapListBuilder(io.fabric8.kubernetes.api.model.ConfigMapListBuilder) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) Test(org.junit.Test)

Aggregations

Resource (io.fabric8.kubernetes.client.dsl.Resource)21 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)15 Async (io.vertx.ext.unit.Async)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 Test (org.junit.Test)12 Map (java.util.Map)10 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 DeploymentList (io.fabric8.kubernetes.api.model.extensions.DeploymentList)4 DoneableDeployment (io.fabric8.kubernetes.api.model.extensions.DoneableDeployment)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)3 DoneableConfigMap (io.fabric8.kubernetes.api.model.DoneableConfigMap)3 DoneablePersistentVolumeClaim (io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim)3 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)3 DoneableService (io.fabric8.kubernetes.api.model.DoneableService)3 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)3 PersistentVolumeClaimList (io.fabric8.kubernetes.api.model.PersistentVolumeClaimList)3 Pod (io.fabric8.kubernetes.api.model.Pod)3