@Test public void getTopics_existingCluster_returnsTopic() { expect(topicManager.getTopic(TOPIC_1.getClusterId(), TOPIC_1.getName())). andReturn(completedFuture(Optional.of(TOPIC_1))); replay(topicManager); FakeAsyncResponse response = new FakeAsyncResponse(); topicsResource.getTopic(response, TOPIC_1.getClusterId(), TOPIC_1.getName()); GetTopicResponse expected = GetTopicResponse.create( TopicData.builder() .setMetadata( Resource.Metadata.builder() .setSelf("/v3/clusters/cluster-1/topics/topic-1") .setResourceName("crn: .build()) .setClusterId("cluster-1") .setTopicName("topic-1") .setInternal(true) .setReplicationFactor(3) .setPartitions( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions")) .setConfigs( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/configs")) .setPartitionReassignments( Resource.Relationship.create( "/v3/clusters/cluster-1/topics/topic-1/partitions/-/reassignment")) .build()); assertEquals(expected, response.getValue()); }
@GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") public void getTopic( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName ) { CompletableFuture<GetTopicResponse> response = topicManager.get() .getTopic(clusterId, topicName) .thenApply(topic -> topic.orElseThrow(NotFoundException::new)) .thenApply(topic -> GetTopicResponse.create(toTopicData(topic))); AsyncResponses.asyncResume(asyncResponse, response); }
TopicsResource { @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") public void getTopic( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName ) { CompletableFuture<GetTopicResponse> response = topicManager.get() .getTopic(clusterId, topicName) .thenApply(topic -> topic.orElseThrow(NotFoundException::new)) .thenApply(topic -> GetTopicResponse.create(toTopicData(topic))); AsyncResponses.asyncResume(asyncResponse, response); } }
TopicsResource { @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") public void getTopic( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName ) { CompletableFuture<GetTopicResponse> response = topicManager.get() .getTopic(clusterId, topicName) .thenApply(topic -> topic.orElseThrow(NotFoundException::new)) .thenApply(topic -> GetTopicResponse.create(toTopicData(topic))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  TopicsResource(
      Provider<TopicManager> topicManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); }
TopicsResource { @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") public void getTopic( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName ) { CompletableFuture<GetTopicResponse> response = topicManager.get() .getTopic(clusterId, topicName) .thenApply(topic -> topic.orElseThrow(NotFoundException::new)) .thenApply(topic -> GetTopicResponse.create(toTopicData(topic))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  TopicsResource(
      Provider<TopicManager> topicManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") void listTopics(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") void getTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  ); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.create") void createTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @Valid CreateTopicRequest request
  ); @DELETE @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.delete") void deleteTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  ); }
TopicsResource { @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") public void getTopic( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName ) { CompletableFuture<GetTopicResponse> response = topicManager.get() .getTopic(clusterId, topicName) .thenApply(topic -> topic.orElseThrow(NotFoundException::new)) .thenApply(topic -> GetTopicResponse.create(toTopicData(topic))); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  TopicsResource(
      Provider<TopicManager> topicManager,
      CrnFactory crnFactory,
      UrlFactory urlFactory
  ); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.list") void listTopics(
      @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId); @GET @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.get") void getTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  ); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.create") void createTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @Valid CreateTopicRequest request
  ); @DELETE @Path("/{topicName}") @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.topics.delete") void deleteTopic(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @PathParam("topicName") String topicName
  );  }