@Test public void shouldNotRemoveUnsuedChannel_whenChannelBelongsToDifferentPolicy() { AlertsChannel emailChannelInPolicy = channelInPolicy(savedEmailChannel, POLICY_ID, POLICY_ID + 1); when(alertsChannelsApiMock.list()).thenReturn(ImmutableList.of( savedUserChannel, emailChannelInPolicy, channelInPolicy(savedSlackChannel, POLICY_ID) )); when(alertsChannelsApiMock.deleteFromPolicy(POLICY_ID, emailChannelInPolicy.getId())) .thenReturn(emailChannelInPolicy); PolicyConfiguration policyConfiguration = buildPolicyConfiguration(SLACK_CHANNEL); testee.sync(policyConfiguration); AlertsPolicyChannels expected = AlertsPolicyChannels.builder() .policyId(POLICY_ID) .channelIds(ImmutableSet.of(savedSlackChannel.getId())) .build(); InOrder order = inOrder(alertsChannelsApiMock, alertsPoliciesApiMock); order.verify(alertsChannelsApiMock).list(); order.verify(alertsPoliciesApiMock).updateChannels(expected); order.verify(alertsChannelsApiMock).deleteFromPolicy(POLICY_ID, savedEmailChannel.getId()); order.verify(alertsChannelsApiMock, never()).delete(savedEmailChannel.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);   }