/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * guess {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedLoad_Filename_Guess() throws Exception { Repository myrepo = mock( Repository.class ); doReturn( true ).when( myrepo ).isConnected(); doReturn( null ).when( myrepo ).getJobEntryAttributeString( any( ObjectId.class ), anyString() ); doReturn( JOB_ENTRY_FILE_PATH ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "file_name" ); JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.loadRep( myrepo, store, JOB_ENTRY_JOB_OBJECT_ID, databases, servers ); jej.getJobMeta( myrepo, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, myrepo, store, null ); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * keep {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedLoad_Filename() throws Exception { Repository myrepo = mock( Repository.class ); doReturn( true ).when( myrepo ).isConnected(); doReturn( null ).when( myrepo ).getJobEntryAttributeString( any( ObjectId.class ), anyString() ); doReturn( "filename" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "specification_method" ); doReturn( JOB_ENTRY_FILE_PATH ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "file_name" ); JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.loadRep( myrepo, store, JOB_ENTRY_JOB_OBJECT_ID, databases, servers ); jej.getJobMeta( myrepo, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, myrepo, store, null ); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by name, * keep {@link ObjectLocationSpecificationMethod} as {@code REPOSITORY_BY_NAME}. * Load the job from the repository using the specified job name and directory. */ @Test public void testConnectedLoad_RepByName_HDFS() throws Exception { Repository myrepo = mock( Repository.class ); doReturn( true ).when( myrepo ).isConnected(); doReturn( null ).when( myrepo ).getJobEntryAttributeString( any( ObjectId.class ), anyString() ); doReturn( "rep_name" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "specification_method" ); doReturn( "job" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "name" ); doReturn( "${hdfs}" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "dir_path" ); JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.loadRep( myrepo, store, JOB_ENTRY_JOB_OBJECT_ID, databases, servers ); jej.getJobMeta( myrepo, store, space ); assertEquals( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, "hdfs://server/path/job.kjb", myrepo, store, null ); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * guess {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedImport_Filename_Guess() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setFileName( JOB_ENTRY_FILE_PATH ); jej.loadXML( getNode( jej ), databases, servers, repository, store ); jej.getJobMeta( repository, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, repository, store, null ); }
/** * When disconnected from the repository and {@link JobEntryJob} references a child job by file path, * {@link ObjectLocationSpecificationMethod} will be {@code FILENAME}. */ @Test public void testNotConnectedLoad_Filename() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); jej.setFileName( JOB_ENTRY_FILE_PATH ); jej.loadXML( getNode( jej ), databases, servers, null, store ); jej.getJobMeta( null, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, null, store, null ); }
/** * When disconnected from the repository and {@link JobEntryJob} references a child job by {@link ObjectId}, * this reference will be invalid to run such job. * Default to {@link ObjectLocationSpecificationMethod}.{@code FILENAME} with a {@code null} file path. */ @Test public void testNotConnectedLoad_RepByRef() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE ); jej.setJobObjectId( JOB_ENTRY_JOB_OBJECT_ID ); jej.loadXML( getNode( jej ), databases, servers, null, store ); jej.getJobMeta( null, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, null, null, store, null ); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * keep {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedImport_Filename() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); jej.setFileName( JOB_ENTRY_FILE_PATH ); jej.loadXML( getNode( jej ), databases, servers, repository, store ); jej.getJobMeta( repository, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, repository, store, null ); }
/** * When disconnected from the repository and {@link JobEntryJob} references a child job by name, * this reference will be invalid to run such job. * Default to {@link ObjectLocationSpecificationMethod}.{@code FILENAME} with a {@code null} file path. */ @Test public void testNotConnectedLoad_RepByName() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME ); jej.setJobName( JOB_ENTRY_FILE_NAME ); jej.setDirectory( JOB_ENTRY_FILE_DIRECTORY ); jej.loadXML( getNode( jej ), databases, servers, null, store ); jej.getJobMeta( null, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, null, null, store, null ); }
/** * Verifies certain behavior <b>happened once</b> * <p> * Alias to <code>verifyNew(mockClass, times(1))</code> E.g: * <p> * <pre> * verifyNew(ClassWithStaticMethod.class); * </pre> * <p> * Above is equivalent to: * <p> * <pre> * verifyNew(ClassWithStaticMethod.class, times(1)); * </pre> * <p> * <p> * * @param mock Class mocked by PowerMock. */ @SuppressWarnings("unchecked") public static synchronized <T> ConstructorArgumentsVerification verifyNew(Class<T> mock) { return verifyNew(mock, times(1)); }
@Test public void scheduleTimerTaskShouldScheduleOneTimeTaskWithCorrectNameAndDelay() throws Exception { final Timer timer = mock(Timer.class); final TimerTask timerTask = createTimerTask(); whenNew(Timer.class).withAnyArguments().thenReturn(timer); timerTools.scheduleTimerTask("TheTimer", timerTask, 123); verifyNew(Timer.class).withArguments("TheTimer"); verify(timer).schedule(timerTask, 123); }
PowerMockito.verifyNew(BufferedItemSourcePool.class).withArguments( eq(poolName), any(UnpooledByteBufAllocator.class),
@Test public void startDownloadThenDisable() throws Exception { /* Simulate async task. */ waitDownloadTask(); /* Verify. */ verify(mDownloadManager).enqueue(mDownloadRequest); verifyNew(DownloadManager.Request.class).withArguments(mDownloadUrl); verifyStatic(); SharedPreferencesManager.putLong(PREFERENCE_KEY_DOWNLOAD_ID, DOWNLOAD_ID); verifyStatic(); SharedPreferencesManager.putInt(PREFERENCE_KEY_DOWNLOAD_STATE, DOWNLOAD_STATE_ENQUEUED); /* Pause/resume should do nothing excepting mentioning progress. */ verify(mDialog).show(); Distribute.getInstance().onActivityPaused(mActivity); Distribute.getInstance().onActivityResumed(mActivity); verify(mDialog).show(); /* Cancel download by disabling. */ Distribute.setEnabled(false); verifyStatic(); SharedPreferencesManager.remove(PREFERENCE_KEY_DOWNLOAD_ID); verifyStatic(); SharedPreferencesManager.remove(PREFERENCE_KEY_DOWNLOAD_STATE); verify(mDownloadTask.get()).cancel(true); verify(mDownloadManager).remove(DOWNLOAD_ID); verify(mNotificationManager, never()).notify(anyInt(), any(Notification.class)); }
@Test public void disableWhileStartingDownload() throws Exception { /* Cancel download before async task completes. */ Distribute.setEnabled(false); waitDownloadTask(); /* Verify. */ verifyStatic(); SharedPreferencesManager.remove(PREFERENCE_KEY_DOWNLOAD_ID); verifyStatic(); SharedPreferencesManager.remove(PREFERENCE_KEY_DOWNLOAD_STATE); verify(mDownloadTask.get()).cancel(true); verify(mDownloadManager).enqueue(mDownloadRequest); verifyNew(DownloadManager.Request.class).withArguments(mDownloadUrl); verify(mDownloadManager).remove(DOWNLOAD_ID); /* And that we didn't persist the state. */ verifyStatic(never()); SharedPreferencesManager.putLong(PREFERENCE_KEY_DOWNLOAD_ID, DOWNLOAD_ID); verifyStatic(never()); SharedPreferencesManager.putString(PREFERENCE_KEY_DOWNLOAD_STATE, ""); verifyZeroInteractions(mNotificationManager); }