@Test public void shouldNotRemoveUnusedUserChannel() { AlertsChannel userChannelInPolicy = channelInPolicy(savedUserChannel, POLICY_ID); when(alertsChannelsApiMock.list()).thenReturn(ImmutableList.of(userChannelInPolicy)); when(alertsChannelsApiMock.deleteFromPolicy(POLICY_ID, userChannelInPolicy.getId())) .thenReturn(userChannelInPolicy); PolicyConfiguration policyConfiguration = buildPolicyConfiguration(); testee.sync(policyConfiguration); AlertsPolicyChannels expected = AlertsPolicyChannels.builder() .policyId(POLICY_ID) .channelIds(emptySet()) .build(); InOrder order = inOrder(alertsChannelsApiMock, alertsPoliciesApiMock); order.verify(alertsChannelsApiMock).list(); order.verify(alertsPoliciesApiMock).updateChannels(expected); order.verify(alertsChannelsApiMock).deleteFromPolicy(POLICY_ID, savedUserChannel.getId()); order.verify(alertsChannelsApiMock, never()).delete(savedUserChannel.getId()); order.verifyNoMoreInteractions(); }
void sync(@NonNull PolicyConfiguration config) { if (!config.getChannels().isPresent()) { LOG.info("No alerts channels for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing alerts channels for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); Set<Integer> policyChannelsToCleanup = createOrUpdatePolicyAlertsChannels(policy, config.getChannels().get()); cleanupPolicyAlertsChannels(policy, policyChannelsToCleanup); LOG.info("Alerts channels for policy {} synchronized", config.getPolicyName()); }
ChannelConfigurator { void sync(@NonNull PolicyConfiguration config) { if (!config.getChannels().isPresent()) { LOG.info("No alerts channels for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing alerts channels for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); Set<Integer> policyChannelsToCleanup = createOrUpdatePolicyAlertsChannels(policy, config.getChannels().get()); cleanupPolicyAlertsChannels(policy, policyChannelsToCleanup); LOG.info("Alerts channels for policy {} synchronized", config.getPolicyName()); } }
ChannelConfigurator { void sync(@NonNull PolicyConfiguration config) { if (!config.getChannels().isPresent()) { LOG.info("No alerts channels for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing alerts channels for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); Set<Integer> policyChannelsToCleanup = createOrUpdatePolicyAlertsChannels(policy, config.getChannels().get()); cleanupPolicyAlertsChannels(policy, policyChannelsToCleanup); LOG.info("Alerts channels for policy {} synchronized", config.getPolicyName()); } ChannelConfigurator(@NonNull NewRelicApi api); }
ChannelConfigurator { void sync(@NonNull PolicyConfiguration config) { if (!config.getChannels().isPresent()) { LOG.info("No alerts channels for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing alerts channels for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); Set<Integer> policyChannelsToCleanup = createOrUpdatePolicyAlertsChannels(policy, config.getChannels().get()); cleanupPolicyAlertsChannels(policy, policyChannelsToCleanup); LOG.info("Alerts channels for policy {} synchronized", config.getPolicyName()); } ChannelConfigurator(@NonNull NewRelicApi api);  }
ChannelConfigurator { void sync(@NonNull PolicyConfiguration config) { if (!config.getChannels().isPresent()) { LOG.info("No alerts channels for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing alerts channels for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); Set<Integer> policyChannelsToCleanup = createOrUpdatePolicyAlertsChannels(policy, config.getChannels().get()); cleanupPolicyAlertsChannels(policy, policyChannelsToCleanup); LOG.info("Alerts channels for policy {} synchronized", config.getPolicyName()); } ChannelConfigurator(@NonNull NewRelicApi api);   }