Search in sources :

Example 6 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse in project kafka-rest by confluentinc.

the class TopicsResourceIntegrationTest method listTopics_existingCluster_returnsTopics.

@Test
public void listTopics_existingCluster_returnsTopics() {
    String baseUrl = restConnect;
    String clusterId = getClusterId();
    ListTopicsResponse expected = ListTopicsResponse.create(TopicDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics").build()).setData(Arrays.asList(TopicData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1).setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_1).build()).setClusterId(clusterId).setTopicName(TOPIC_1).setInternal(false).setReplicationFactor(1).setPartitionsCount(1).setPartitions(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/partitions")).setConfigs(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/configs")).setPartitionReassignments(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/partitions/-/reassignment")).setAuthorizedOperations(emptySet()).build(), TopicData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_2).setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_2).build()).setClusterId(clusterId).setTopicName(TOPIC_2).setInternal(false).setReplicationFactor(1).setPartitionsCount(1).setPartitions(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_2 + "/partitions")).setConfigs(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_2 + "/configs")).setPartitionReassignments(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_2 + "/partitions/-/reassignment")).setAuthorizedOperations(emptySet()).build(), TopicData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_3).setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_3).build()).setClusterId(clusterId).setTopicName(TOPIC_3).setInternal(false).setReplicationFactor(1).setPartitionsCount(1).setPartitions(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_3 + "/partitions")).setConfigs(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_3 + "/configs")).setPartitionReassignments(Resource.Relationship.create(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_3 + "/partitions/-/reassignment")).setAuthorizedOperations(emptySet()).build())).build());
    testWithRetry(() -> {
        Response response = request("/v3/clusters/" + clusterId + "/topics").accept(MediaType.APPLICATION_JSON).get();
        assertEquals(Status.OK.getStatusCode(), response.getStatus());
        ListTopicsResponse actual = response.readEntity(ListTopicsResponse.class);
        assertEquals(expected, actual);
    });
}
Also used : GetTopicResponse(io.confluent.kafkarest.entities.v3.GetTopicResponse) CreateTopicResponse(io.confluent.kafkarest.entities.v3.CreateTopicResponse) GetTopicConfigResponse(io.confluent.kafkarest.entities.v3.GetTopicConfigResponse) ListTopicsResponse(io.confluent.kafkarest.entities.v3.ListTopicsResponse) Response(javax.ws.rs.core.Response) ListTopicsResponse(io.confluent.kafkarest.entities.v3.ListTopicsResponse) Test(org.junit.jupiter.api.Test)

Example 7 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse in project java-pubsub by googleapis.

the class TopicAdminClientTest method listTopicsTest2.

@Test
public void listTopicsTest2() throws Exception {
    Topic responsesElement = Topic.newBuilder().build();
    ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder().setNextPageToken("").addAllTopics(Arrays.asList(responsesElement)).build();
    mockPublisher.addResponse(expectedResponse);
    String project = "project-309310695";
    ListTopicsPagedResponse pagedListResponse = client.listTopics(project);
    List<Topic> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTopicsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTopicsRequest actualRequest = ((ListTopicsRequest) actualRequests.get(0));
    Assert.assertEquals(project, actualRequest.getProject());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListTopicsPagedResponse(com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) ByteString(com.google.protobuf.ByteString) Topic(com.google.pubsub.v1.Topic) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse) Test(org.junit.Test)

Aggregations

ListTopicsRequest (com.google.pubsub.v1.ListTopicsRequest)5 ListTopicsResponse (com.google.pubsub.v1.ListTopicsResponse)5 Topic (com.google.pubsub.v1.Topic)4 Test (org.junit.Test)3 ListTopicsPagedResponse (com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 ProjectName (com.google.pubsub.v1.ProjectName)2 ListTopicsResponse (io.confluent.kafkarest.entities.v3.ListTopicsResponse)2 Test (org.junit.jupiter.api.Test)2 ListTopicsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 CreateTopicResponse (io.confluent.kafkarest.entities.v3.CreateTopicResponse)1 GetTopicConfigResponse (io.confluent.kafkarest.entities.v3.GetTopicConfigResponse)1 GetTopicResponse (io.confluent.kafkarest.entities.v3.GetTopicResponse)1 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1