@Test public void shouldThrowException_whenPolicyDoesNotExist() { when(alertsPoliciesApiMock.getByName(POLICY_NAME)).thenReturn(Optional.empty()); expectedException.expect(NewRelicSyncException.class); expectedException.expectMessage(format("Policy %s does not exist", POLICY_NAME)); testee.sync(getPolicyConfiguration()); }
@Override public void sync(@NonNull PolicyConfiguration config) { if (! getConfigItems(config).isPresent()) { LOG.info("No items for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing items for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); List<T> allItems = getItemsApi().list(policy.getId()); List<Integer> updatedItemsIds = createOrUpdateAlertsNrqlConditions(policy, getConfigItems(config).get(), allItems); cleanupOldItems(policy, allItems, updatedItemsIds); LOG.info("Items for policy {} synchronized", config.getPolicyName()); }
AbstractPolicyItemConfigurator implements PolicyItemConfigurator { @Override public void sync(@NonNull PolicyConfiguration config) { if (! getConfigItems(config).isPresent()) { LOG.info("No items for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing items for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); List<T> allItems = getItemsApi().list(policy.getId()); List<Integer> updatedItemsIds = createOrUpdateAlertsNrqlConditions(policy, getConfigItems(config).get(), allItems); cleanupOldItems(policy, allItems, updatedItemsIds); LOG.info("Items for policy {} synchronized", config.getPolicyName()); } }
AbstractPolicyItemConfigurator implements PolicyItemConfigurator { @Override public void sync(@NonNull PolicyConfiguration config) { if (! getConfigItems(config).isPresent()) { LOG.info("No items for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing items for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); List<T> allItems = getItemsApi().list(policy.getId()); List<Integer> updatedItemsIds = createOrUpdateAlertsNrqlConditions(policy, getConfigItems(config).get(), allItems); cleanupOldItems(policy, allItems, updatedItemsIds); LOG.info("Items for policy {} synchronized", config.getPolicyName()); } AbstractPolicyItemConfigurator(@NonNull NewRelicApi api); }
AbstractPolicyItemConfigurator implements PolicyItemConfigurator { @Override public void sync(@NonNull PolicyConfiguration config) { if (! getConfigItems(config).isPresent()) { LOG.info("No items for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing items for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); List<T> allItems = getItemsApi().list(policy.getId()); List<Integer> updatedItemsIds = createOrUpdateAlertsNrqlConditions(policy, getConfigItems(config).get(), allItems); cleanupOldItems(policy, allItems, updatedItemsIds); LOG.info("Items for policy {} synchronized", config.getPolicyName()); } AbstractPolicyItemConfigurator(@NonNull NewRelicApi api); @Override void sync(@NonNull PolicyConfiguration config); }
AbstractPolicyItemConfigurator implements PolicyItemConfigurator { @Override public void sync(@NonNull PolicyConfiguration config) { if (! getConfigItems(config).isPresent()) { LOG.info("No items for policy {} - skipping...", config.getPolicyName()); return; } LOG.info("Synchronizing items for policy {}...", config.getPolicyName()); AlertsPolicy policy = api.getAlertsPoliciesApi().getByName(config.getPolicyName()).orElseThrow( () -> new NewRelicSyncException(format("Policy %s does not exist", config.getPolicyName()))); List<T> allItems = getItemsApi().list(policy.getId()); List<Integer> updatedItemsIds = createOrUpdateAlertsNrqlConditions(policy, getConfigItems(config).get(), allItems); cleanupOldItems(policy, allItems, updatedItemsIds); LOG.info("Items for policy {} synchronized", config.getPolicyName()); } AbstractPolicyItemConfigurator(@NonNull NewRelicApi api); @Override void sync(@NonNull PolicyConfiguration config);  }