@Test public void getResource() { final Resource mockedResource = new Resource(); mockedResource.setId("resource-1"); mockedResource.setName("resource-one"); mockedResource.setLabel("Resource One"); mockedResource.setVersion("1.0.0"); mockedResource.setFramework("test-framework"); mockedResource.setFrameworkLabel("Test Framework"); when(resourceServiceMock.getResource(anyString())).then(new Answer<Resource>() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { String argResourceId = (String) invocation.getArguments()[0]; assertEquals("Service resource ID should match the requested resource ID", argResourceId, mockedResource.getId()); return mockedResource; } }); Resource responseResource = resource().path("/api/resources/" + mockedResource.getId()) .accept(MediaType.APPLICATION_JSON).get(Resource.class); assertEquals("Response resource should match the mocked resource", mockedResource, responseResource); verify(resourceServiceMock).getResource(anyString()); }
@GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) public Resource getResource(@PathParam("resourceId") String resourceId) { return resourceService.getResource(resourceId); }
ResourceResource { @GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) public Resource getResource(@PathParam("resourceId") String resourceId) { return resourceService.getResource(resourceId); } }
ResourceResource { @GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) public Resource getResource(@PathParam("resourceId") String resourceId) { return resourceService.getResource(resourceId); } @Inject  ResourceResource(ResourceService resourceService); }
ResourceResource { @GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) public Resource getResource(@PathParam("resourceId") String resourceId) { return resourceService.getResource(resourceId); } @Inject  ResourceResource(ResourceService resourceService); @GET @Produces(MediaType.APPLICATION_JSON) List<Resource> listResources(); @GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) Resource getResource(@PathParam("resourceId") String resourceId); @GET @Path("/{resourceId}/config") @Produces(MediaType.APPLICATION_JSON) ResourceConfig getResourceConfig(@PathParam("resourceId") String resourceId); }
ResourceResource { @GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) public Resource getResource(@PathParam("resourceId") String resourceId) { return resourceService.getResource(resourceId); } @Inject  ResourceResource(ResourceService resourceService); @GET @Produces(MediaType.APPLICATION_JSON) List<Resource> listResources(); @GET @Path("/{resourceId}") @Produces(MediaType.APPLICATION_JSON) Resource getResource(@PathParam("resourceId") String resourceId); @GET @Path("/{resourceId}/config") @Produces(MediaType.APPLICATION_JSON) ResourceConfig getResourceConfig(@PathParam("resourceId") String resourceId);  }