Example #1
0
  @BeforeMethod(groups = "unit")
  public void init() {
    support = new EventSupportImpl();

    eventDispatcher = EasyMock.createMock(EventDispatcher.class);
    messageSource = EasyMock.createMock(MessageSource.class);

    collection.add(eventDispatcher);
    collection.add(messageSource);

    support.setEventDispatcher(eventDispatcher);
    support.setMessageSource(messageSource);
    event = null;
    eventDispatcher.fireEvent(
        EasyMockUtils.record(
            new EasyMockUtils.Recorder<EventBase>() {
              public void record(final EventBase object) {
                event = object;
              }
            }));

    EasyMock.expect(messageSource.getMessage("code", null)).andStubReturn("message");

    collection.replay();
    final User user = new User();
    user.setCagridId(userId);

    template = new EventBaseImpl();
    template.setJobId(jobId);
    template.setUserId(userId);
    template.setJobName(jobName);
    template.setWorkflowId(workflowId);
  }
Example #2
0
 @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();
 }
Example #3
0
 @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();
 }
Example #4
0
 @Test(groups = "unit")
 public void canUpload() throws RemoteException {
   EasyMock.expect(authorizationProvider.canUpload(fileId, gridId)).andReturn(false);
   mockObjects.replay();
   assert !service.canUpload(fileId, gridId);
   mockObjects.verifyAndReset();
   allowUpload();
   mockObjects.replay();
   assert service.canUpload(fileId, gridId);
   mockObjects.verifyAndReset();
 }
Example #5
0
 @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();
 }
Example #6
0
 @Test(groups = "unit")
 public void canDownload() throws RemoteException {
   expectCannotDownload();
   mockObjects.replay();
   assert !service.canDownload(fileId, gridId);
   mockObjects.verifyAndReset();
   expectCanDownload();
   mockObjects.replay();
   assert service.canDownload(fileId, gridId);
   mockObjects.verifyAndReset();
 }
Example #7
0
 @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();
 }
Example #8
0
 @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;
 }
  @BeforeMethod(groups = "unit")
  public void init() {
    factory = new RawExtractJobFactoryImpl();
    stagingDirectoryFactory = EasyMock.createMock(CredentialedStagingDirectoryFactory.class);
    stagingDirectory = EasyMock.createMock(StagingDirectory.class);
    EasyMock.expect(stagingDirectory.getAbsolutePath()).andStubReturn(PATH);

    EasyMock.expect(stagingDirectory.getSep()).andStubReturn("/");
    final Supplier<DisposableResourceTracker> trackerSupplier = EasyMockUtils.createMockSupplier();
    tracker = createMock(DisposableResourceTracker.class);
    expect(trackerSupplier.get()).andReturn(tracker);
    replay(trackerSupplier);
    rawPopulator = EasyMock.createMock(InputContext.class);

    converter = EasyMock.createMock(DTAToMzXMLConverter.class);
    options = new DTAToMzXMLOptions();

    factory.setDtaToMzXMLConverter(converter);
    factory.setDtaToMxXMLOptions(options);
    factory.setDisposableResourceTrackerSupplier(trackerSupplier);
    factory.setCredentialedStagingDirectoryFactory(stagingDirectoryFactory);
    mockObjects =
        MockObjectCollection.fromObjects(
            stagingDirectoryFactory, stagingDirectory, tracker, rawPopulator, converter);
  }
 protected void postProcessAndVerify() {
   try {
     job.postprocess(completedNormally);
   } finally {
     mockObjects.verifyAndReset();
   }
 }
Example #11
0
 private void expectFinalizeAndReplay(final boolean shouldCommit, final long length) {
   fileService.recordLength(fileId, length);
   if (shouldCommit) {
     fileService.commit(fileId);
   }
   mockObjects.replay();
 }
Example #12
0
 @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");
 }
Example #13
0
 @Test(groups = "unit", expectedExceptions = RuntimeException.class)
 public void getMetadatasException() throws RemoteException {
   EasyMock.expect(
           authorizationProvider.canDownloadAll(
               EasyMock.aryEq(new String[] {fileId, fileId2}), EasyMock.eq(gridId)))
       .andReturn(false);
   mockObjects.replay();
   service.getFileMetadata(Lists.newArrayList(fileId, fileId2), gridId);
 }
Example #14
0
 @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;
 }
Example #15
0
  @BeforeMethod(groups = "unit")
  public void init() {
    service = new StorageManagerImpl();
    gridId = UUID.randomUUID().toString();
    fileId = UUID.randomUUID().toString();
    fileId2 = UUID.randomUUID().toString();
    accessProvider = EasyMock.createMock(AccessProvider.class);
    authorizationProvider = EasyMock.createMock(AuthorizationProvider.class);
    fileService = EasyMock.createMock(FileService.class);

    service.setAccessProvider(accessProvider);
    service.setAuthorizationProvider(authorizationProvider);
    service.setFileService(fileService);

    mockObjects =
        MockObjectCollection.fromObjects(accessProvider, authorizationProvider, fileService);
  }
Example #16
0
 @AfterMethod(groups = "unit")
 public void verifyDispatched() {
   collection.verifyAndReset();
   verifyEvent();
 }
 protected void expectPreprocessingAndReplayMocks() {
   expectPreprocessingIfNeeded();
   expectCleanUp();
   mockObjects.replay();
 }
Example #18
0
 @Test(groups = "unit", expectedExceptions = RuntimeException.class)
 public void uploadAccessException() throws RemoteException {
   EasyMock.expect(authorizationProvider.canUpload(fileId, gridId)).andReturn(false);
   mockObjects.replay();
   service.upload(fileId, gridId);
 }
Example #19
0
 @Test(groups = "unit", expectedExceptions = RuntimeException.class)
 public void dateModifiedAccessException() throws RemoteException {
   expectCannotDownload();
   mockObjects.replay();
   service.getDateModified(fileId, gridId);
 }