Search in sources :

Example 66 with BillingPeriod

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

the class TestTransfer method testTransferBPNoTrialWithCTD.

@Test(groups = "slow")
public void testTransferBPNoTrialWithCTD() throws Exception {
    final String baseProduct = "Shotgun";
    final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
    final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // CREATE BP
    final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
    // MOVE AFTER TRIAL
    testListener.pushExpectedEvent(NextEvent.PHASE);
    clock.addDays(40);
    assertListenerStatus();
    // SET CTD
    final DateTime ctd = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
    subscriptionInternalApi.setChargedThroughDate(baseSubscription.getId(), ctd, internalCallContext);
    final DateTime transferRequestedDate = clock.getUTCNow();
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext);
    assertListenerStatus();
    // CHECK OLD BASE IS CANCEL AT THE TRANSFER DATE
    final SubscriptionBase oldBaseSubscription = subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    assertNotNull(oldBaseSubscription.getFutureEndDate());
    assertTrue(oldBaseSubscription.getFutureEndDate().compareTo(ctd) == 0);
    // CHECK NEW BUNDLE EXIST, WITH ONE SUBSCRIPTION STARTING ON TRANSFER_DATE
    final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext);
    assertEquals(bundlesForAccountAndKey.size(), 1);
    final SubscriptionBaseBundle newBundle = bundlesForAccountAndKey.get(0);
    final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), null, internalCallContext);
    assertEquals(subscriptions.size(), 1);
    final SubscriptionBase newBaseSubscription = subscriptions.get(0);
    assertTrue(((DefaultSubscriptionBase) newBaseSubscription).getAlignStartDate().compareTo(((DefaultSubscriptionBase) baseSubscription).getAlignStartDate()) == 0);
    // CHECK ONLY ONE PHASE EXISTS
    assertEquals(subscriptionInternalApi.getAllTransitions(newBaseSubscription, internalCallContext).size(), 1);
    Plan newPlan = newBaseSubscription.getCurrentPlan();
    assertEquals(newPlan.getProduct().getName(), baseProduct);
    assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
    // MAKE A PLAN CHANGE IMM
    clock.addDays(5);
    final String newBaseProduct1 = "Assault-Rifle";
    final BillingPeriod newBaseTerm1 = BillingPeriod.ANNUAL;
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    newBaseSubscription.changePlan(new PlanSpecifier(newBaseProduct1, newBaseTerm1, basePriceList), null, callContext);
    assertListenerStatus();
    newPlan = newBaseSubscription.getCurrentPlan();
    assertEquals(newPlan.getProduct().getName(), newBaseProduct1);
    assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
    // SET CTD AND MAKE CHANGE EOT
    clock.addDays(2);
    final DateTime newCtd = newBaseSubscription.getStartDate().plusYears(1);
    subscriptionInternalApi.setChargedThroughDate(newBaseSubscription.getId(), newCtd, internalCallContext);
    final SubscriptionBase newBaseSubscriptionWithCtd = subscriptionInternalApi.getSubscriptionFromId(newBaseSubscription.getId(), internalCallContext);
    final String newBaseProduct2 = "Pistol";
    final BillingPeriod newBaseTerm2 = BillingPeriod.ANNUAL;
    newBaseSubscriptionWithCtd.changePlan(new PlanSpecifier(newBaseProduct2, newBaseTerm2, basePriceList), null, callContext);
    newPlan = newBaseSubscriptionWithCtd.getCurrentPlan();
    assertEquals(newPlan.getProduct().getName(), newBaseProduct1);
    assertEquals(newBaseSubscriptionWithCtd.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
    assertNotNull(newBaseSubscriptionWithCtd.getPendingTransition());
    assertEquals(newBaseSubscriptionWithCtd.getPendingTransition().getEffectiveTransitionTime(), newCtd);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 67 with BillingPeriod

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

the class TestTransfer method testTransferWithUncancel.

@Test(groups = "slow")
public void testTransferWithUncancel() throws Exception {
    final String baseProduct = "Shotgun";
    final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
    final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // CREATE BP
    SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    clock.addDays(30);
    assertListenerStatus();
    // SET CTD TO TRIGGER CANCELLATION EOT
    final DateTime ctd = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
    subscriptionInternalApi.setChargedThroughDate(baseSubscription.getId(), ctd, internalCallContext);
    // CANCEL BP
    baseSubscription = subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    baseSubscription.cancel(callContext);
    // MOVE CLOCK one day AHEAD AND UNCANCEL BP
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.UNCANCEL);
    baseSubscription.uncancel(callContext);
    assertListenerStatus();
    // MOVE CLOCK one day AHEAD AND UNCANCEL BP
    clock.addDays(1);
    final DateTime transferRequestedDate = clock.getUTCNow();
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext);
    assertListenerStatus();
    final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext);
    assertEquals(bundlesForAccountAndKey.size(), 1);
    final SubscriptionBaseBundle newBundle = bundlesForAccountAndKey.get(0);
    final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), null, internalCallContext);
    assertEquals(subscriptions.size(), 1);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 68 with BillingPeriod

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

the class TestUserApiAddOn method testAddonCreateInternal.

private void testAddonCreateInternal(final String aoProduct, final BillingPeriod aoTerm, final String aoPriceList, final PlanAlignmentCreate expAlignement) throws SubscriptionBaseApiException {
    final String baseProduct = "Shotgun";
    final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
    final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // CREATE BP
    final DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
    // MOVE CLOCK 14 DAYS LATER
    Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14));
    clock.addDeltaFromReality(it.toDurationMillis());
    // CREATE ADDON
    final DateTime beforeAOCreation = clock.getUTCNow();
    DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
    final DateTime afterAOCreation = clock.getUTCNow();
    // CHECK EVERYTHING
    Plan aoCurrentPlan = aoSubscription.getCurrentPlan();
    assertNotNull(aoCurrentPlan);
    assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct);
    assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON);
    assertEquals(aoCurrentPlan.getRecurringBillingPeriod(), aoTerm);
    PlanPhase aoCurrentPhase = aoSubscription.getCurrentPhase();
    assertNotNull(aoCurrentPhase);
    assertEquals(aoCurrentPhase.getPhaseType(), PhaseType.DISCOUNT);
    testUtil.assertDateWithin(aoSubscription.getStartDate(), beforeAOCreation, afterAOCreation);
    assertEquals(aoSubscription.getBundleStartDate(), baseSubscription.getBundleStartDate());
    // CHECK next AO PHASE EVENT IS INDEED A MONTH AFTER BP STARTED => BUNDLE ALIGNMENT
    SubscriptionBaseTransition aoPendingTranstion = aoSubscription.getPendingTransition();
    if (expAlignement == PlanAlignmentCreate.START_OF_BUNDLE) {
        assertEquals(aoPendingTranstion.getEffectiveTransitionTime(), baseSubscription.getStartDate().plusMonths(1));
    } else {
        assertEquals(aoPendingTranstion.getEffectiveTransitionTime(), aoSubscription.getStartDate().plusMonths(1));
    }
    // ADD TWO PHASE EVENTS (BP + AO)
    testListener.pushExpectedEvent(NextEvent.PHASE);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    // MOVE THROUGH TIME TO GO INTO EVERGREEN
    it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(33));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // CHECK EVERYTHING AGAIN
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    aoCurrentPlan = aoSubscription.getCurrentPlan();
    assertNotNull(aoCurrentPlan);
    assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct);
    assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON);
    assertEquals(aoCurrentPlan.getRecurringBillingPeriod(), aoTerm);
    aoCurrentPhase = aoSubscription.getCurrentPhase();
    assertNotNull(aoCurrentPhase);
    assertEquals(aoCurrentPhase.getPhaseType(), PhaseType.EVERGREEN);
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    aoPendingTranstion = aoSubscription.getPendingTransition();
    assertNull(aoPendingTranstion);
    assertListenerStatus();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval)

Example 69 with BillingPeriod

use of org.killbill.billing.catalog.api.BillingPeriod 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 70 with BillingPeriod

use of org.killbill.billing.catalog.api.BillingPeriod 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)

Aggregations

BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)80 Test (org.testng.annotations.Test)69 DateTime (org.joda.time.DateTime)53 LocalDate (org.joda.time.LocalDate)30 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)29 BigDecimal (java.math.BigDecimal)28 Account (org.killbill.billing.account.api.Account)27 Invoice (org.killbill.billing.invoice.api.Invoice)26 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)20 Interval (org.joda.time.Interval)18 Plan (org.killbill.billing.catalog.api.Plan)16 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)16 ArrayList (java.util.ArrayList)11 Duration (org.killbill.billing.catalog.api.Duration)9 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)9 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)9 Account (org.killbill.billing.client.model.Account)7 Subscription (org.killbill.billing.client.model.Subscription)7 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)7 UUID (java.util.UUID)6