@Test public void getCluster() { final Cluster mockedCluster = new Cluster("CLUSTER_TO_GET", "Retrieved Cluster"); when(clusterServiceMock.getCluster(anyString())).then(new Answer<Cluster>() { @Override public Cluster answer(InvocationOnMock invocation) throws Throwable { String argClusterId = (String) invocation.getArguments()[0]; assertEquals("Service cluster ID should match the requested cluster ID", argClusterId, mockedCluster.getId()); return mockedCluster; } }); Cluster responseCluster = resource().path("/api/clusters/" + mockedCluster.getId()) .accept(MediaType.APPLICATION_JSON).get(Cluster.class); assertEquals("Response cluster should match the mocked cluster", mockedCluster, responseCluster); verify(clusterServiceMock).getCluster(anyString()); }
@GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public Cluster getCluster(@PathParam("clusterId") String clusterId) { return clusterService.getCluster(clusterId); }
ClusterResource { @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public Cluster getCluster(@PathParam("clusterId") String clusterId) { return clusterService.getCluster(clusterId); } }
ClusterResource { @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public Cluster getCluster(@PathParam("clusterId") String clusterId) { return clusterService.getCluster(clusterId); } @Inject  ClusterResource(ClusterService clusterService); }
ClusterResource { @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public Cluster getCluster(@PathParam("clusterId") String clusterId) { return clusterService.getCluster(clusterId); } @Inject  ClusterResource(ClusterService clusterService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<Cluster> listClusters(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Cluster createCluster(Cluster cluster); @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) Cluster getCluster(@PathParam("clusterId") String clusterId); @PUT @Path("/{clusterId}") @Consumes(MediaType.APPLICATION_JSON) Response updateCluster(@PathParam("clusterId") String clusterId, Cluster cluster); @DELETE @Path("/{clusterId}") Response deleteCluster(@PathParam("clusterId") String clusterId); @GET @Path("/{clusterId}/summary") @Produces(MediaType.APPLICATION_JSON) ClusterSummary getClusterSummary(@PathParam("clusterId") String clusterId); }
ClusterResource { @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) public Cluster getCluster(@PathParam("clusterId") String clusterId) { return clusterService.getCluster(clusterId); } @Inject  ClusterResource(ClusterService clusterService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<Cluster> listClusters(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Cluster createCluster(Cluster cluster); @GET @Path("/{clusterId}") @Produces(MediaType.APPLICATION_JSON) Cluster getCluster(@PathParam("clusterId") String clusterId); @PUT @Path("/{clusterId}") @Consumes(MediaType.APPLICATION_JSON) Response updateCluster(@PathParam("clusterId") String clusterId, Cluster cluster); @DELETE @Path("/{clusterId}") Response deleteCluster(@PathParam("clusterId") String clusterId); @GET @Path("/{clusterId}/summary") @Produces(MediaType.APPLICATION_JSON) ClusterSummary getClusterSummary(@PathParam("clusterId") String clusterId);  }