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();
}
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();
}
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);
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestUserApiCancel method testCancelSubscription_START_OF_TERM.
@Test(groups = "slow")
public void testCancelSubscription_START_OF_TERM() throws SubscriptionBaseApiException {
// Set date in such a way that Phase align with the first of the month (and so matches our hardcoded accountData account BCD)
final DateTime testStartDate = new DateTime(2016, 11, 1, 0, 3, 42, 0);
clock.setDeltaFromReality(testStartDate.getMillis() - clock.getUTCNow().getMillis());
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet);
PlanPhase currentPhase = subscription.getCurrentPhase();
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL);
// Move out of TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
clock.addDays(30);
assertListenerStatus();
// Artificially set the CTD
final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(clock.getUTCNow(), ctd);
subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
// Move ahead a bit abd cancel START_OF_TERM
clock.addDays(5);
testListener.pushExpectedEvent(NextEvent.CANCEL);
subscription.cancelWithPolicy(BillingActionPolicy.START_OF_TERM, accountData.getTimeZone(), accountData.getBillCycleDayLocal(), callContext);
assertListenerStatus();
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
Assert.assertEquals(subscription.getAllTransitions().get(subscription.getAllTransitions().size() - 1).getTransitionType(), SubscriptionBaseTransitionType.CANCEL);
Assert.assertEquals(new LocalDate(subscription.getAllTransitions().get(subscription.getAllTransitions().size() - 1).getEffectiveTransitionTime(), accountData.getTimeZone()), new LocalDate(2016, 12, 1));
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestUserApiCancel method testCancelSubscriptionEOTWithChargeThroughDate.
@Test(groups = "slow")
public void testCancelSubscriptionEOTWithChargeThroughDate() throws SubscriptionBillingApiException, SubscriptionBaseApiException {
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet);
PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
// NEXT PHASE
final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration());
testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
clock.addDeltaFromReality(it.toDurationMillis());
assertListenerStatus();
trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.EVERGREEN);
// SET CTD + RE READ SUBSCRIPTION + CHANGE PLAN
final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(expectedPhaseTrialChange, ctd);
subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
assertEquals(subscription.getLastActiveBillingPeriod(), term);
assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
// CANCEL
subscription.cancel(callContext);
assertListenerStatus();
// CANCEL a second time (first pending CANCEL should be made inactive)
subscription.cancel(callContext);
assertListenerStatus();
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
assertEquals(subscription.getLastActiveBillingPeriod(), term);
assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
final DateTime futureEndDate = subscription.getFutureEndDate();
Assert.assertNotNull(futureEndDate);
// MOVE TO EOT + RECHECK
testListener.pushExpectedEvents(NextEvent.CANCEL);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
clock.addDeltaFromReality(it.toDurationMillis());
assertListenerStatus();
assertTrue(futureEndDate.compareTo(subscription.getEndDate()) == 0);
final PlanPhase currentPhase = subscription.getCurrentPhase();
assertNull(currentPhase);
testUtil.checkNextPhaseChange(subscription, 0, null);
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
assertEquals(subscription.getLastActiveBillingPeriod(), term);
assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
assertListenerStatus();
}
Aggregations