@Test public void listConsumerGroups_returnsConsumerGroups() { expect(consumerGroupManager.listConsumerGroups(CLUSTER_ID)) .andReturn(completedFuture(Arrays.asList(CONSUMER_GROUPS))); replay(consumerGroupManager); FakeAsyncResponse response = new FakeAsyncResponse(); consumerGroupsResource.listConsumerGroups(response, CLUSTER_ID); ListConsumerGroupsResponse expected = ListConsumerGroupsResponse.create( ConsumerGroupDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf("/v3/clusters/cluster-1/consumer-groups") .build()) .setData( Arrays.asList( ConsumerGroupData.fromConsumerGroup(CONSUMER_GROUPS[0]) .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1") .setResourceName( "crn: .build()) .setCoordinator( Relationship.create("/v3/clusters/cluster-1/brokers/1")) .setConsumers( Relationship.create( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers")) .build(), ConsumerGroupData.fromConsumerGroup(CONSUMER_GROUPS[1]) .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/consumer-groups/consumer-group-2") .setResourceName( "crn: .build()) .setCoordinator( Relationship.create("/v3/clusters/cluster-1/brokers/2")) .setConsumers( Relationship.create( "/v3/clusters/cluster-1/consumer-groups/consumer-group-2" + "/consumers")) .build())) .build()); assertEquals(expected, response.getValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") public void listConsumerGroups( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListConsumerGroupsResponse> response = consumerGroupManager.get() .listConsumerGroups(clusterId) .thenApply( consumerGroups -> ListConsumerGroupsResponse.create( ConsumerGroupDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups")) .build()) .setData( consumerGroups.stream() .map( consumerGroup -> toConsumerGroupData(clusterId, consumerGroup)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
ConsumerGroupsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") public void listConsumerGroups( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListConsumerGroupsResponse> response = consumerGroupManager.get() .listConsumerGroups(clusterId) .thenApply( consumerGroups -> ListConsumerGroupsResponse.create( ConsumerGroupDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups")) .build()) .setData( consumerGroups.stream() .map( consumerGroup -> toConsumerGroupData(clusterId, consumerGroup)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
ConsumerGroupsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") public void listConsumerGroups( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListConsumerGroupsResponse> response = consumerGroupManager.get() .listConsumerGroups(clusterId) .thenApply( consumerGroups -> ListConsumerGroupsResponse.create( ConsumerGroupDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups")) .build()) .setData( consumerGroups.stream() .map( consumerGroup -> toConsumerGroupData(clusterId, consumerGroup)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ConsumerGroupsResource(
      Provider<ConsumerGroupManager> consumerGroupManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory); }
ConsumerGroupsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") public void listConsumerGroups( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListConsumerGroupsResponse> response = consumerGroupManager.get() .listConsumerGroups(clusterId) .thenApply( consumerGroups -> ListConsumerGroupsResponse.create( ConsumerGroupDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups")) .build()) .setData( consumerGroups.stream() .map( consumerGroup -> toConsumerGroupData(clusterId, consumerGroup)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ConsumerGroupsResource(
      Provider<ConsumerGroupManager> consumerGroupManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") void listConsumerGroups(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{consumerGroupId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.get") void getConsumerGroup(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("consumerGroupId") String consumerGroupId
  ); }
ConsumerGroupsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") public void listConsumerGroups( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListConsumerGroupsResponse> response = consumerGroupManager.get() .listConsumerGroups(clusterId) .thenApply( consumerGroups -> ListConsumerGroupsResponse.create( ConsumerGroupDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups")) .build()) .setData( consumerGroups.stream() .map( consumerGroup -> toConsumerGroupData(clusterId, consumerGroup)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ConsumerGroupsResource(
      Provider<ConsumerGroupManager> consumerGroupManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.list") void listConsumerGroups(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{consumerGroupId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumer-groups.get") void getConsumerGroup(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("consumerGroupId") String consumerGroupId
  );  }