@Test void testUpload() throws ExecutionException, InterruptedException { String blobId = "MyBlobId"; BlobMetadata blobMetadata = when(mock(BlobMetadata.class).getId()).thenReturn(blobId).getMock(); when(blobMetadata.getSize()).thenReturn(1L); when(blobStore.store(any())).thenReturn(blobMetadata); FileMeta fileMeta = mock(FileMeta.class); when(fileMetaFactory.create(blobId)).thenReturn(fileMeta); MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); httpServletRequest.setContent(new byte[] {0x00}); String contentType = "application/octet-stream"; httpServletRequest.setContentType(contentType); String filename = "myfile.bin"; httpServletRequest.addHeader("x-molgenis-filename", filename); assertEquals(fileMeta, filesApiServiceImpl.upload(httpServletRequest).get()); verify(fileMeta).setContentType(contentType); verify(fileMeta).setSize(1L); verify(fileMeta).setFilename(filename); verify(fileMeta).setUrl("/MyBlobId?alt=media"); verifyNoMoreInteractions(fileMeta); }
@Transactional @Override public CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest) { BlobMetadata blobMetadata; try (ReadableByteChannel fromChannel = newChannel(httpServletRequest.getInputStream())) { blobMetadata = blobStore.store(fromChannel); } catch (IOException e) { throw new UncheckedIOException(e); } FileMeta fileMeta = createFileMeta(httpServletRequest, blobMetadata); dataService.add(FILE_META, fileMeta); return CompletableFuture.completedFuture(fileMeta); }
FilesServiceImpl implements FilesService { @Transactional @Override public CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest) { BlobMetadata blobMetadata; try (ReadableByteChannel fromChannel = newChannel(httpServletRequest.getInputStream())) { blobMetadata = blobStore.store(fromChannel); } catch (IOException e) { throw new UncheckedIOException(e); } FileMeta fileMeta = createFileMeta(httpServletRequest, blobMetadata); dataService.add(FILE_META, fileMeta); return CompletableFuture.completedFuture(fileMeta); } }
FilesServiceImpl implements FilesService { @Transactional @Override public CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest) { BlobMetadata blobMetadata; try (ReadableByteChannel fromChannel = newChannel(httpServletRequest.getInputStream())) { blobMetadata = blobStore.store(fromChannel); } catch (IOException e) { throw new UncheckedIOException(e); } FileMeta fileMeta = createFileMeta(httpServletRequest, blobMetadata); dataService.add(FILE_META, fileMeta); return CompletableFuture.completedFuture(fileMeta); } FilesServiceImpl(DataService dataService, BlobStore blobStore, FileMetaFactory fileMetaFactory); }
FilesServiceImpl implements FilesService { @Transactional @Override public CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest) { BlobMetadata blobMetadata; try (ReadableByteChannel fromChannel = newChannel(httpServletRequest.getInputStream())) { blobMetadata = blobStore.store(fromChannel); } catch (IOException e) { throw new UncheckedIOException(e); } FileMeta fileMeta = createFileMeta(httpServletRequest, blobMetadata); dataService.add(FILE_META, fileMeta); return CompletableFuture.completedFuture(fileMeta); } FilesServiceImpl(DataService dataService, BlobStore blobStore, FileMetaFactory fileMetaFactory); @Transactional(readOnly = true) @Override FileMeta getFileMeta(String fileId); @Override void delete(String fileId); @Transactional @Override CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest); @Transactional(readOnly = true) @Override ResponseEntity<StreamingResponseBody> download(String fileId); }
FilesServiceImpl implements FilesService { @Transactional @Override public CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest) { BlobMetadata blobMetadata; try (ReadableByteChannel fromChannel = newChannel(httpServletRequest.getInputStream())) { blobMetadata = blobStore.store(fromChannel); } catch (IOException e) { throw new UncheckedIOException(e); } FileMeta fileMeta = createFileMeta(httpServletRequest, blobMetadata); dataService.add(FILE_META, fileMeta); return CompletableFuture.completedFuture(fileMeta); } FilesServiceImpl(DataService dataService, BlobStore blobStore, FileMetaFactory fileMetaFactory); @Transactional(readOnly = true) @Override FileMeta getFileMeta(String fileId); @Override void delete(String fileId); @Transactional @Override CompletableFuture<FileMeta> upload(HttpServletRequest httpServletRequest); @Transactional(readOnly = true) @Override ResponseEntity<StreamingResponseBody> download(String fileId);  }