@Test public void shouldUpdateCondition() { U itemFromConfig = getItemFromConfig(); U itemUpdated = getItemUpdated(); PolicyConfiguration policyConfiguration = getPolicyConfiguration(); PolicyItemApi<U> itemApiMock = getPolicyItemApiMock(); when(itemApiMock.list(POLICY.getId())).thenReturn(ImmutableList.of(itemUpdated)); when(itemApiMock.update(itemUpdated.getId(), itemFromConfig)).thenReturn(itemUpdated); testee.sync(policyConfiguration); InOrder order = inOrder(itemApiMock); order.verify(itemApiMock).list(POLICY.getId()); order.verify(itemApiMock).update(itemUpdated.getId(), itemFromConfig); order.verifyNoMoreInteractions(); }
@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);  }