HarvestAgentManagerImpl implements HarvestAgentManager { @Override public void stop(TargetInstance aTargetInstance) { HarvestAgentStatusDTO status = getHarvestAgentStatusFor(aTargetInstance.getJobName()); if (status == null) { log.warn("STOP Failed. Failed to find the Harvest Agent for the Job {}.", aTargetInstance.getJobName()); return; } HarvestAgent agent = harvestAgentFactory.getHarvestAgent(status.getHost(), status.getPort(), status.getService()); agent.stop(aTargetInstance.getJobName()); }  @Override void heartbeat(HarvestAgentStatusDTO aStatus); @Override void updateProfileOverrides(TargetInstance aTargetInstance, String profileString); @Override void pause(TargetInstance aTargetInstance); @Override void resume(TargetInstance aTargetInstance); @Override void abort(TargetInstance aTargetInstance); @Override void stop(TargetInstance aTargetInstance); @Override void pauseAll(); @Override void resumeAll(); @Override LogReader getLogReader(TargetInstance aTargetInstance); @Override void pauseAgent(String agentName); @Override void resumeAgent(String agentName); @Override boolean runningOrPaused(TargetInstance aTargetInstance); @Override void restrictBandwidthFor(TargetInstance targetInstance); @Override List<HarvestAgentStatusDTO> getHarvestersForAgency(String agencyName); @Override void markDead(HarvestAgentStatusDTO agent); @Override void initiateHarvest(HarvestAgentStatusDTO aHarvestAgent, TargetInstance aTargetInstance, String profile,
			String seedsString); @Override void recoverHarvests(String haHost, int haPort, String haService, List<String> activeJobs); @Override boolean lock(Long tiOid); @Override void unLock(Long tiOid); @Override HashMap<String, HarvestAgentStatusDTO> getHarvestAgents(); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setHarvestAgentFactory(HarvestAgentFactory harvestAgentFactory); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); @Override void purgeAbortedTargetInstances(String[] tiNames); @Override List<HarvestAgentStatusDTO> getAvailableHarvesters(String agencyName); @Override HarvestAgentStatusDTO getHarvester(String agencyName, String harvesterType);  }
@Test public void testStop() { String jobName = "testJob"; HarvestAgent mockHarvestAgent = setHarvestAgentFactory(jobName); TargetInstance mockTi = mock(TargetInstance.class); when(mockTi.getJobName()).thenReturn(jobName); underTest.stop(mockTi); verify(mockHarvestAgent).stop(jobName); }
@Test public void testStopJobDoesntExist() { String jobName = "nonexistant"; underTest.harvestAgents.clear(); TargetInstance mockTi = mock(TargetInstance.class); when(mockTi.getJobName()).thenReturn(jobName); underTest.stop(mockTi); }