@Test public void listClusters() { Collection<Cluster> mockedClusters = new ArrayList<Cluster>(); mockedClusters.add(new Cluster("LOCAL", "Local Cluster")); doReturn(mockedClusters).when(clusterServiceMock).listClusters(); Collection<Cluster> responseClusters = resource().path("/api/clusters") .accept(MediaType.APPLICATION_JSON).get(new GenericType<Collection<Cluster>>(){}); assertEquals("Response clusters should be equal to the mocked clusters", mockedClusters, responseClusters); verify(clusterServiceMock).listClusters(); }
@GET @Produces(MediaType.APPLICATION_JSON) public Collection<Cluster> listClusters() { return clusterService.listClusters(); }
ClusterResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Cluster> listClusters() { return clusterService.listClusters(); } }
ClusterResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Cluster> listClusters() { return clusterService.listClusters(); } @Inject  ClusterResource(ClusterService clusterService); }
ClusterResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<Cluster> listClusters() { return clusterService.listClusters(); } @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 @Produces(MediaType.APPLICATION_JSON) public Collection<Cluster> listClusters() { return clusterService.listClusters(); } @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);  }