use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestDefaultBillingEvent method testToString.
@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}");
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestDefaultBillingEvent method testEdgeCaseAllEventsHappenAtTheSameTime.
@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());
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestDefaultBillingEvent method testEventTotalOrdering.
@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.CANCEL, 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());
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestDefaultBillingEvent method testEventOrderingDate.
@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());
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class BlockingCalculator method precedingBillingEventForSubscription.
protected BillingEvent precedingBillingEventForSubscription(final DateTime datetime, final SortedSet<BillingEvent> billingEvents, final SubscriptionBase subscription) {
if (datetime == null) {
//second of a pair can be null if there's no re-enabling
return null;
}
final SortedSet<BillingEvent> filteredBillingEvents = filter(billingEvents, subscription);
BillingEvent result = filteredBillingEvents.first();
if (datetime.isBefore(result.getEffectiveDate())) {
//This case can happen, for example, if we have an add on and the bundle goes into disabled before the add on is created
return null;
}
for (final BillingEvent event : filteredBillingEvents) {
if (!event.getEffectiveDate().isBefore(datetime)) {
// found it its the previous event
return result;
} else {
// still looking
result = event;
}
}
return result;
}
Aggregations