Search in sources :

Example 11 with BaseEntitlementWithAddOnsSpecifier

use of org.killbill.billing.entitlement.api.BaseEntitlementWithAddOnsSpecifier in project killbill by killbill.

the class TestMigrationSubscriptions method testMigrationWithMultipleBundlesAndDifferentDates.

@Test(groups = "slow")
public void testMigrationWithMultipleBundlesAndDifferentDates() throws Exception {
    clock.setDay(new LocalDate(2016, 1, 1));
    final AccountData accountData = getAccountData(1);
    final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
    accountChecker.checkAccount(account.getId(), accountData, callContext);
    // We set both entitlement and billing date with desired value
    final LocalDate entitlementMigrationDateBundle1 = new LocalDate(2015, 12, 20);
    final LocalDate billingMigrationDateBundle1 = new LocalDate(2016, 2, 1);
    // We set both entitlement and billing date with desired value
    final LocalDate entitlementMigrationDateBundle2 = new LocalDate(2015, 12, 20);
    final LocalDate billingMigrationDateBundle2 = new LocalDate(2016, 3, 1);
    final PlanPhaseSpecifier baseSpec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
    final PlanPhaseSpecifier addOnSpec1 = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
    final String externalKey = "baseExternalKey";
    EntitlementSpecifier baseEntitlementSpecifier = new DefaultEntitlementSpecifier(baseSpec, null);
    EntitlementSpecifier addOnEntitlementSpecifier1 = new DefaultEntitlementSpecifier(addOnSpec1, null);
    final List<EntitlementSpecifier> specifierList = new ArrayList<EntitlementSpecifier>();
    specifierList.add(baseEntitlementSpecifier);
    specifierList.add(addOnEntitlementSpecifier1);
    busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK, NextEvent.BLOCK, NextEvent.BLOCK);
    BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifierBundle1 = buildBaseEntitlementWithAddOnsSpecifier(entitlementMigrationDateBundle1, billingMigrationDateBundle1, externalKey, specifierList);
    List<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifierList = new ArrayList<BaseEntitlementWithAddOnsSpecifier>();
    BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifierBundle2 = buildBaseEntitlementWithAddOnsSpecifier(entitlementMigrationDateBundle2, billingMigrationDateBundle2, externalKey, specifierList);
    baseEntitlementWithAddOnsSpecifierList.add(baseEntitlementWithAddOnsSpecifierBundle1);
    baseEntitlementWithAddOnsSpecifierList.add(baseEntitlementWithAddOnsSpecifierBundle2);
    final List<Entitlement> baseEntitlements = entitlementApi.createBaseEntitlementsWithAddOns(account.getId(), baseEntitlementWithAddOnsSpecifierList, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    Assert.assertEquals(baseEntitlements.get(0).getState(), EntitlementState.ACTIVE);
    Assert.assertEquals(baseEntitlements.get(1).getState(), EntitlementState.ACTIVE);
    // Billing starts straight on EVERGREEN for Bundle 1 after 1 month
    clock.addMonths(1);
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.CREATE, NextEvent.INVOICE, NextEvent.NULL_INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    assertListenerStatus();
    // Billing starts straight on EVERGREEN for Bundle 2 after 2 months
    clock.addMonths(1);
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.CREATE, NextEvent.INVOICE, NextEvent.NULL_INVOICE, NextEvent.NULL_INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    assertListenerStatus();
    // Next month we should still get one single invoice and payment / invoice payment
    clock.addMonths(1);
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) EntitlementSpecifier(org.killbill.billing.entitlement.api.EntitlementSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) AccountData(org.killbill.billing.account.api.AccountData) BaseEntitlementWithAddOnsSpecifier(org.killbill.billing.entitlement.api.BaseEntitlementWithAddOnsSpecifier) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Test(org.testng.annotations.Test)

Example 12 with BaseEntitlementWithAddOnsSpecifier

use of org.killbill.billing.entitlement.api.BaseEntitlementWithAddOnsSpecifier in project killbill by killbill.

the class TestMigrationSubscriptions method testSimpleMigrationBundle.

//
// Scenario: On 2016-1-1, we decide to migrate a bundle (one BP and one AO). We migrate straight to EVERGREEN phase. The scenario is very similar to previous one
//           but with an additional AO (by using the createBaseEntitlementWithAddOns api).
//
//  Note that while convenient to migrate a bundle at once (BP + AOS), one could do several calls for each subscription. The advantage of the later approach is that
//  the granularity in terms of alignments for when things start and which phase are skipped can be better controlled.
//
@Test(groups = "slow")
public void testSimpleMigrationBundle() throws Exception {
    clock.setDay(new LocalDate(2016, 1, 1));
    final AccountData accountData = getAccountData(1);
    final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
    accountChecker.checkAccount(account.getId(), accountData, callContext);
    // We set both entitlement and billing date with desired value
    final LocalDate entitlementMigrationDate = new LocalDate(2015, 12, 20);
    final LocalDate billingMigrationDate = new LocalDate(2016, 2, 1);
    final PlanPhaseSpecifier baseSpec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
    final PlanPhaseSpecifier addOnSpec1 = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
    final String externalKey = "baseExternalKey";
    EntitlementSpecifier baseEntitlementSpecifier = new DefaultEntitlementSpecifier(baseSpec, null);
    EntitlementSpecifier addOnEntitlementSpecifier1 = new DefaultEntitlementSpecifier(addOnSpec1, null);
    final List<EntitlementSpecifier> specifierList = new ArrayList<EntitlementSpecifier>();
    specifierList.add(baseEntitlementSpecifier);
    specifierList.add(addOnEntitlementSpecifier1);
    busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
    BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier = buildBaseEntitlementWithAddOnsSpecifier(entitlementMigrationDate, billingMigrationDate, externalKey, specifierList);
    List<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifierList = new ArrayList<BaseEntitlementWithAddOnsSpecifier>();
    baseEntitlementWithAddOnsSpecifierList.add(baseEntitlementWithAddOnsSpecifier);
    final List<Entitlement> baseEntitlements = entitlementApi.createBaseEntitlementsWithAddOns(account.getId(), baseEntitlementWithAddOnsSpecifierList, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    Assert.assertEquals(baseEntitlements.get(0).getState(), EntitlementState.ACTIVE);
    // Billing starts straight on EVERGREEN
    clock.addMonths(1);
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.CREATE, NextEvent.INVOICE, NextEvent.NULL_INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) EntitlementSpecifier(org.killbill.billing.entitlement.api.EntitlementSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) AccountData(org.killbill.billing.account.api.AccountData) BaseEntitlementWithAddOnsSpecifier(org.killbill.billing.entitlement.api.BaseEntitlementWithAddOnsSpecifier) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Test(org.testng.annotations.Test)

Aggregations

BaseEntitlementWithAddOnsSpecifier (org.killbill.billing.entitlement.api.BaseEntitlementWithAddOnsSpecifier)12 ArrayList (java.util.ArrayList)11 LocalDate (org.joda.time.LocalDate)7 Account (org.killbill.billing.account.api.Account)7 EntitlementSpecifier (org.killbill.billing.entitlement.api.EntitlementSpecifier)7 DefaultBaseEntitlementWithAddOnsSpecifier (org.killbill.billing.entitlement.api.DefaultBaseEntitlementWithAddOnsSpecifier)6 Entitlement (org.killbill.billing.entitlement.api.Entitlement)6 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)5 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)5 Test (org.testng.annotations.Test)5 CallContext (org.killbill.billing.util.callcontext.CallContext)4 DefaultEntitlementContext (org.killbill.billing.entitlement.api.DefaultEntitlementContext)3 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)3 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)3 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)3 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)3 Predicate (com.google.common.base.Predicate)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 List (java.util.List)2