Search in sources :

Example 1 with KafkaTopicList

use of io.strimzi.api.kafka.KafkaTopicList in project strimzi by strimzi.

the class K8sImplTest method testList.

@Test
public void testList(VertxTestContext context) {
    Checkpoint async = context.checkpoint();
    List<KafkaTopic> mockKafkaTopicsList = Collections.singletonList(new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("unrelated").withLabels(Collections.singletonMap("foo", "bar")).build()).build());
    KubernetesClient mockClient = mock(KubernetesClient.class);
    MixedOperation<KafkaTopic, KafkaTopicList, Resource<KafkaTopic>> mockResources = mock(MixedOperation.class);
    when(mockClient.resources(any(Class.class), any(Class.class))).thenReturn(mockResources);
    when(mockClient.resources(any(Class.class), any(Class.class))).thenReturn(mockResources);
    when(mockResources.withLabels(any())).thenReturn(mockResources);
    when(mockResources.inNamespace(any())).thenReturn(mockResources);
    when(mockResources.list()).thenAnswer(invocation -> {
        KafkaTopicList ktl = new KafkaTopicList();
        ktl.setItems(mockKafkaTopicsList);
        return ktl;
    });
    K8sImpl k8s = new K8sImpl(vertx, mockClient, new Labels("foo", "bar"), "default");
    k8s.listResources().onComplete(context.succeeding(kafkaTopics -> context.verify(() -> {
        assertThat(kafkaTopics, is(mockKafkaTopicsList));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Resource(io.fabric8.kubernetes.client.dsl.Resource) List(java.util.List) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaTopicList(io.strimzi.api.kafka.KafkaTopicList) BeforeAll(org.junit.jupiter.api.BeforeAll) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Mockito.mock(org.mockito.Mockito.mock) KafkaTopicList(io.strimzi.api.kafka.KafkaTopicList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Resource(io.fabric8.kubernetes.client.dsl.Resource) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Checkpoint(io.vertx.junit5.Checkpoint) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with KafkaTopicList

use of io.strimzi.api.kafka.KafkaTopicList in project strimzi-kafka-operator by strimzi.

the class K8sImplTest method testList.

@Test
public void testList(VertxTestContext context) {
    Checkpoint async = context.checkpoint();
    List<KafkaTopic> mockKafkaTopicsList = Collections.singletonList(new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("unrelated").withLabels(Collections.singletonMap("foo", "bar")).build()).build());
    KubernetesClient mockClient = mock(KubernetesClient.class);
    MixedOperation<KafkaTopic, KafkaTopicList, Resource<KafkaTopic>> mockResources = mock(MixedOperation.class);
    when(mockClient.resources(any(Class.class), any(Class.class))).thenReturn(mockResources);
    when(mockClient.resources(any(Class.class), any(Class.class))).thenReturn(mockResources);
    when(mockResources.withLabels(any())).thenReturn(mockResources);
    when(mockResources.inNamespace(any())).thenReturn(mockResources);
    when(mockResources.list()).thenAnswer(invocation -> {
        KafkaTopicList ktl = new KafkaTopicList();
        ktl.setItems(mockKafkaTopicsList);
        return ktl;
    });
    K8sImpl k8s = new K8sImpl(vertx, mockClient, new Labels("foo", "bar"), "default");
    k8s.listResources().onComplete(context.succeeding(kafkaTopics -> context.verify(() -> {
        assertThat(kafkaTopics, is(mockKafkaTopicsList));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Resource(io.fabric8.kubernetes.client.dsl.Resource) List(java.util.List) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaTopicList(io.strimzi.api.kafka.KafkaTopicList) BeforeAll(org.junit.jupiter.api.BeforeAll) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Mockito.mock(org.mockito.Mockito.mock) KafkaTopicList(io.strimzi.api.kafka.KafkaTopicList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Resource(io.fabric8.kubernetes.client.dsl.Resource) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Checkpoint(io.vertx.junit5.Checkpoint) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 KafkaTopicList (io.strimzi.api.kafka.KafkaTopicList)2 KafkaTopic (io.strimzi.api.kafka.model.KafkaTopic)2 KafkaTopicBuilder (io.strimzi.api.kafka.model.KafkaTopicBuilder)2 Vertx (io.vertx.core.Vertx)2 Checkpoint (io.vertx.junit5.Checkpoint)2 VertxExtension (io.vertx.junit5.VertxExtension)2 VertxTestContext (io.vertx.junit5.VertxTestContext)2 Collections (java.util.Collections)2 List (java.util.List)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.is (org.hamcrest.Matchers.is)2 AfterAll (org.junit.jupiter.api.AfterAll)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Test (org.junit.jupiter.api.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2