Search in sources :

Example 46 with DefaultBlockingState

use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.

the class TestDefaultSubscriptionBundleTimeline method testRemoveOverlappingBlockingStatesImpl.

public void testRemoveOverlappingBlockingStatesImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
    clock.setDay(new LocalDate(2013, 1, 1));
    final DateTimeZone accountTimeZone = DateTimeZone.UTC;
    final UUID accountId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final String externalKey = "foo";
    final UUID entitlementId = UUID.randomUUID();
    final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
    final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
    DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
    final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
    allTransitions.add(tr1);
    if (!regressionFlagForOlderVersionThan_0_17_X) {
        final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
        blockingStates.add(bsCreate);
    }
    // Overlapping ENT_STATE_BLOCKED - should merge
    effectiveDate = effectiveDate.plusDays(5);
    clock.addDays(5);
    final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
    blockingStates.add(bs1);
    effectiveDate = effectiveDate.plusDays(1);
    clock.addDays(1);
    final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 1L);
    blockingStates.add(bs2);
    // Overlapping ENT_STATE_CANCELLED - should merge
    effectiveDate = effectiveDate.plusDays(1);
    clock.addDays(1);
    final BlockingState bs3 = new DefaultBlockingState(UUID.randomUUID(), accountId, BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_CANCELLED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 2L);
    blockingStates.add(bs3);
    final BlockingState bs4 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CANCELLED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 3L);
    blockingStates.add(bs4);
    final List<Entitlement> entitlements = new ArrayList<Entitlement>();
    final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
    entitlements.add(entitlement);
    final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
    final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
    assertEquals(events.size(), 4);
    assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
    assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
    assertEquals(events.get(0).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertEquals(events.get(2).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(3).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertNull(events.get(0).getPrevPhase());
    assertNull(events.get(1).getPrevPhase());
    assertEquals(events.get(1).getNextPhase().getName(), "trial");
    assertEquals(events.get(2).getPrevPhase().getName(), "trial");
    assertEquals(events.get(2).getNextPhase().getName(), "trial");
    assertEquals(events.get(3).getPrevPhase().getName(), "trial");
    assertNull(events.get(3).getNextPhase());
}
Also used : ArrayList(java.util.ArrayList) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) LocalDate(org.joda.time.LocalDate) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) UUID(java.util.UUID) SubscriptionBaseTransition(org.killbill.billing.subscription.api.user.SubscriptionBaseTransition) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Example 47 with DefaultBlockingState

use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.

the class TestDefaultSubscriptionBundleTimeline method testOneEntitlementWithOverduePauseThenCancelImpl.

private void testOneEntitlementWithOverduePauseThenCancelImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
    clock.setDay(new LocalDate(2013, 1, 1));
    final DateTimeZone accountTimeZone = DateTimeZone.UTC;
    final UUID accountId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final String externalKey = "foo";
    final UUID entitlementId = UUID.randomUUID();
    final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
    final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
    DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
    final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
    allTransitions.add(tr1);
    if (!regressionFlagForOlderVersionThan_0_17_X) {
        final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
        blockingStates.add(bsCreate);
    }
    effectiveDate = effectiveDate.plusDays(30);
    clock.addDays(30);
    final SubscriptionBaseTransition tr2 = createTransition(entitlementId, EventType.PHASE, null, effectiveDate, clock.getUTCNow(), "trial", "phase");
    allTransitions.add(tr2);
    final String overdueService = "overdue-service";
    effectiveDate = effectiveDate.plusDays(12);
    clock.addDays(12);
    final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), accountId, BlockingStateType.ACCOUNT, "ODE1", overdueService, true, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
    blockingStates.add(bs1);
    effectiveDate = effectiveDate.plusDays(42);
    clock.addDays(42);
    final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), accountId, BlockingStateType.ACCOUNT, "ODE2", overdueService, true, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 1L);
    blockingStates.add(bs2);
    effectiveDate = effectiveDate.plusDays(15);
    clock.addDays(15);
    final BlockingState bs3 = new DefaultBlockingState(UUID.randomUUID(), accountId, BlockingStateType.ACCOUNT, "ODE3", overdueService, true, true, true, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 2L);
    blockingStates.add(bs3);
    effectiveDate = effectiveDate.plusDays(15);
    clock.addDays(15);
    final BlockingState bs4 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 3L);
    blockingStates.add(bs4);
    effectiveDate = effectiveDate.plusDays(1);
    clock.addDays(1);
    final BlockingState bs5 = new DefaultBlockingState(UUID.randomUUID(), accountId, BlockingStateType.ACCOUNT, "ODE4", overdueService, true, true, true, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 4L);
    blockingStates.add(bs5);
    // Note: cancellation event and ODE4 at the same effective date (see https://github.com/killbill/killbill/issues/148)
    final SubscriptionBaseTransition tr3 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "phase", null);
    allTransitions.add(tr3);
    final List<Entitlement> entitlements = new ArrayList<Entitlement>();
    final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
    entitlements.add(entitlement);
    final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
    assertEquals(timeline.getAccountId(), accountId);
    assertEquals(timeline.getBundleId(), bundleId);
    assertEquals(timeline.getExternalKey(), externalKey);
    final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
    assertEquals(events.size(), 10);
    assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(6).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(7).getEffectiveDate().compareTo(new LocalDate(bs4.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(8).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(9).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE);
    assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE);
    assertEquals(events.get(4).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE);
    assertEquals(events.get(5).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
    assertEquals(events.get(6).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING);
    assertEquals(events.get(7).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
    assertEquals(events.get(8).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE);
    assertEquals(events.get(9).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
    assertEquals(events.get(0).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertEquals(events.get(2).getServiceName(), EntitlementOrderingBase.ENT_BILLING_SERVICE_NAME);
    assertEquals(events.get(3).getServiceName(), overdueService);
    assertEquals(events.get(4).getServiceName(), overdueService);
    assertEquals(events.get(5).getServiceName(), overdueService);
    assertEquals(events.get(6).getServiceName(), overdueService);
    assertEquals(events.get(7).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(8).getServiceName(), overdueService);
    assertEquals(events.get(9).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertNull(events.get(0).getPrevPhase());
    assertNull(events.get(1).getPrevPhase());
    assertEquals(events.get(1).getNextPhase().getName(), "trial");
    assertEquals(events.get(2).getPrevPhase().getName(), "trial");
    assertEquals(events.get(2).getNextPhase().getName(), "phase");
    assertEquals(events.get(3).getPrevPhase().getName(), "phase");
    assertEquals(events.get(3).getNextPhase().getName(), "phase");
    assertEquals(events.get(4).getPrevPhase().getName(), "phase");
    assertEquals(events.get(4).getNextPhase().getName(), "phase");
    assertEquals(events.get(5).getPrevPhase().getName(), "phase");
    assertEquals(events.get(5).getNextPhase().getName(), "phase");
    assertEquals(events.get(6).getPrevPhase().getName(), "phase");
    assertEquals(events.get(6).getNextPhase().getName(), "phase");
    assertEquals(events.get(7).getPrevPhase().getName(), "phase");
    assertNull(events.get(7).getNextPhase());
    assertEquals(events.get(8).getPrevPhase().getName(), "phase");
    assertNull(events.get(8).getNextPhase());
    assertEquals(events.get(9).getPrevPhase().getName(), "phase");
    assertNull(events.get(9).getNextPhase());
}
Also used : ArrayList(java.util.ArrayList) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) LocalDate(org.joda.time.LocalDate) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) UUID(java.util.UUID) SubscriptionBaseTransition(org.killbill.billing.subscription.api.user.SubscriptionBaseTransition) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Example 48 with DefaultBlockingState

use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.

the class TestDefaultSubscriptionBundleTimeline method testWithOverdueOfflineImpl.

private void testWithOverdueOfflineImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
    clock.setDay(new LocalDate(2013, 1, 1));
    final DateTimeZone accountTimeZone = DateTimeZone.UTC;
    final UUID accountId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final String externalKey = "foo";
    final UUID entitlementId = UUID.randomUUID();
    final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
    final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
    DateTime effectiveDate = new DateTime(2013, 1, 1, 23, 11, 8, 0, DateTimeZone.UTC);
    final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
    allTransitions.add(tr1);
    if (!regressionFlagForOlderVersionThan_0_17_X) {
        final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
        blockingStates.add(bsCreate);
    }
    effectiveDate = effectiveDate.plusDays(30);
    clock.addDays(30);
    final SubscriptionBaseTransition tr2 = createTransition(entitlementId, EventType.PHASE, null, effectiveDate, clock.getUTCNow(), "trial", "phase");
    allTransitions.add(tr2);
    // 2013-03-12
    effectiveDate = effectiveDate.plusDays(40);
    clock.addDays(40);
    final SubscriptionBaseTransition tr3 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "phase", null);
    allTransitions.add(tr3);
    // Verify the timeline without the blocking state events
    final ImmutableList<Entitlement> entitlementsWithoutBlockingStates = ImmutableList.<Entitlement>of(createEntitlement(entitlementId, allTransitions, blockingStates));
    final List<SubscriptionEvent> eventsWithoutBlockingStates = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlementsWithoutBlockingStates, internalCallContext).getSubscriptionEvents();
    assertEquals(eventsWithoutBlockingStates.size(), 4);
    assertEquals(eventsWithoutBlockingStates.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(eventsWithoutBlockingStates.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(eventsWithoutBlockingStates.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE);
    assertEquals(eventsWithoutBlockingStates.get(3).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
    final String service = "overdue-service";
    final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.ACCOUNT, "OFFLINE", service, true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
    blockingStates.add(bs1);
    // Verify the timeline with the overdue event blocking the entitlement
    final ImmutableList<Entitlement> entitlementsWithOverdueEvent = ImmutableList.<Entitlement>of(createEntitlement(entitlementId, allTransitions, blockingStates));
    final List<SubscriptionEvent> eventsWithOverdueEvent = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlementsWithOverdueEvent, internalCallContext).getSubscriptionEvents();
    assertEquals(eventsWithOverdueEvent.size(), 5);
    assertEquals(eventsWithOverdueEvent.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(eventsWithOverdueEvent.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(eventsWithOverdueEvent.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE);
    assertEquals(eventsWithOverdueEvent.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
    assertEquals(eventsWithOverdueEvent.get(4).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
    final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 1L);
    blockingStates.add(bs2);
    final List<Entitlement> entitlements = new ArrayList<Entitlement>();
    final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
    entitlements.add(entitlement);
    // Verify the timeline with both the overdue event and the entitlement cancel event
    final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
    assertEquals(timeline.getAccountId(), accountId);
    assertEquals(timeline.getBundleId(), bundleId);
    assertEquals(timeline.getExternalKey(), externalKey);
    final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
    assertEquals(events.size(), 6);
    assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE);
    assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
    assertEquals(events.get(4).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
    assertEquals(events.get(5).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
    assertEquals(events.get(0).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertEquals(events.get(2).getServiceName(), EntitlementOrderingBase.ENT_BILLING_SERVICE_NAME);
    assertEquals(events.get(3).getServiceName(), service);
    assertEquals(events.get(4).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(5).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertNull(events.get(0).getPrevPhase());
    assertNull(events.get(1).getPrevPhase());
    assertEquals(events.get(1).getNextPhase().getName(), "trial");
    assertEquals(events.get(2).getPrevPhase().getName(), "trial");
    assertEquals(events.get(2).getNextPhase().getName(), "phase");
    assertEquals(events.get(3).getPrevPhase().getName(), "phase");
    assertEquals(events.get(3).getNextPhase().getName(), "phase");
    assertEquals(events.get(4).getPrevPhase().getName(), "phase");
    assertNull(events.get(4).getNextPhase());
    assertEquals(events.get(5).getPrevPhase().getName(), "phase");
    assertNull(events.get(5).getNextPhase());
}
Also used : ArrayList(java.util.ArrayList) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) LocalDate(org.joda.time.LocalDate) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) UUID(java.util.UUID) SubscriptionBaseTransition(org.killbill.billing.subscription.api.user.SubscriptionBaseTransition) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Example 49 with DefaultBlockingState

use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.

the class TestBlockingChecker method setStateSubscription.

private void setStateSubscription(final boolean bC, final boolean bE, final boolean bB) {
    final BlockingState subscriptionState = new DefaultBlockingState(subscription.getId(), BlockingStateType.SUBSCRIPTION, "state", "test-service", bC, bE, bB, clock.getUTCNow());
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(subscriptionState, Optional.<UUID>of(subscription.getBundleId())), internalCallContext);
}
Also used : DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Example 50 with DefaultBlockingState

use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.

the class TestBlockingChecker method setStateBundle.

private void setStateBundle(final boolean bC, final boolean bE, final boolean bB) {
    final BlockingState bundleState = new DefaultBlockingState(bundle.getId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "state", "test-service", bC, bE, bB, clock.getUTCNow());
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(bundleState, Optional.<UUID>absent()), internalCallContext);
}
Also used : DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Aggregations

DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)63 UUID (java.util.UUID)46 DateTime (org.joda.time.DateTime)38 BlockingState (org.killbill.billing.entitlement.api.BlockingState)37 Test (org.testng.annotations.Test)35 LocalDate (org.joda.time.LocalDate)34 Account (org.killbill.billing.account.api.Account)23 ArrayList (java.util.ArrayList)21 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)19 DateTimeZone (org.joda.time.DateTimeZone)14 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)14 SubscriptionBaseTransition (org.killbill.billing.subscription.api.user.SubscriptionBaseTransition)11 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)9 Entitlement (org.killbill.billing.entitlement.api.Entitlement)8 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)7 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)7 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)7 BigDecimal (java.math.BigDecimal)6 BillingEvent (org.killbill.billing.junction.BillingEvent)6