@Test public void updateFileInfo() { final FileInfo requestFileInfo = new FileInfo(); requestFileInfo.setId("upload-1"); requestFileInfo.setFileName("New File.txt"); requestFileInfo.setFileType("text/html"); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { String argFileInfoId = (String) invocation.getArguments()[0]; FileInfo argFileInfo = (FileInfo) invocation.getArguments()[1]; assertEquals("Service upload ID should match the requested upload ID", argFileInfoId, requestFileInfo.getId()); assertEquals("Service upload should match the requested upload", argFileInfo, requestFileInfo); return null; } }).when(fileServiceMock).updateFile(anyString(), any(FileInfo.class)); ClientResponse clientResponse = resource().path("/api/files/" + requestFileInfo.getId()) .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .put(ClientResponse.class, requestFileInfo); assertEquals("Response HTTP status code should be 200 (OK)", clientResponse.getStatus(), 200); verify(fileServiceMock).updateFile(anyString(), any(FileInfo.class)); }
@PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo) { fileService.updateFile(fileId, fileInfo); return Response.ok().build(); }
FileResource { @PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo) { fileService.updateFile(fileId, fileInfo); return Response.ok().build(); } }
FileResource { @PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo) { fileService.updateFile(fileId, fileInfo); return Response.ok().build(); } @Inject  FileResource(FileService fileService); }
FileResource { @PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo) { fileService.updateFile(fileId, fileInfo); return Response.ok().build(); } @Inject  FileResource(FileService fileService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<FileInfo> listFiles(); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) FileInfo createFile(@FormDataParam("file") byte[] fileContent,
            @FormDataParam("file") FormDataContentDisposition fileDetail,
            @HeaderParam("Content-type") String contentType); @GET @Path("/{fileId}") @Produces(MediaType.APPLICATION_JSON) FileInfo getFile(@PathParam("fileId") String fileId); @PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo); @DELETE @Path("/{fileId}") Response deleteFile(@PathParam("fileId") String fileId); @GET @Path("/{fileId}/content") Response getFileContent(@PathParam("fileId") String fileId); @POST @Path("/{fileId}/content") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) FileInfo updateFileContent(@PathParam("fileId") String fileId,
            @FormDataParam("file") byte[] fileContent,
            @FormDataParam("file") FormDataContentDisposition fileDetail,
            @HeaderParam("Content-type") String contentType); }
FileResource { @PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) public Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo) { fileService.updateFile(fileId, fileInfo); return Response.ok().build(); } @Inject  FileResource(FileService fileService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<FileInfo> listFiles(); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) FileInfo createFile(@FormDataParam("file") byte[] fileContent,
            @FormDataParam("file") FormDataContentDisposition fileDetail,
            @HeaderParam("Content-type") String contentType); @GET @Path("/{fileId}") @Produces(MediaType.APPLICATION_JSON) FileInfo getFile(@PathParam("fileId") String fileId); @PUT @Path("/{fileId}") @Consumes(MediaType.APPLICATION_JSON) Response updateFile(@PathParam("fileId") String fileId, FileInfo fileInfo); @DELETE @Path("/{fileId}") Response deleteFile(@PathParam("fileId") String fileId); @GET @Path("/{fileId}/content") Response getFileContent(@PathParam("fileId") String fileId); @POST @Path("/{fileId}/content") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) FileInfo updateFileContent(@PathParam("fileId") String fileId,
            @FormDataParam("file") byte[] fileContent,
            @FormDataParam("file") FormDataContentDisposition fileDetail,
            @HeaderParam("Content-type") String contentType);  }