@Test public void getBroker_nonExistingCluster_throwsNotFound() { expect(brokerManager.getBroker(CLUSTER_ID, 1)).andReturn(failedFuture(new NotFoundException())); replay(brokerManager); FakeAsyncResponse response = new FakeAsyncResponse(); brokersResource.getBroker(response, CLUSTER_ID, 1); assertEquals(NotFoundException.class, response.getException().getClass()); }
@GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") public void getBroker( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("brokerId") Integer brokerId ) { CompletableFuture<GetBrokerResponse> response = brokerManager.get() .getBroker(clusterId, brokerId) .thenApply(broker -> broker.orElseThrow(NotFoundException::new)) .thenApply(broker -> GetBrokerResponse.create(toBrokerData(broker))); AsyncResponses.asyncResume(asyncResponse, response); }
BrokersResource { @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") public void getBroker( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("brokerId") Integer brokerId ) { CompletableFuture<GetBrokerResponse> response = brokerManager.get() .getBroker(clusterId, brokerId) .thenApply(broker -> broker.orElseThrow(NotFoundException::new)) .thenApply(broker -> GetBrokerResponse.create(toBrokerData(broker))); AsyncResponses.asyncResume(asyncResponse, response); } }
BrokersResource { @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") public void getBroker( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("brokerId") Integer brokerId ) { CompletableFuture<GetBrokerResponse> response = brokerManager.get() .getBroker(clusterId, brokerId) .thenApply(broker -> broker.orElseThrow(NotFoundException::new)) .thenApply(broker -> GetBrokerResponse.create(toBrokerData(broker))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  BrokersResource(
      Provider<BrokerManager> brokerManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
BrokersResource { @GET @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") public void getBroker( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("brokerId") Integer brokerId ) { CompletableFuture<GetBrokerResponse> response = brokerManager.get() .getBroker(clusterId, brokerId) .thenApply(broker -> broker.orElseThrow(NotFoundException::new)) .thenApply(broker -> GetBrokerResponse.create(toBrokerData(broker))); 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 @Path("/{brokerId}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.brokers.get") public void getBroker( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("brokerId") Integer brokerId ) { CompletableFuture<GetBrokerResponse> response = brokerManager.get() .getBroker(clusterId, brokerId) .thenApply(broker -> broker.orElseThrow(NotFoundException::new)) .thenApply(broker -> GetBrokerResponse.create(toBrokerData(broker))); 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
  );  }