@Test public void testUpdateLoadAlert() { Long clusterId = 10L; Long alertId = 20L; LoadAlert testAlert = getLoadAlert(); when(loadAlertRepository.findByCluster(alertId, clusterId)).thenReturn(mockLoadAlert); when(mockLoadAlert.getScalingPolicy()).thenReturn(new ScalingPolicy()); when(loadAlertRepository.save(mockLoadAlert)).thenReturn(mockLoadAlert); LoadAlert response = underTest.updateLoadAlert(clusterId, alertId, testAlert); assertNotNull("LoadAlert should not be null", response); verify(mockLoadAlert).setName(anyString()); verify(mockLoadAlert).setDescription(anyString()); verify(mockLoadAlert, times(4)).getScalingPolicy(); verify(loadAlertRepository).save(mockLoadAlert); }
public LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate) { LoadAlert alert = loadAlertRepository.findByCluster(alertId, clusterId); alert.setName(loadAlertForUpdate.getName()); alert.setDescription(loadAlertForUpdate.getDescription()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (loadAlertForUpdate.getLoadAlertConfiguration() != null) { alert.setLoadAlertConfiguration(loadAlertForUpdate.getLoadAlertConfiguration()); } if (loadAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(loadAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(loadAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(loadAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(loadAlertForUpdate.getScalingPolicy().getHostGroup()); } return loadAlertRepository.save(alert); }
AlertService { public LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate) { LoadAlert alert = loadAlertRepository.findByCluster(alertId, clusterId); alert.setName(loadAlertForUpdate.getName()); alert.setDescription(loadAlertForUpdate.getDescription()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (loadAlertForUpdate.getLoadAlertConfiguration() != null) { alert.setLoadAlertConfiguration(loadAlertForUpdate.getLoadAlertConfiguration()); } if (loadAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(loadAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(loadAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(loadAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(loadAlertForUpdate.getScalingPolicy().getHostGroup()); } return loadAlertRepository.save(alert); } }
AlertService { public LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate) { LoadAlert alert = loadAlertRepository.findByCluster(alertId, clusterId); alert.setName(loadAlertForUpdate.getName()); alert.setDescription(loadAlertForUpdate.getDescription()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (loadAlertForUpdate.getLoadAlertConfiguration() != null) { alert.setLoadAlertConfiguration(loadAlertForUpdate.getLoadAlertConfiguration()); } if (loadAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(loadAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(loadAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(loadAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(loadAlertForUpdate.getScalingPolicy().getHostGroup()); } return loadAlertRepository.save(alert); }  }
AlertService { public LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate) { LoadAlert alert = loadAlertRepository.findByCluster(alertId, clusterId); alert.setName(loadAlertForUpdate.getName()); alert.setDescription(loadAlertForUpdate.getDescription()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (loadAlertForUpdate.getLoadAlertConfiguration() != null) { alert.setLoadAlertConfiguration(loadAlertForUpdate.getLoadAlertConfiguration()); } if (loadAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(loadAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(loadAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(loadAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(loadAlertForUpdate.getScalingPolicy().getHostGroup()); } return loadAlertRepository.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 LoadAlert updateLoadAlert(Long clusterId, Long alertId, LoadAlert loadAlertForUpdate) { LoadAlert alert = loadAlertRepository.findByCluster(alertId, clusterId); alert.setName(loadAlertForUpdate.getName()); alert.setDescription(loadAlertForUpdate.getDescription()); if (StringUtils.isEmpty(alert.getAlertCrn())) { alert.setAlertCrn(createAlertCrn(ThreadBasedUserCrnProvider.getAccountId())); } if (loadAlertForUpdate.getLoadAlertConfiguration() != null) { alert.setLoadAlertConfiguration(loadAlertForUpdate.getLoadAlertConfiguration()); } if (loadAlertForUpdate.getScalingPolicy() != null) { alert.getScalingPolicy().setName(loadAlertForUpdate.getScalingPolicy().getName()); alert.getScalingPolicy().setAdjustmentType(loadAlertForUpdate.getScalingPolicy().getAdjustmentType()); alert.getScalingPolicy().setScalingAdjustment(loadAlertForUpdate.getScalingPolicy().getScalingAdjustment()); alert.getScalingPolicy().setHostGroup(loadAlertForUpdate.getScalingPolicy().getHostGroup()); } return loadAlertRepository.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);  }