@Test public void updateFileInfoContent() { final FileInfo mockedFileInfo = new FileInfo(); mockedFileInfo.setId("test-upload"); final byte[] mockedFileInfoData = "UPDATED UPLOAD FILE CONTENT!".getBytes(); when(fileServiceMock.getFileInfo(anyString())).thenReturn(mockedFileInfo); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { String argFileInfoId = (String) invocation.getArguments()[0]; FileInfo argFileInfo = (FileInfo) invocation.getArguments()[1]; byte[] argFileInfoData = (byte[]) invocation.getArguments()[2]; assertEquals("Service upload ID should match the requested upload ID", argFileInfoId, mockedFileInfo.getId()); assertEquals("FileInfo file name should be set on the service upload object", "updated-file.txt", argFileInfo.getFileName()); assertEquals("FileInfo file size should be set on the service upload object", 28, (long) argFileInfo.getFileSize()); assertEquals("FileInfo file type should be set on the service upload object", "text/plain", argFileInfo.getFileType()); assertEquals("FileInfo content hash should be set on the service upload object", "de1e1f8c088c7024368d2af801f51c67", argFileInfo.getContentHash()); assertTrue("Service upload data should match the requested upload data", Arrays.equals(mockedFileInfoData, argFileInfoData)); return null; } }).when(fileServiceMock).updateFile(anyString(), any(FileInfo.class), any(byte[].class)); FormDataMultiPart formData = new FormDataMultiPart(); FormDataBodyPart bodyPart = new FormDataBodyPart( FormDataContentDisposition.name("file").fileName("updated-file.txt").build(), mockedFileInfoData, MediaType.TEXT_PLAIN_TYPE); formData.bodyPart(bodyPart); FileInfo responseFileInfo = resource().path("/api/files/" + mockedFileInfo.getId() + "/content") .accept(MediaType.APPLICATION_JSON).type(MediaType.MULTIPART_FORM_DATA) .post(FileInfo.class, formData); assertNotNull("Response upload should not be null after valid file upload", responseFileInfo); verify(fileServiceMock).getFileInfo(anyString()); verify(fileServiceMock).updateFile(anyString(), any(FileInfo.class), any(byte[].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);  }