Search in sources :

Example 16 with SubscriptionBaseTransition

use of org.killbill.billing.subscription.api.user.SubscriptionBaseTransition in project killbill by killbill.

the class TestDefaultSubscriptionBundleTimeline method testOneSimpleEntitlementImpl.

private void testOneSimpleEntitlementImpl(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 String externalKey = "foo";
    final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
    final UUID entitlementId = UUID.randomUUID();
    final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
    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, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, 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);
    effectiveDate = effectiveDate.plusDays(15);
    clock.addDays(15);
    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(), 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(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(3).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.STOP_BILLING);
    assertEquals(events.get(0).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
    assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertEquals(events.get(2).getServiceName(), EntitlementOrderingBase.ENT_BILLING_SERVICE_NAME);
    assertEquals(events.get(3).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");
    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 17 with SubscriptionBaseTransition

use of org.killbill.billing.subscription.api.user.SubscriptionBaseTransition in project killbill by killbill.

the class TestPlanAligner method changeSubscription.

private void changeSubscription(final DateTime effectiveChangeDate, final DefaultSubscriptionBase defaultSubscriptionBase, final String previousProductName, final String newProductName, final PhaseType commonPhaseType) throws CatalogApiException {
    final SubscriptionBaseEvent previousEvent = createSubscriptionEvent(defaultSubscriptionBase.getStartDate(), previousProductName, commonPhaseType, ApiEventType.CREATE);
    final SubscriptionBaseEvent event = createSubscriptionEvent(effectiveChangeDate, newProductName, commonPhaseType, ApiEventType.CHANGE);
    final List<SubscriptionBaseEvent> events = new ArrayList<SubscriptionBaseEvent>();
    events.add(previousEvent);
    events.add(event);
    defaultSubscriptionBase.rebuildTransitions(events, catalogService.getFullCatalog(true, true, internalCallContext));
    final List<SubscriptionBaseTransition> newTransitions = defaultSubscriptionBase.getAllTransitions();
    Assert.assertEquals(newTransitions.size(), 2);
    Assert.assertNull(newTransitions.get(0).getPreviousPhase());
    Assert.assertEquals(newTransitions.get(0).getNextPhase(), newTransitions.get(1).getPreviousPhase());
    Assert.assertNotNull(newTransitions.get(1).getNextPhase());
}
Also used : ArrayList(java.util.ArrayList) SubscriptionBaseTransition(org.killbill.billing.subscription.api.user.SubscriptionBaseTransition) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent)

Aggregations

SubscriptionBaseTransition (org.killbill.billing.subscription.api.user.SubscriptionBaseTransition)17 ArrayList (java.util.ArrayList)12 UUID (java.util.UUID)12 DateTime (org.joda.time.DateTime)12 LocalDate (org.joda.time.LocalDate)12 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)12 DateTimeZone (org.joda.time.DateTimeZone)10 Product (org.killbill.billing.catalog.api.Product)2 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)2 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 Account (org.killbill.billing.account.api.Account)1 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)1 PhaseType (org.killbill.billing.catalog.api.PhaseType)1 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)1 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)1 ProductCategory (org.killbill.billing.catalog.api.ProductCategory)1 BlockingState (org.killbill.billing.entitlement.api.BlockingState)1