@Test public void listBrokers_nonExistingCluster_throwsNotFound() { expect(brokerManager.listBrokers(CLUSTER_ID)).andReturn(failedFuture(new NotFoundException())); replay(brokerManager); FakeAsyncResponse response = new FakeAsyncResponse(); brokersResource.listBrokers(response, CLUSTER_ID); assertEquals(NotFoundException.class, response.getException().getClass()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") void listBrokers(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") void getBroker(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("brokerId") Integer brokerId
  ); }
BrokersResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") public void listBrokers( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) { CompletableFuture<ListBrokersResponse> response = brokerManager.get() .listBrokers(clusterId) .thenApply( brokers -> ListBrokersResponse.create( BrokerDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.create("v3", "clusters", clusterId, "brokers")) .build()) .setData( brokers.stream() .map(this::toBrokerData) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.list") void listBrokers(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") void getBroker(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("brokerId") Integer brokerId
  );  }