@Test public void getFileInfoContent() { final byte[] mockedFileInfoContent = "UPLOADED_CONTENT_HERE!".getBytes(); final FileInfo mockedFileInfo = new FileInfo(); mockedFileInfo.setFileName("test-file.txt"); mockedFileInfo.setFileSize((long)mockedFileInfoContent.length); when(fileServiceMock.getFileInfo(anyString())).thenReturn(mockedFileInfo); when(fileServiceMock.getFileContent(anyString())).thenReturn(mockedFileInfoContent); ClientResponse clientResponse = resource().path("/api/files/" + mockedFileInfo.getId() + "/content").get(ClientResponse.class); assertEquals("Response HTTP status code should be 200 (OK)", clientResponse.getStatus(), 200); assertTrue("Reponse upload data should match mocked upload data", Arrays.equals(mockedFileInfoContent, clientResponse.getEntity(byte[].class))); verify(fileServiceMock).getFileInfo(anyString()); verify(fileServiceMock).getFileContent(anyString()); }
@GET @Path("/{fileId}/content") public Response getFileContent(@PathParam("fileId") String fileId) { byte[] fileContent = fileService.getFileContent(fileId); FileInfo fileInfo = fileService.getFileInfo(fileId); return Response.ok().entity(fileContent).type(fileInfo.getFileType()) .header("Content-Disposition", "attachment; filename=" + fileInfo.getFileName()) .header("Cache-Control", "no-cache").build(); }
FileResource { @GET @Path("/{fileId}/content") public Response getFileContent(@PathParam("fileId") String fileId) { byte[] fileContent = fileService.getFileContent(fileId); FileInfo fileInfo = fileService.getFileInfo(fileId); return Response.ok().entity(fileContent).type(fileInfo.getFileType()) .header("Content-Disposition", "attachment; filename=" + fileInfo.getFileName()) .header("Cache-Control", "no-cache").build(); } }
FileResource { @GET @Path("/{fileId}/content") public Response getFileContent(@PathParam("fileId") String fileId) { byte[] fileContent = fileService.getFileContent(fileId); FileInfo fileInfo = fileService.getFileInfo(fileId); return Response.ok().entity(fileContent).type(fileInfo.getFileType()) .header("Content-Disposition", "attachment; filename=" + fileInfo.getFileName()) .header("Cache-Control", "no-cache").build(); } @Inject  FileResource(FileService fileService); }
FileResource { @GET @Path("/{fileId}/content") public Response getFileContent(@PathParam("fileId") String fileId) { byte[] fileContent = fileService.getFileContent(fileId); FileInfo fileInfo = fileService.getFileInfo(fileId); return Response.ok().entity(fileContent).type(fileInfo.getFileType()) .header("Content-Disposition", "attachment; filename=" + fileInfo.getFileName()) .header("Cache-Control", "no-cache").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 { @GET @Path("/{fileId}/content") public Response getFileContent(@PathParam("fileId") String fileId) { byte[] fileContent = fileService.getFileContent(fileId); FileInfo fileInfo = fileService.getFileInfo(fileId); return Response.ok().entity(fileContent).type(fileInfo.getFileType()) .header("Content-Disposition", "attachment; filename=" + fileInfo.getFileName()) .header("Cache-Control", "no-cache").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);  }