@Test public void shouldDoNothing_whenPolicyNotUpdated() { when(alertsPoliciesApiMock.getByName(POLICY_NAME)).thenReturn(Optional.of(ALERT_POLICY_SAME)); testee.sync(CONFIGURATION); InOrder order = inOrder(alertsPoliciesApiMock); order.verify(alertsPoliciesApiMock).getByName(POLICY_NAME); order.verifyNoMoreInteractions(); }
void sync(@NonNull PolicyConfiguration config) { LOG.info("Synchronizing policy {}...", config.getPolicyName()); AlertsPolicy alertsPolicyFromConfig = AlertsPolicy.builder() .name(config.getPolicyName()) .incidentPreference(config.getIncidentPreference().name()) .build(); Optional<AlertsPolicy> policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()); if (policy.isPresent()) { AlertsPolicy oldPolicy = policy.get(); if (!StringUtils.equals(alertsPolicyFromConfig.getIncidentPreference(), oldPolicy.getIncidentPreference())) { api.getAlertsPoliciesApi().delete(oldPolicy.getId()); api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info(format("Policy %s updated", config.getPolicyName())); } } else { api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info("Policy {} created", config.getPolicyName()); } LOG.info("Policy {} synchronized", config.getPolicyName()); }
PolicyConfigurator { void sync(@NonNull PolicyConfiguration config) { LOG.info("Synchronizing policy {}...", config.getPolicyName()); AlertsPolicy alertsPolicyFromConfig = AlertsPolicy.builder() .name(config.getPolicyName()) .incidentPreference(config.getIncidentPreference().name()) .build(); Optional<AlertsPolicy> policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()); if (policy.isPresent()) { AlertsPolicy oldPolicy = policy.get(); if (!StringUtils.equals(alertsPolicyFromConfig.getIncidentPreference(), oldPolicy.getIncidentPreference())) { api.getAlertsPoliciesApi().delete(oldPolicy.getId()); api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info(format("Policy %s updated", config.getPolicyName())); } } else { api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info("Policy {} created", config.getPolicyName()); } LOG.info("Policy {} synchronized", config.getPolicyName()); } }
PolicyConfigurator { void sync(@NonNull PolicyConfiguration config) { LOG.info("Synchronizing policy {}...", config.getPolicyName()); AlertsPolicy alertsPolicyFromConfig = AlertsPolicy.builder() .name(config.getPolicyName()) .incidentPreference(config.getIncidentPreference().name()) .build(); Optional<AlertsPolicy> policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()); if (policy.isPresent()) { AlertsPolicy oldPolicy = policy.get(); if (!StringUtils.equals(alertsPolicyFromConfig.getIncidentPreference(), oldPolicy.getIncidentPreference())) { api.getAlertsPoliciesApi().delete(oldPolicy.getId()); api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info(format("Policy %s updated", config.getPolicyName())); } } else { api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info("Policy {} created", config.getPolicyName()); } LOG.info("Policy {} synchronized", config.getPolicyName()); } PolicyConfigurator(@NonNull NewRelicApi api); }
PolicyConfigurator { void sync(@NonNull PolicyConfiguration config) { LOG.info("Synchronizing policy {}...", config.getPolicyName()); AlertsPolicy alertsPolicyFromConfig = AlertsPolicy.builder() .name(config.getPolicyName()) .incidentPreference(config.getIncidentPreference().name()) .build(); Optional<AlertsPolicy> policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()); if (policy.isPresent()) { AlertsPolicy oldPolicy = policy.get(); if (!StringUtils.equals(alertsPolicyFromConfig.getIncidentPreference(), oldPolicy.getIncidentPreference())) { api.getAlertsPoliciesApi().delete(oldPolicy.getId()); api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info(format("Policy %s updated", config.getPolicyName())); } } else { api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info("Policy {} created", config.getPolicyName()); } LOG.info("Policy {} synchronized", config.getPolicyName()); } PolicyConfigurator(@NonNull NewRelicApi api);  }
PolicyConfigurator { void sync(@NonNull PolicyConfiguration config) { LOG.info("Synchronizing policy {}...", config.getPolicyName()); AlertsPolicy alertsPolicyFromConfig = AlertsPolicy.builder() .name(config.getPolicyName()) .incidentPreference(config.getIncidentPreference().name()) .build(); Optional<AlertsPolicy> policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()); if (policy.isPresent()) { AlertsPolicy oldPolicy = policy.get(); if (!StringUtils.equals(alertsPolicyFromConfig.getIncidentPreference(), oldPolicy.getIncidentPreference())) { api.getAlertsPoliciesApi().delete(oldPolicy.getId()); api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info(format("Policy %s updated", config.getPolicyName())); } } else { api.getAlertsPoliciesApi().create(alertsPolicyFromConfig); LOG.info("Policy {} created", config.getPolicyName()); } LOG.info("Policy {} synchronized", config.getPolicyName()); } PolicyConfigurator(@NonNull NewRelicApi api);   }