@Test(groups = "unit") public void exists() throws RemoteException { EasyMock.expect(accessProvider.fileExists(fileId)).andReturn(true); mockObjects.replay(); assert service.exists(fileId); mockObjects.verifyAndReset(); EasyMock.expect(accessProvider.fileExists(fileId)).andReturn(false); mockObjects.replay(); assert !service.exists(fileId); mockObjects.verifyAndReset(); }
@Test(groups = "unit") public void getMetadatas() { EasyMock.expect( authorizationProvider.canDownloadAll( EasyMock.aryEq(new String[] {fileId, fileId2}), EasyMock.eq(gridId))) .andReturn(true); EasyMock.expect(accessProvider.getFileMetadata(fileId)).andReturn(new FileMetadata(13L, 12L)); EasyMock.expect(accessProvider.getFileMetadata(fileId2)).andReturn(new FileMetadata(14L, 11L)); mockObjects.replay(); final List<FileMetadata> metadatas = service.getFileMetadata(Lists.newArrayList(fileId, fileId2), gridId); assert metadatas.get(0).getLength() == 12L; assert metadatas.get(1).getLength() == 11L; }
@Test(groups = "unit") public void length() throws RemoteException { expectCanDownload(); EasyMock.expect(accessProvider.getFileMetadata(fileId)).andReturn(new FileMetadata(12L, 13L)); mockObjects.replay(); assert service.getLength(fileId, gridId) == 13L; }
@Test(groups = "unit") public void downloadSkipCheck() throws RemoteException { final HasStreamInputContext file = EasyMock.createMock(HasStreamInputContext.class); EasyMock.expect(accessProvider.getFile(fileId)).andReturn(file); mockObjects.replay(); assert file.equals(service.download(fileId, gridId, false)); mockObjects.verifyAndReset(); }
@Test(groups = "unit") public void delete() throws RemoteException { EasyMock.expect(authorizationProvider.canDelete(fileId, gridId)).andReturn(true); EasyMock.expect(accessProvider.deleteFile(fileId)).andReturn(true); mockObjects.replay(); assert service.delete(fileId, gridId); mockObjects.verifyAndReset(); }
@Test(groups = "unit", dataProvider = "bool1", dataProviderClass = TestNGDataProviders.class) public void upload(final boolean shouldCommit) throws RemoteException { handleShouldCommit(shouldCommit); allowUpload(); mockObjects.replay(); final InputStream inputStream = new ByteArrayInputStream("moo".getBytes()); final UploadCallback callback = service.upload(fileId, gridId); mockObjects.verifyAndReset(); final long length = 3L; EasyMock.expect(accessProvider.putFile(EasyMock.eq(fileId), EasyMock.same(inputStream))) .andReturn(length); expectFinalizeAndReplay(shouldCommit, length); callback.onUpload(inputStream); mockObjects.verifyAndReset(); }
@Test(groups = "unit", dataProvider = "bool1", dataProviderClass = TestNGDataProviders.class) public void uploadStream(final boolean shouldCommit) throws IOException { handleShouldCommit(shouldCommit); allowUpload(); final ByteArrayOutputStream underlyingOutputStream = new ByteArrayOutputStream(); EasyMock.expect(accessProvider.getPutFileOutputStream(fileId)) .andReturn(underlyingOutputStream); mockObjects.replay(); final OutputStream outputStream = service.prepareUploadStream(fileId, gridId); mockObjects.verifyAndReset(); expectFinalizeAndReplay(shouldCommit, 3L); InputContexts.forString("moo").get(outputStream); outputStream.close(); mockObjects.verifyAndReset(); assert new String(underlyingOutputStream.toByteArray()).equals("moo"); }