Search in sources :

Example 56 with KafkaTopicBuilder

use of io.strimzi.api.kafka.model.KafkaTopicBuilder 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

KafkaTopicBuilder (io.strimzi.api.kafka.model.KafkaTopicBuilder)56 KafkaTopic (io.strimzi.api.kafka.model.KafkaTopic)54 Test (org.junit.jupiter.api.Test)40 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)22 Checkpoint (io.vertx.junit5.Checkpoint)22 NewTopic (org.apache.kafka.clients.admin.NewTopic)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 KafkaTopicList (io.strimzi.api.kafka.KafkaTopicList)2 KafkaTopicStatusBuilder (io.strimzi.api.kafka.model.status.KafkaTopicStatusBuilder)2 Vertx (io.vertx.core.Vertx)2 VertxExtension (io.vertx.junit5.VertxExtension)2 VertxTestContext (io.vertx.junit5.VertxTestContext)2 File (java.io.File)2