@Test public void testUpdateTimeAlert() { Long clusterId = 10L; Long alertId = 20L; TimeAlert testAlert = getTimeAlert(); when(timeAlertRepository.findByCluster(alertId, clusterId)).thenReturn(mockTimeAlert); when(mockTimeAlert.getScalingPolicy()).thenReturn(new ScalingPolicy()); when(timeAlertRepository.save(mockTimeAlert)).thenReturn(mockTimeAlert); TimeAlert response = underTest.updateTimeAlert(clusterId, alertId, testAlert); assertNotNull("TimeAlert should not be null", response); verify(mockTimeAlert).setName(anyString()); verify(mockTimeAlert).setDescription(anyString()); verify(mockTimeAlert).setCron(anyString()); verify(mockTimeAlert).setTimeZone(anyString()); verify(mockTimeAlert, times(4)).getScalingPolicy(); verify(timeAlertRepository).save(mockTimeAlert); }
public TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate) { TimeAlert alert = timeAlertRepository.findByCluster(alertId, clusterId); alert.setDescription(timeAlertForUpdate.getDescription()); alert.setCron(timeAlertForUpdate.getCron()); alert.setTimeZone(timeAlertForUpdate.getTimeZone()); alert.setName(timeAlertForUpdate.getName()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (timeAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(timeAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(timeAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(timeAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(timeAlertForUpdate.getScalingPolicy().getHostGroup()); } return timeAlertRepository.save(alert); }
AlertService { public TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate) { TimeAlert alert = timeAlertRepository.findByCluster(alertId, clusterId); alert.setDescription(timeAlertForUpdate.getDescription()); alert.setCron(timeAlertForUpdate.getCron()); alert.setTimeZone(timeAlertForUpdate.getTimeZone()); alert.setName(timeAlertForUpdate.getName()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (timeAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(timeAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(timeAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(timeAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(timeAlertForUpdate.getScalingPolicy().getHostGroup()); } return timeAlertRepository.save(alert); } }
AlertService { public TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate) { TimeAlert alert = timeAlertRepository.findByCluster(alertId, clusterId); alert.setDescription(timeAlertForUpdate.getDescription()); alert.setCron(timeAlertForUpdate.getCron()); alert.setTimeZone(timeAlertForUpdate.getTimeZone()); alert.setName(timeAlertForUpdate.getName()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (timeAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(timeAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(timeAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(timeAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(timeAlertForUpdate.getScalingPolicy().getHostGroup()); } return timeAlertRepository.save(alert); }  }
AlertService { public TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate) { TimeAlert alert = timeAlertRepository.findByCluster(alertId, clusterId); alert.setDescription(timeAlertForUpdate.getDescription()); alert.setCron(timeAlertForUpdate.getCron()); alert.setTimeZone(timeAlertForUpdate.getTimeZone()); alert.setName(timeAlertForUpdate.getName()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (timeAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(timeAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(timeAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(timeAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(timeAlertForUpdate.getScalingPolicy().getHostGroup()); } return timeAlertRepository.save(alert); }  TimeAlert createTimeAlert(Long clusterId, TimeAlert alert); TimeAlert findTimeAlertByCluster(Long clusterId, Long alertId); TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate); Set<TimeAlert> getTimeAlerts(Long clusterId); void deleteTimeAlert(Long clusterId, Long alertId); Set<TimeAlert> removeTimeAlert(Cluster cluster, Long alertId); BaseAlert getBaseAlert(Long clusterId, Long alertId); BaseAlert save(BaseAlert alert); LoadAlert createLoadAlert(Long clusterId, LoadAlert loadAlert); LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate); LoadAlert findLoadAlertByCluster(Long clusterId, Long alertId); void deleteLoadAlert(Long clusterId, Long alertId); Set<LoadAlert> removeLoadAlert(Cluster cluster, Long alertId); Set<LoadAlert> getLoadAlertsForClusterHostGroup(Long clusterId, String hostGroup); Set<LoadAlert> getLoadAlerts(Long clusterId); }
AlertService { public TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate) { TimeAlert alert = timeAlertRepository.findByCluster(alertId, clusterId); alert.setDescription(timeAlertForUpdate.getDescription()); alert.setCron(timeAlertForUpdate.getCron()); alert.setTimeZone(timeAlertForUpdate.getTimeZone()); alert.setName(timeAlertForUpdate.getName()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (timeAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(timeAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(timeAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(timeAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(timeAlertForUpdate.getScalingPolicy().getHostGroup()); } return timeAlertRepository.save(alert); }  TimeAlert createTimeAlert(Long clusterId, TimeAlert alert); TimeAlert findTimeAlertByCluster(Long clusterId, Long alertId); TimeAlert updateTimeAlert(Long clusterId, Long alertId, TimeAlert timeAlertForUpdate); Set<TimeAlert> getTimeAlerts(Long clusterId); void deleteTimeAlert(Long clusterId, Long alertId); Set<TimeAlert> removeTimeAlert(Cluster cluster, Long alertId); BaseAlert getBaseAlert(Long clusterId, Long alertId); BaseAlert save(BaseAlert alert); LoadAlert createLoadAlert(Long clusterId, LoadAlert loadAlert); LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate); LoadAlert findLoadAlertByCluster(Long clusterId, Long alertId); void deleteLoadAlert(Long clusterId, Long alertId); Set<LoadAlert> removeLoadAlert(Cluster cluster, Long alertId); Set<LoadAlert> getLoadAlertsForClusterHostGroup(Long clusterId, String hostGroup); Set<LoadAlert> getLoadAlerts(Long clusterId);  }