@Test public void testIsHarvestOptimizationAllowed() throws Exception { BandwidthRestriction mockBandwidthRestriction = mock(BandwidthRestriction.class); when(mockBandwidthRestriction.isAllowOptimize()).thenReturn(true); when(mockHarvestCoordinatorDao.getBandwidthRestriction(anyString(), any(Date.class))).thenReturn(mockBandwidthRestriction); boolean result = underTest.isHarvestOptimizationAllowed(); verify(mockHarvestCoordinatorDao).getBandwidthRestriction(anyString(), any(Date.class)); assertTrue(result); when(mockBandwidthRestriction.isAllowOptimize()).thenReturn(false); result = underTest.isHarvestOptimizationAllowed(); assertFalse(result); }
@Override public boolean isHarvestOptimizationAllowed() { try { Calendar now = Calendar.getInstance(); String time = BandwidthRestriction.TIMEONLY_FORMAT.format(now.getTime()); log.info("isHarvestOptimizationAllowed - Parsing date for the bandwidth restriction, time: " + time); Date date = BandwidthRestriction.FULLDATE_FORMAT.parse(BandwidthRestriction.DEFAULT_DATE + time); String day = BandwidthRestriction.FULLDAY_FORMAT.format(now.getTime()).toUpperCase(); BandwidthRestriction br = harvestCoordinatorDao.getBandwidthRestriction(day, date); if (br == null) return false; return br.isAllowOptimize(); } catch (ParseException e) { log.error("Failed to parse the date for the bandwith restriction : " + e.getMessage(), e); } return false; }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public boolean isHarvestOptimizationAllowed() { try { Calendar now = Calendar.getInstance(); String time = BandwidthRestriction.TIMEONLY_FORMAT.format(now.getTime()); log.info("isHarvestOptimizationAllowed - Parsing date for the bandwidth restriction, time: " + time); Date date = BandwidthRestriction.FULLDATE_FORMAT.parse(BandwidthRestriction.DEFAULT_DATE + time); String day = BandwidthRestriction.FULLDAY_FORMAT.format(now.getTime()).toUpperCase(); BandwidthRestriction br = harvestCoordinatorDao.getBandwidthRestriction(day, date); if (br == null) return false; return br.isAllowOptimize(); } catch (ParseException e) { log.error("Failed to parse the date for the bandwith restriction : " + e.getMessage(), e); } return false; } }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public boolean isHarvestOptimizationAllowed() { try { Calendar now = Calendar.getInstance(); String time = BandwidthRestriction.TIMEONLY_FORMAT.format(now.getTime()); log.info("isHarvestOptimizationAllowed - Parsing date for the bandwidth restriction, time: " + time); Date date = BandwidthRestriction.FULLDATE_FORMAT.parse(BandwidthRestriction.DEFAULT_DATE + time); String day = BandwidthRestriction.FULLDAY_FORMAT.format(now.getTime()).toUpperCase(); BandwidthRestriction br = harvestCoordinatorDao.getBandwidthRestriction(day, date); if (br == null) return false; return br.isAllowOptimize(); } catch (ParseException e) { log.error("Failed to parse the date for the bandwith restriction : " + e.getMessage(), e); } return false; }  }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public boolean isHarvestOptimizationAllowed() { try { Calendar now = Calendar.getInstance(); String time = BandwidthRestriction.TIMEONLY_FORMAT.format(now.getTime()); log.info("isHarvestOptimizationAllowed - Parsing date for the bandwidth restriction, time: " + time); Date date = BandwidthRestriction.FULLDATE_FORMAT.parse(BandwidthRestriction.DEFAULT_DATE + time); String day = BandwidthRestriction.FULLDAY_FORMAT.format(now.getTime()).toUpperCase(); BandwidthRestriction br = harvestCoordinatorDao.getBandwidthRestriction(day, date); if (br == null) return false; return br.isAllowOptimize(); } catch (ParseException e) { log.error("Failed to parse the date for the bandwith restriction : " + e.getMessage(), e); } return false; }  @Override void sendBandWidthRestrictions(); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(TargetInstance aTargetInstance); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(); @Override long getCurrentGlobalMaxBandwidth(); @Override boolean isMiniumBandwidthAvailable(QueuedTargetInstanceDTO aTargetInstance); @Override boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); @Override synchronized void checkForBandwidthTransition(); @Override boolean isHarvestOptimizationAllowed(); @Override BandwidthRestriction getBandwidthRestriction(Long oid); @Override void saveOrUpdate(BandwidthRestriction bandwidthRestriction); @Override void delete(BandwidthRestriction bandwidthRestriction); @Override BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); @Override HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); @Override int getMinimumBandwidth(); @Override void setMinimumBandwidth(int minimumBandwidth); @Override int getMaxBandwidthPercent(); @Override void setMaxBandwidthPercent(int maxBandwidthPercent); void setHarvestCoordinatorDao(HarvestCoordinatorDAO harvestCoordinatorDao); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setBandwidthCalculator(BandwidthCalculator bandwidthCalculator); }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public boolean isHarvestOptimizationAllowed() { try { Calendar now = Calendar.getInstance(); String time = BandwidthRestriction.TIMEONLY_FORMAT.format(now.getTime()); log.info("isHarvestOptimizationAllowed - Parsing date for the bandwidth restriction, time: " + time); Date date = BandwidthRestriction.FULLDATE_FORMAT.parse(BandwidthRestriction.DEFAULT_DATE + time); String day = BandwidthRestriction.FULLDAY_FORMAT.format(now.getTime()).toUpperCase(); BandwidthRestriction br = harvestCoordinatorDao.getBandwidthRestriction(day, date); if (br == null) return false; return br.isAllowOptimize(); } catch (ParseException e) { log.error("Failed to parse the date for the bandwith restriction : " + e.getMessage(), e); } return false; }  @Override void sendBandWidthRestrictions(); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(TargetInstance aTargetInstance); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(); @Override long getCurrentGlobalMaxBandwidth(); @Override boolean isMiniumBandwidthAvailable(QueuedTargetInstanceDTO aTargetInstance); @Override boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); @Override synchronized void checkForBandwidthTransition(); @Override boolean isHarvestOptimizationAllowed(); @Override BandwidthRestriction getBandwidthRestriction(Long oid); @Override void saveOrUpdate(BandwidthRestriction bandwidthRestriction); @Override void delete(BandwidthRestriction bandwidthRestriction); @Override BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); @Override HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); @Override int getMinimumBandwidth(); @Override void setMinimumBandwidth(int minimumBandwidth); @Override int getMaxBandwidthPercent(); @Override void setMaxBandwidthPercent(int maxBandwidthPercent); void setHarvestCoordinatorDao(HarvestCoordinatorDAO harvestCoordinatorDao); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setBandwidthCalculator(BandwidthCalculator bandwidthCalculator);  }