private BillingEvent createEvent(final SubscriptionBase sub, final DateTime effectiveDate, final SubscriptionBaseTransitionType type) { return createEvent(sub, effectiveDate, type, 1L); }
@Test(groups = "fast") public void testEventOrderingSubscription() { final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final BillingEvent event1 = createEvent(subscription(ID_ONE), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final BillingEvent event2 = createEvent(subscription(ID_TWO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>(); set.add(event2); set.add(event1); set.add(event0); final Iterator<BillingEvent> it = set.iterator(); Assert.assertEquals(event0, it.next()); Assert.assertEquals(event1, it.next()); Assert.assertEquals(event2, it.next()); }
@Test(groups = "fast") public void testEventTotalOrdering() { final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE, 1L); final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CANCEL, 2L); final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.RE_CREATE, 3L); final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>(); set.add(event2); set.add(event1); set.add(event0); final Iterator<BillingEvent> it = set.iterator(); Assert.assertEquals(event0, it.next()); Assert.assertEquals(event1, it.next()); Assert.assertEquals(event2, it.next()); }
@Test(groups = "fast") public void testEventOrderingMix() { final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-02T00:02:04.000Z"), SubscriptionBaseTransitionType.CHANGE); final BillingEvent event2 = createEvent(subscription(ID_ONE), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CANCEL); final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>(); set.add(event2); set.add(event1); set.add(event0); final Iterator<BillingEvent> it = set.iterator(); Assert.assertEquals(event0, it.next()); Assert.assertEquals(event1, it.next()); Assert.assertEquals(event2, it.next()); }
@Test(groups = "fast") public void testEventOrderingDate() { final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-02-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-03-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>(); set.add(event2); set.add(event1); set.add(event0); final Iterator<BillingEvent> it = set.iterator(); Assert.assertEquals(event0, it.next()); Assert.assertEquals(event1, it.next()); Assert.assertEquals(event2, it.next()); }
@Test(groups = "fast") public void testEntitlementEventsHappeningAtTheSameTimeAsOverdueEvents() throws Exception { final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.START_BILLING_DISABLED); final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE); final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:05.000Z"), SubscriptionBaseTransitionType.CHANGE); final BillingEvent event3 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:05.000Z"), SubscriptionBaseTransitionType.END_BILLING_DISABLED); final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>(); set.add(event0); set.add(event1); set.add(event2); set.add(event3); final Iterator<BillingEvent> it = set.iterator(); Assert.assertEquals(event1, it.next()); Assert.assertEquals(event0, it.next()); Assert.assertEquals(event3, it.next()); Assert.assertEquals(event2, it.next()); }
@Test(groups = "fast") public void testEdgeCaseAllEventsHappenAtTheSameTime() throws Exception { final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.START_BILLING_DISABLED); final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE, 1); final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CHANGE, 2); // Note the time delta here. Having a blocking duration of zero and events at the same time won't work as the backing tree set does local // comparisons (and not global), making the END_BILLING_DISABLED start the first one in the set final BillingEvent event3 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:05.000Z"), SubscriptionBaseTransitionType.END_BILLING_DISABLED); final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>(); set.add(event0); set.add(event1); set.add(event2); set.add(event3); final Iterator<BillingEvent> it = set.iterator(); Assert.assertEquals(event1, it.next()); Assert.assertEquals(event2, it.next()); Assert.assertEquals(event0, it.next()); Assert.assertEquals(event3, it.next()); }
@Test(groups = "fast") public void testToString() throws Exception { // Simple test to ensure we have an easy to read toString representation final BillingEvent event = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z", DateTimeZone.UTC), SubscriptionBaseTransitionType.CREATE); Assert.assertEquals(event.toString(), "DefaultBillingEvent{type=CREATE, effectiveDate=2012-01-01T00:02:04.000Z, planPhaseName=Test-trial, subscriptionId=00000000-0000-0000-0000-000000000000, totalOrdering=1, accountId=" + event.getAccount().getId().toString() + "}"); }