Search in sources :

Example 31 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiAddOn method testChangeBPWithAddonIncluded.

@Test(groups = "slow")
public void testChangeBPWithAddonIncluded() throws SubscriptionBaseApiException {
    final String baseProduct = "Shotgun";
    final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
    final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // CREATE BP
    DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
    final String aoProduct = "Telescopic-Scope";
    final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
    final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    // MOVE CLOCK AFTER TRIAL + AO DISCOUNT
    final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(2));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD TO CHANGE IN FUTURE
    final DateTime now = clock.getUTCNow();
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(now, ctd);
    subscriptionInternalApi.setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate, internalCallContext);
    baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    // CHANGE IMMEDIATELY WITH TO BP WITH NON INCLUDED ADDON
    final String newBaseProduct = "Assault-Rifle";
    final BillingPeriod newBaseTerm = BillingPeriod.MONTHLY;
    final String newBasePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    final List<EntitlementAOStatusDryRun> aoStatus = subscriptionInternalApi.getDryRunChangePlanStatus(baseSubscription.getId(), newBaseProduct, now, internalCallContext);
    assertEquals(aoStatus.size(), 1);
    assertEquals(aoStatus.get(0).getId(), aoSubscription.getId());
    assertEquals(aoStatus.get(0).getProductName(), aoProduct);
    assertEquals(aoStatus.get(0).getBillingPeriod(), aoTerm);
    assertEquals(aoStatus.get(0).getPhaseType(), aoSubscription.getCurrentPhase().getPhaseType());
    assertEquals(aoStatus.get(0).getPriceList(), aoSubscription.getCurrentPriceList().getName());
    assertEquals(aoStatus.get(0).getReason(), DryRunChangeReason.AO_INCLUDED_IN_NEW_PLAN);
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    baseSubscription.changePlan(new PlanSpecifier(newBaseProduct, newBaseTerm, newBasePriceList), null, callContext);
    assertListenerStatus();
    // REFETCH AO SUBSCRIPTION AND CHECK THIS CANCELLED
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    assertEquals(aoSubscription.getState(), EntitlementState.CANCELLED);
    assertListenerStatus();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) EntitlementAOStatusDryRun(org.killbill.billing.entitlement.api.EntitlementAOStatusDryRun) Duration(org.killbill.billing.catalog.api.Duration) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 32 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiAddOn method testAddonCreateWithBundleAlign.

@Test(groups = "slow")
public void testAddonCreateWithBundleAlign() throws CatalogApiException, SubscriptionBaseApiException {
    final String aoProduct = "Telescopic-Scope";
    final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
    final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // This is just to double check our test catalog gives us what we want before we start the test
    final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct, aoTerm, aoPriceList);
    final PlanAlignmentCreate alignement = catalog.planCreateAlignment(planSpecifier, clock.getUTCNow());
    assertEquals(alignement, PlanAlignmentCreate.START_OF_BUNDLE);
    testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignement);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 33 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiChangePlan method testMultipleChangeLastIMM.

@Test(groups = "slow")
public void testMultipleChangeLastIMM() throws SubscriptionBillingApiException, SubscriptionBaseApiException {
    DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, "Assault-Rifle", BillingPeriod.MONTHLY, "gunclubDiscount");
    final PlanPhase trialPhase = subscription.getCurrentPhase();
    assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
    // MOVE TO NEXT PHASE
    testListener.pushExpectedEvent(NextEvent.PHASE);
    final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD
    final List<Duration> durationList = new ArrayList<Duration>();
    durationList.add(trialPhase.getDuration());
    //durationList.add(subscription.getCurrentPhase().getDuration());
    final DateTime startDiscountPhase = TestSubscriptionHelper.addDuration(subscription.getStartDate(), durationList);
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(startDiscountPhase, ctd);
    subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
    subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    // CHANGE EOT
    subscription.changePlan(new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, "gunclubDiscount"), null, callContext);
    assertListenerStatus();
    // CHANGE
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    subscription.changePlan(new PlanSpecifier("Assault-Rifle", BillingPeriod.ANNUAL, "gunclubDiscount"), null, callContext);
    assertListenerStatus();
    final Plan currentPlan = subscription.getCurrentPlan();
    assertNotNull(currentPlan);
    assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle");
    assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE);
    assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
    final PlanPhase currentPhase = subscription.getCurrentPhase();
    assertNotNull(currentPhase);
    assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
    assertListenerStatus();
}
Also used : ArrayList(java.util.ArrayList) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Duration(org.killbill.billing.catalog.api.Duration) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 34 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiChangePlan method testMultipleChangeLastEOT.

@Test(groups = "slow")
public void testMultipleChangeLastEOT() throws SubscriptionBillingApiException, SubscriptionBaseApiException {
    DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, "Assault-Rifle", BillingPeriod.ANNUAL, "gunclubDiscount");
    final PlanPhase trialPhase = subscription.getCurrentPhase();
    assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD
    final List<Duration> durationList = new ArrayList<Duration>();
    durationList.add(trialPhase.getDuration());
    final DateTime startDiscountPhase = TestSubscriptionHelper.addDuration(subscription.getStartDate(), durationList);
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(startDiscountPhase, ctd);
    subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
    subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    // CHANGE EOT
    subscription.changePlan(new PlanSpecifier("Shotgun", BillingPeriod.MONTHLY, "gunclubDiscount"), null, callContext);
    assertListenerStatus();
    // CHANGE EOT
    subscription.changePlan(new PlanSpecifier("Pistol", BillingPeriod.ANNUAL, "gunclubDiscount"), null, callContext);
    assertListenerStatus();
    // CHECK NO CHANGE OCCURED YET
    Plan currentPlan = subscription.getCurrentPlan();
    assertNotNull(currentPlan);
    assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle");
    assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE);
    assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
    PlanPhase currentPhase = subscription.getCurrentPhase();
    assertNotNull(currentPhase);
    assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
    // ACTIVATE CHANGE BY MOVING AFTER CTD
    testListener.pushExpectedEvents(NextEvent.CHANGE);
    it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    currentPlan = subscription.getCurrentPlan();
    assertNotNull(currentPlan);
    assertEquals(currentPlan.getProduct().getName(), "Pistol");
    assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE);
    assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
    currentPhase = subscription.getCurrentPhase();
    assertNotNull(currentPhase);
    assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
    // MOVE TO NEXT PHASE
    testListener.pushExpectedEvent(NextEvent.PHASE);
    it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(6));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    currentPlan = subscription.getCurrentPlan();
    assertNotNull(currentPlan);
    assertEquals(currentPlan.getProduct().getName(), "Pistol");
    assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE);
    assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
    currentPhase = subscription.getCurrentPhase();
    assertNotNull(currentPhase);
    assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
    assertListenerStatus();
}
Also used : ArrayList(java.util.ArrayList) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Duration(org.killbill.billing.catalog.api.Duration) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 35 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiChangePlan method tChangePlanBundleAlignIMM.

private void tChangePlanBundleAlignIMM(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet, final String toProd, final BillingPeriod toTerm, final String toPlanSet) throws SubscriptionBaseApiException {
    final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
    clock.addDeltaFromReality(it.toDurationMillis());
    // CHANGE PLAN IMM
    subscription.changePlan(new PlanSpecifier(toProd, toTerm, toPlanSet), null, callContext);
    checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.TRIAL);
    assertListenerStatus();
    final PlanPhase currentPhase = subscription.getCurrentPhase();
    final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), currentPhase.getDuration());
    testUtil.checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange);
    // NEXT PHASE
    testListener.pushExpectedEvent(NextEvent.PHASE);
    it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(30));
    clock.addDeltaFromReality(it.toDurationMillis());
    final DateTime futureNow = clock.getUTCNow();
    assertTrue(futureNow.isAfter(nextExpectedPhaseChange));
    assertListenerStatus();
}
Also used : PlanPhase(org.killbill.billing.catalog.api.PlanPhase) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Aggregations

PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)39 Test (org.testng.annotations.Test)28 DateTime (org.joda.time.DateTime)16 Interval (org.joda.time.Interval)11 LocalDate (org.joda.time.LocalDate)9 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)7 Duration (org.killbill.billing.catalog.api.Duration)7 Account (org.killbill.billing.account.api.Account)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)6 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)6 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)5 Plan (org.killbill.billing.catalog.api.Plan)5 ArrayList (java.util.ArrayList)4 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)4 PlanAlignmentCreate (org.killbill.billing.catalog.api.PlanAlignmentCreate)4 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 BigDecimal (java.math.BigDecimal)3 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)3