Search in sources :

Example 11 with DisabledDuration

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

the class TestBlockingCalculator method testCreateNewEventsClosedPrevBetw.

// Closed duration with a previous event and in-between event
// --X--[------Y-----]---------------------
@Test(groups = "fast")
public void testCreateNewEventsClosedPrevBetw() 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));
    billingEvents.add(createRealEvent(now.plusDays(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 12 with DisabledDuration

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

the class TestBlockingCalculator method testCreateNewEventsOpenPrevFollow.

// Open with previous and following events
// --X--[----Y-----------------------------
@Test(groups = "fast")
public void testCreateNewEventsOpenPrevFollow() 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.minusDays(1), subscription1));
    billingEvents.add(createRealEvent(now.plusDays(1), subscription1));
    final SortedSet<BillingEvent> results = blockingCalculator.createNewEvents(disabledDuration, billingEvents, subscription1, internalCallContext);
    assertEquals(results.size(), 1);
    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);
}
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 13 with DisabledDuration

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

the class TestBlockingCalculator method testEventsToRemoveClosedFollow.

// Closed duration with only following
// -----[------------]-------Z-------------
@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);
}
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 14 with DisabledDuration

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

the class TestBlockingCalculator method testCreateNewEventsClosedFollow.

// Closed duration with only following
// -----[------------]-------Z-------------
@Test(groups = "fast")
public void testCreateNewEventsClosedFollow() 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(3), 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 15 with DisabledDuration

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

the class TestBlockingCalculator method testCreateDisablePairs.

@Test(groups = "fast")
public void testCreateDisablePairs() {
    List<BlockingState> blockingEvents;
    final UUID ovdId = UUID.randomUUID();
    final UUID ovdId2 = UUID.randomUUID();
    final DateTime now = clock.getUTCNow();
    // Simple events open clear -> disabled
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    List<DisabledDuration> pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertNotNull(pairs.get(0).getStart());
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertNull(pairs.get(0).getEnd());
    // Simple events closed clear -> disabled
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2)));
    pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertNotNull(pairs.get(0).getStart());
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertNotNull(pairs.get(0).getEnd());
    assertEquals(pairs.get(0).getEnd(), now.plusDays(2));
    // Simple BUNDLE events closed clear -> disabled
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2)));
    pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertNotNull(pairs.get(0).getStart());
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertNotNull(pairs.get(0).getEnd());
    assertEquals(pairs.get(0).getEnd(), now.plusDays(2));
    // Two or more disabled in a row
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(2)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(3)));
    pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertNotNull(pairs.get(0).getStart());
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertNotNull(pairs.get(0).getEnd());
    assertEquals(pairs.get(0).getEnd(), now.plusDays(3));
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(2)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(3)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(4)));
    pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertNotNull(pairs.get(0).getStart());
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertNotNull(pairs.get(0).getEnd());
    assertEquals(pairs.get(0).getEnd(), now.plusDays(4));
    // Verify ordering at the same effective date doesn't matter. This is to work around nondeterministic ordering
    // behavior in ProxyBlockingStateDao#BLOCKING_STATE_ORDERING_WITH_TIES_UNHANDLED. See also TestDefaultInternalBillingApi.
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2)));
    blockingEvents.add(new DefaultBlockingState(ovdId2, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(2)));
    blockingEvents.add(new DefaultBlockingState(ovdId2, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(3)));
    pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertEquals(pairs.get(0).getEnd(), now.plusDays(3));
    blockingEvents = new ArrayList<BlockingState>();
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)));
    blockingEvents.add(new DefaultBlockingState(ovdId2, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(2)));
    blockingEvents.add(new DefaultBlockingState(ovdId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2)));
    blockingEvents.add(new DefaultBlockingState(ovdId2, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(3)));
    pairs = blockingCalculator.createBlockingDurations(blockingEvents);
    assertEquals(pairs.size(), 1);
    assertEquals(pairs.get(0).getStart(), now.plusDays(1));
    assertEquals(pairs.get(0).getEnd(), now.plusDays(3));
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) 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