use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestBlockingCalculator method testSimpleWithClearBlockingDuration.
@Test(groups = "fast")
public void testSimpleWithClearBlockingDuration() throws Exception {
final BillingEvent trial = createRealEvent(new LocalDate(2012, 5, 1).toDateTimeAtStartOfDay(DateTimeZone.UTC), subscription1, SubscriptionBaseTransitionType.CREATE);
final BillingEvent phase = createRealEvent(new LocalDate(2012, 5, 31).toDateTimeAtStartOfDay(DateTimeZone.UTC), subscription1, SubscriptionBaseTransitionType.PHASE);
final BillingEvent upgrade = createRealEvent(new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC), subscription1, SubscriptionBaseTransitionType.CHANGE);
final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>();
billingEvents.add(trial);
billingEvents.add(phase);
billingEvents.add(upgrade);
final BlockingState blockingState1 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, false, false, new LocalDate(2012, 7, 5).toDateTimeAtStartOfDay(DateTimeZone.UTC));
final BlockingState blockingState2 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, new LocalDate(2012, 7, 15).toDateTimeAtStartOfDay(DateTimeZone.UTC));
final BlockingState blockingState3 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, new LocalDate(2012, 7, 24).toDateTimeAtStartOfDay(DateTimeZone.UTC));
final BlockingState blockingState4 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC));
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState1, Optional.<UUID>absent(), blockingState2, Optional.<UUID>absent(), blockingState3, Optional.<UUID>absent(), blockingState4, Optional.<UUID>absent()), internalCallContext);
blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), internalCallContext);
assertEquals(billingEvents.size(), 5);
final List<BillingEvent> events = new ArrayList<BillingEvent>(billingEvents);
assertEquals(events.get(0).getEffectiveDate(), new LocalDate(2012, 5, 1).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE);
assertEquals(events.get(1).getEffectiveDate(), new LocalDate(2012, 5, 31).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(1).getTransitionType(), SubscriptionBaseTransitionType.PHASE);
assertEquals(events.get(2).getEffectiveDate(), new LocalDate(2012, 7, 15).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(2).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
assertEquals(events.get(3).getEffectiveDate(), new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(3).getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
assertEquals(events.get(4).getEffectiveDate(), new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(4).getTransitionType(), SubscriptionBaseTransitionType.CHANGE);
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestBlockingCalculator method testCreateNewEventsClosedBetweenFollow.
// Closed with no previous event but in-between events and following
// -----[------Y-----]-------Z-------------
@Test(groups = "fast")
public void testCreateNewEventsClosedBetweenFollow() throws CatalogApiException {
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)));
billingEvents.add(createRealEvent(now.plusDays(1), subscription1));
final SortedSet<BillingEvent> results = blockingCalculator.createNewEvents(disabledDuration, billingEvents, subscription1, internalCallContext);
assertEquals(results.size(), 1);
assertEquals(results.last().getEffectiveDate(), now.plusDays(2));
assertEquals(results.last().getRecurringPrice(null), billingEvents.first().getRecurringPrice(null));
assertEquals(results.last().getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestBlockingCalculator method testCreateNewEventsClosedPrev.
// Closed duration with a single previous event
// --X--[------------]---------------------
@Test(groups = "fast")
public void testCreateNewEventsClosedPrev() throws CatalogApiException {
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)));
billingEvents.add(createRealEvent(now.minusDays(1), subscription1));
final SortedSet<BillingEvent> results = blockingCalculator.createNewEvents(disabledDuration, billingEvents, subscription1, internalCallContext);
assertEquals(results.size(), 2);
assertEquals(results.first().getEffectiveDate(), now);
assertNull(results.first().getFixedPrice());
assertNull(results.first().getRecurringPrice(null));
assertEquals(results.first().getBillingPeriod(), BillingPeriod.NO_BILLING_PERIOD);
assertEquals(results.first().getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
assertEquals(results.last().getEffectiveDate(), now.plusDays(2));
assertEquals(results.last().getRecurringPrice(null), billingEvents.first().getRecurringPrice(null));
assertEquals(results.last().getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestBlockingCalculator method testEventsToRemoveClosedPrevBetwNext.
// Closed duration with a previous event and in-between event and following
// --X--[------Y-----]-------Z-------------
@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);
}
use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.
the class TestDefaultBillingEvent method testEntitlementEventsHappeningAtTheSameTimeAsOverdueEvents.
@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());
}
Aggregations