@Test public void listConsumers_returnsConsumers() { expect(consumerManager.listConsumers(CLUSTER_ID, CONSUMER_GROUP.getConsumerGroupId())) .andReturn(completedFuture(Arrays.asList(CONSUMERS))); replay(consumerManager); FakeAsyncResponse response = new FakeAsyncResponse(); consumersResource.listConsumers(response, CLUSTER_ID, CONSUMER_GROUP.getConsumerGroupId()); ListConsumersResponse expected = ListConsumersResponse.create( ConsumerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1/consumers") .build()) .setData( Arrays.asList( ConsumerData.fromConsumer(CONSUMERS[0]) .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1") .setResourceName( "crn: + "/consumer=consumer-1") .build()) .setAssignments( Relationship.create( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-1/assignments")) .build(), ConsumerData.fromConsumer(CONSUMERS[1]) .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-2") .setResourceName( "crn: + "/consumer=consumer-2") .build()) .setAssignments( Relationship.create( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-2/assignments")) .build(), ConsumerData.fromConsumer(CONSUMERS[2]) .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-3") .setResourceName( "crn: + "/consumer=consumer-3") .build()) .setAssignments( Relationship.create( "/v3/clusters/cluster-1/consumer-groups/consumer-group-1" + "/consumers/consumer-3/assignments")) .build())) .build()); assertEquals(expected, response.getValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") public void listConsumers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId ) { CompletableFuture<ListConsumersResponse> response = consumerManager.get() .listConsumers(clusterId, consumerGroupId) .thenApply( consumers -> ListConsumersResponse.create( ConsumerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "consumers")) .build()) .setData( consumers.stream() .map(this::toConsumerData) .sorted(Comparator.comparing(ConsumerData::getConsumerId)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
ConsumersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") public void listConsumers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId ) { CompletableFuture<ListConsumersResponse> response = consumerManager.get() .listConsumers(clusterId, consumerGroupId) .thenApply( consumers -> ListConsumersResponse.create( ConsumerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "consumers")) .build()) .setData( consumers.stream() .map(this::toConsumerData) .sorted(Comparator.comparing(ConsumerData::getConsumerId)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
ConsumersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") public void listConsumers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId ) { CompletableFuture<ListConsumersResponse> response = consumerManager.get() .listConsumers(clusterId, consumerGroupId) .thenApply( consumers -> ListConsumersResponse.create( ConsumerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "consumers")) .build()) .setData( consumers.stream() .map(this::toConsumerData) .sorted(Comparator.comparing(ConsumerData::getConsumerId)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ConsumersResource(
      Provider<ConsumerManager> consumerManager, CrnFactory crnFactory, UrlFactory urlFactory); }
ConsumersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") public void listConsumers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId ) { CompletableFuture<ListConsumersResponse> response = consumerManager.get() .listConsumers(clusterId, consumerGroupId) .thenApply( consumers -> ListConsumersResponse.create( ConsumerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "consumers")) .build()) .setData( consumers.stream() .map(this::toConsumerData) .sorted(Comparator.comparing(ConsumerData::getConsumerId)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ConsumersResource(
      Provider<ConsumerManager> consumerManager, CrnFactory crnFactory, UrlFactory urlFactory); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") void listConsumers(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("consumerGroupId") String consumerGroupId
  ); @GET @Path("/{consumerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.get") void getConsumer(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("consumerGroupId") String consumerGroupId,
      @PathParam("consumerId") String consumerId
  ); }
ConsumersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") public void listConsumers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId ) { CompletableFuture<ListConsumersResponse> response = consumerManager.get() .listConsumers(clusterId, consumerGroupId) .thenApply( consumers -> ListConsumersResponse.create( ConsumerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create( "v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "consumers")) .build()) .setData( consumers.stream() .map(this::toConsumerData) .sorted(Comparator.comparing(ConsumerData::getConsumerId)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ConsumersResource(
      Provider<ConsumerManager> consumerManager, CrnFactory crnFactory, UrlFactory urlFactory); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.list") void listConsumers(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("consumerGroupId") String consumerGroupId
  ); @GET @Path("/{consumerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.consumers.get") void getConsumer(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("consumerGroupId") String consumerGroupId,
      @PathParam("consumerId") String consumerId
  );  }