@Test public void listClusters_returnsArrayWithOwnClusters() { expect(clusterManager.listClusters()) .andReturn(CompletableFuture.completedFuture(singletonList(CLUSTER_1))); replay(clusterManager); FakeAsyncResponse response = new FakeAsyncResponse(); clustersResource.listClusters(response); ListClustersResponse expected = ListClustersResponse.create( ClusterDataList.builder() .setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters").build()) .setData( singletonList( ClusterData.builder() .setMetadata( Resource.Metadata.builder() .setSelf("/v3/clusters/cluster-1") .setResourceName("crn: .build()) .setClusterId("cluster-1") .setController( Resource.Relationship.create("/v3/clusters/cluster-1/brokers/1")) .setAcls(Resource.Relationship.create("/v3/clusters/cluster-1/acls")) .setBrokers( Resource.Relationship.create("/v3/clusters/cluster-1/brokers")) .setBrokerConfigs( Resource.Relationship.create( "/v3/clusters/cluster-1/broker-configs")) .setConsumerGroups( Resource.Relationship.create( "/v3/clusters/cluster-1/consumer-groups")) .setTopics( Resource.Relationship.create("/v3/clusters/cluster-1/topics")) .setPartitionReassignments( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/-/partitions/-/reassignment")) .build())) .build()); assertEquals(expected, response.getValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") public void listClusters(@Suspended AsyncResponse asyncResponse) { CompletableFuture<ListClustersResponse> response = clusterManager.get() .listClusters() .thenApply( clusters -> ListClustersResponse.create( ClusterDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf(urlFactory.create("v3", "clusters")) .build()) .setData( clusters.stream() .map(this::toClusterData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
ClustersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") public void listClusters(@Suspended AsyncResponse asyncResponse) { CompletableFuture<ListClustersResponse> response = clusterManager.get() .listClusters() .thenApply( clusters -> ListClustersResponse.create( ClusterDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf(urlFactory.create("v3", "clusters")) .build()) .setData( clusters.stream() .map(this::toClusterData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
ClustersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") public void listClusters(@Suspended AsyncResponse asyncResponse) { CompletableFuture<ListClustersResponse> response = clusterManager.get() .listClusters() .thenApply( clusters -> ListClustersResponse.create( ClusterDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf(urlFactory.create("v3", "clusters")) .build()) .setData( clusters.stream() .map(this::toClusterData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ClustersResource(
      Provider<ClusterManager> clusterManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
ClustersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") public void listClusters(@Suspended AsyncResponse asyncResponse) { CompletableFuture<ListClustersResponse> response = clusterManager.get() .listClusters() .thenApply( clusters -> ListClustersResponse.create( ClusterDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf(urlFactory.create("v3", "clusters")) .build()) .setData( clusters.stream() .map(this::toClusterData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ClustersResource(
      Provider<ClusterManager> clusterManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") void listClusters(@Suspended AsyncResponse asyncResponse); @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.get") void getCluster(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); }
ClustersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") public void listClusters(@Suspended AsyncResponse asyncResponse) { CompletableFuture<ListClustersResponse> response = clusterManager.get() .listClusters() .thenApply( clusters -> ListClustersResponse.create( ClusterDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf(urlFactory.create("v3", "clusters")) .build()) .setData( clusters.stream() .map(this::toClusterData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  ClustersResource(
      Provider<ClusterManager> clusterManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.list") void listClusters(@Suspended AsyncResponse asyncResponse); @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.clusters.get") void getCluster(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId);  }