Search in sources :

Example 1 with DisabledDuration

use of org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration in project killbill by killbill.

the class TestBlockingCalculator method testCreateNewEventsOpenFollow.

// Open with no previous event (only following)
// -----[----X-----------------------------
@Test(groups = "fast")
public void testCreateNewEventsOpenFollow() 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, null));
    billingEvents.add(createRealEvent(now.plusDays(1), subscription1));
    final SortedSet<BillingEvent> results = blockingCalculator.createNewEvents(disabledDuration, billingEvents, subscription1, internalCallContext);
    assertEquals(results.size(), 0);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with DisabledDuration

use of org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration 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);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with DisabledDuration

use of org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration 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);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with DisabledDuration

use of org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration 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);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with DisabledDuration

use of org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration in project killbill by killbill.

the class TestBlockingCalculator method testEventsToRemoveOpenPrev.

// Open ended duration with a previous event
// --X--[----------------------------------
@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);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

DateTime (org.joda.time.DateTime)19 DisabledDuration (org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration)19 Test (org.testng.annotations.Test)19 ArrayList (java.util.ArrayList)18 TreeSet (java.util.TreeSet)18 BillingEvent (org.killbill.billing.junction.BillingEvent)18 UUID (java.util.UUID)1 BlockingState (org.killbill.billing.entitlement.api.BlockingState)1 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)1