@Test public void getKafkaCluster() { final KafkaCluster mockedCluster = new KafkaCluster(); mockedCluster.setId("kafkaCluster-1"); mockedCluster.setName("Kafka Cluster 1"); mockedCluster.setZookeeperUri("zookeeper: when(kafkaServiceMock.getCluster(anyString())).then(new Answer<KafkaCluster>() { @Override public KafkaCluster answer(InvocationOnMock invocation) throws Throwable { String argClusterId = (String) invocation.getArguments()[0]; assertEquals("Service kafka cluster ID should match the requested kafka cluster ID", argClusterId, mockedCluster.getId()); return mockedCluster; } }); KafkaCluster responseCluster = resource() .path("/api/kafka/clusters/" + mockedCluster.getId()) .accept(MediaType.APPLICATION_JSON).get(KafkaCluster.class); assertEquals("Response kafka cluster should match the mocked kafka cluster", mockedCluster, responseCluster); verify(kafkaServiceMock).getCluster(anyString()); }
@GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId) { return kafkaService.getCluster(clusterId); }
KafkaResource { @GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId) { return kafkaService.getCluster(clusterId); } }
KafkaResource { @GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId) { return kafkaService.getCluster(clusterId); } @Inject  KafkaResource(KafkaService kafkaService); }
KafkaResource { @GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId) { return kafkaService.getCluster(clusterId); } @Inject  KafkaResource(KafkaService kafkaService); @GET @Path("/clusters") @Produces(MediaType.APPLICATION_JSON) List<KafkaCluster> listKafkaClusters(); @POST @Path("/clusters") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) KafkaCluster addKafkaCluster(KafkaCluster kafkaCluster); @GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId); @DELETE @Path("/clusters/{clusterId}") Response removeKafkaCluster(@PathParam("clusterId") String clusterId); @GET @Path("/clusters/{clusterId}/topics") @Produces(MediaType.APPLICATION_JSON) List<KafkaTopic> listKafkaTopics(@PathParam("clusterId") String clusterId); @POST @Path("/clusters/{clusterId}/topics") Response addKafkaTopic(@PathParam("clusterId") String clusterId, KafkaTopic topic); @DELETE @Path("/clusters/{clusterId}/topics/{topicName}") Response deleteKafkaTopic(@PathParam("clusterId") String clusterId, 
            @PathParam("topicName") String topicName); }
KafkaResource { @GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId) { return kafkaService.getCluster(clusterId); } @Inject  KafkaResource(KafkaService kafkaService); @GET @Path("/clusters") @Produces(MediaType.APPLICATION_JSON) List<KafkaCluster> listKafkaClusters(); @POST @Path("/clusters") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) KafkaCluster addKafkaCluster(KafkaCluster kafkaCluster); @GET @Path("/clusters/{clusterId}") @Produces(MediaType.APPLICATION_JSON) KafkaCluster getKafkaCluster(@PathParam("clusterId") String clusterId); @DELETE @Path("/clusters/{clusterId}") Response removeKafkaCluster(@PathParam("clusterId") String clusterId); @GET @Path("/clusters/{clusterId}/topics") @Produces(MediaType.APPLICATION_JSON) List<KafkaTopic> listKafkaTopics(@PathParam("clusterId") String clusterId); @POST @Path("/clusters/{clusterId}/topics") Response addKafkaTopic(@PathParam("clusterId") String clusterId, KafkaTopic topic); @DELETE @Path("/clusters/{clusterId}/topics/{topicName}") Response deleteKafkaTopic(@PathParam("clusterId") String clusterId, 
            @PathParam("topicName") String topicName);  }