Search in sources :

Example 36 with BillingPeriod

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

the class TestUserApiCancel method testUncancel.

// Similar test to testCancelSubscriptionEOTWithChargeThroughDate except we uncancel and check things
// are as they used to be and we can move forward without hitting cancellation
@Test(groups = "slow")
public void testUncancel() throws 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);
    final 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);
    clock.addMonths(1);
    assertListenerStatus();
    PlanPhase currentPhase = subscription.getCurrentPhase();
    assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
    // SET CTD + RE READ SUBSCRIPTION + CHANGE PLAN
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(expectedPhaseTrialChange, ctd);
    setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
    subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    // CANCEL EOT
    subscription.cancel(callContext);
    assertListenerStatus();
    // UNCANCEL
    testListener.pushExpectedEvent(NextEvent.UNCANCEL);
    subscription.uncancel(callContext);
    assertListenerStatus();
    // MOVE TO EOT + RECHECK
    clock.addMonths(1);
    assertListenerStatus();
    final Plan currentPlan = subscription.getCurrentPlan();
    assertEquals(currentPlan.getProduct().getName(), prod);
    currentPhase = subscription.getCurrentPhase();
    assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) 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) Test(org.testng.annotations.Test)

Example 37 with BillingPeriod

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

the class TestUserApiCancel method testCancelUncancelFutureSubscription.

@Test(groups = "slow")
public void testCancelUncancelFutureSubscription() throws SubscriptionBaseApiException {
    final LocalDate init = clock.getUTCToday();
    final String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
    final LocalDate futureCreationDate = init.plusDays(10);
    DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, futureCreationDate);
    assertListenerStatus();
    assertNotNull(subscription);
    assertEquals(subscription.getState(), EntitlementState.PENDING);
    // Cancel / Uncancel a few times to make sure this works and we end up on a stable state
    for (int i = 0; i < 3; i++) {
        subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext);
        subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
        assertEquals(subscription.getState(), EntitlementState.PENDING);
        testListener.pushExpectedEvents(NextEvent.UNCANCEL);
        subscription.uncancel(callContext);
        assertListenerStatus();
    }
    // Now check we are on the right state (as if nothing had happened)
    testListener.pushExpectedEvents(NextEvent.CREATE);
    clock.addDays(10);
    assertListenerStatus();
    subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    assertEquals(subscription.getState(), EntitlementState.ACTIVE);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    clock.addMonths(1);
    assertListenerStatus();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 38 with BillingPeriod

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

the class TestUserApiAddOn method testCancelUncancelBPWithAddon.

@Test(groups = "slow")
public void testCancelUncancelBPWithAddon() 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
    Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(2));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD TO CANCEL IN FUTURE
    final DateTime now = clock.getUTCNow();
    final Duration ctd = testUtil.getDurationMonth(1);
    // Why not just use clock.getUTCNow().plusMonths(1) ?
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(now, ctd);
    setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate, internalCallContext);
    baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    // FUTURE CANCELLATION
    baseSubscription.cancel(callContext);
    // REFETCH AO SUBSCRIPTION AND CHECK THIS IS ACTIVE
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE);
    assertTrue(aoSubscription.isFutureCancelled());
    testListener.pushExpectedEvent(NextEvent.UNCANCEL);
    baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    baseSubscription.uncancel(callContext);
    assertListenerStatus();
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE);
    assertFalse(aoSubscription.isFutureCancelled());
    // CANCEL AGAIN
    it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(1));
    clock.addDeltaFromReality(it.toDurationMillis());
    baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    baseSubscription.cancel(callContext);
    baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE);
    assertTrue(baseSubscription.isFutureCancelled());
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE);
    assertTrue(aoSubscription.isFutureCancelled());
    assertListenerStatus();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Duration(org.killbill.billing.catalog.api.Duration) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.testng.annotations.Test)

Example 39 with BillingPeriod

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

the class TestUserApiAddOn method testAddonCreateWithSubscriptionAlign.

@Test(groups = "slow")
public void testAddonCreateWithSubscriptionAlign() throws SubscriptionBaseApiException, CatalogApiException {
    final String aoProduct = "Laser-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 DateTime utcNow = clock.getUTCNow();
    final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, utcNow, utcNow);
    assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
    testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignment);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 40 with BillingPeriod

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

the class TestUserApiAddOn method testChangeBPWithAddonNonAvailable.

@Test(groups = "slow")
public void testChangeBPWithAddonNonAvailable() 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;
    // CREATE AO
    DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    // MOVE CLOCK AFTER TRIAL + AO DISCOUNT
    Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(2));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD TO CANCEL IN FUTURE
    final DateTime now = clock.getUTCNow();
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(now, ctd);
    setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate, internalCallContext);
    baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
    // CHANGE IMMEDIATELY WITH TO BP WITH NON AVAILABLE ADDON
    final String newBaseProduct = "Pistol";
    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_NOT_AVAILABLE_IN_NEW_PLAN);
    final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(newBaseProduct, newBaseTerm, newBasePriceList);
    baseSubscription.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), callContext);
    // REFETCH AO SUBSCRIPTION AND CHECK THIS IS ACTIVE
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE);
    assertTrue(aoSubscription.isFutureCancelled());
    // MOVE AFTER CHANGE
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // REFETCH AO SUBSCRIPTION AND CHECK THIS CANCELLED
    aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
    assertEquals(aoSubscription.getState(), EntitlementState.CANCELLED);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) 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) Test(org.testng.annotations.Test)

Aggregations

BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)111 Test (org.testng.annotations.Test)91 LocalDate (org.joda.time.LocalDate)61 DateTime (org.joda.time.DateTime)59 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)45 BigDecimal (java.math.BigDecimal)44 Account (org.killbill.billing.account.api.Account)44 Invoice (org.killbill.billing.invoice.api.Invoice)40 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)31 Plan (org.killbill.billing.catalog.api.Plan)20 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)20 Interval (org.joda.time.Interval)17 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)17 UUID (java.util.UUID)15 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)15 ArrayList (java.util.ArrayList)14 Duration (org.killbill.billing.catalog.api.Duration)10 Entitlement (org.killbill.billing.entitlement.api.Entitlement)10 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)10 HashMap (java.util.HashMap)9