/** * Given a set of billing events, add corresponding blocking (overdue) billing events. * * @param billingEvents the original list of billing events to update (without overdue events) */ public void insertBlockingEvents(final SortedSet<BillingEvent> billingEvents, final InternalTenantContext context) { if (billingEvents.size() <= 0) { return; } final Account account = billingEvents.first().getAccount(); final Hashtable<UUID, List<SubscriptionBase>> bundleMap = createBundleSubscriptionMap(billingEvents); final SortedSet<BillingEvent> billingEventsToAdd = new TreeSet<BillingEvent>(); final SortedSet<BillingEvent> billingEventsToRemove = new TreeSet<BillingEvent>(); final List<BlockingState> blockingEvents = blockingApi.getBlockingAllForAccount(context); final List<DisabledDuration> blockingDurations = createBlockingDurations(blockingEvents); for (final UUID bundleId : bundleMap.keySet()) { for (final SubscriptionBase subscription : bundleMap.get(bundleId)) { billingEventsToAdd.addAll(createNewEvents(blockingDurations, billingEvents, account, subscription)); billingEventsToRemove.addAll(eventsToRemove(blockingDurations, billingEvents, subscription)); } } for (final BillingEvent eventToAdd : billingEventsToAdd) { billingEvents.add(eventToAdd); } for (final BillingEvent eventToRemove : billingEventsToRemove) { billingEvents.remove(eventToRemove); } }
@Test(groups = "fast") public void testEventsToRemoveClosedBetwn() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, now.plusDays(2))); final BillingEvent e2 = createRealEvent(now.plusDays(1), subscription1); billingEvents.add(e2); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 1); assertEquals(results.first(), e2); }
@Test(groups = "fast") public void testEventsToRemoveOpenFollow() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, null)); final BillingEvent e1 = createRealEvent(now.plusDays(1), subscription1); billingEvents.add(e1); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 1); assertEquals(results.first(), e1); }
@Test(groups = "fast") public void testEventsToRemoveClosedFollow() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, now.plusDays(2))); final BillingEvent e3 = createRealEvent(now.plusDays(3), subscription1); billingEvents.add(e3); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 0); }
@Test(groups = "fast") public void testEventsToRemoveClosedPrev() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, now.plusDays(2))); final BillingEvent e1 = createRealEvent(now.minusDays(1), subscription1); billingEvents.add(e1); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 0); }
@Test(groups = "fast") public void testEventsToRemoveClosedPrevBetw() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, now.plusDays(2))); final BillingEvent e1 = createRealEvent(now.minusDays(1), subscription1); final BillingEvent e2 = createRealEvent(now.plusDays(1), subscription1); billingEvents.add(e1); billingEvents.add(e2); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 1); assertEquals(results.first(), e2); }
@Test(groups = "fast") public void testEventsToRemoveClosedBetweenFollow() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, now.plusDays(2))); final BillingEvent e2 = createRealEvent(now.plusDays(1), subscription1); final BillingEvent e3 = createRealEvent(now.plusDays(3), subscription1); billingEvents.add(e2); billingEvents.add(e3); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 1); assertEquals(results.first(), e2); }
@Test(groups = "fast") public void testEventsToRemoveOpenPrev() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, null)); billingEvents.add(createRealEvent(now.minusDays(1), subscription1)); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 0); }
@Test(groups = "fast") public void testEventsToRemoveOpenPrevFollow() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, null)); final BillingEvent e1 = createRealEvent(now.minusDays(1), subscription1); final BillingEvent e2 = createRealEvent(now.plusDays(1), subscription1); billingEvents.add(e1); billingEvents.add(e2); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 1); assertEquals(results.first(), e2); }
@Test(groups = "fast") public void testEventsToRemoveClosedPrevBetwNext() { final DateTime now = clock.getUTCNow(); final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>(); final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>(); disabledDuration.add(new DisabledDuration(now, now.plusDays(2))); final BillingEvent e1 = createRealEvent(now.minusDays(1), subscription1); final BillingEvent e2 = createRealEvent(now.plusDays(1), subscription1); final BillingEvent e3 = createRealEvent(now.plusDays(3), subscription1); billingEvents.add(e1); billingEvents.add(e2); billingEvents.add(e3); final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1); assertEquals(results.size(), 1); assertEquals(results.first(), e2); }