Search in sources :

Example 16 with DefaultEntitlementSpecifier

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

the class TestCatalogFixedTermWithVersionedCatalogs method testVersionedCatalogsEffectiveDateAfterEndOfFixedTerm.

@Test(groups = "slow")
public void testVersionedCatalogsEffectiveDateAfterEndOfFixedTerm() throws Exception {
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("plumber-insurance-monthly2", null);
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, UUID.randomUUID().toString(), null), "something", null, null, false, true, ImmutableList.<PluginProperty>of(), testCallContext);
    assertNotNull(entitlementId);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 1, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2021, 01, 01), new LocalDate(2021, 02, 01), InvoiceItemType.RECURRING, new BigDecimal("40.00")));
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    // 2021-02-01
    clock.addMonths(1);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 2, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2021, 02, 01), new LocalDate(2021, 03, 01), InvoiceItemType.RECURRING, new BigDecimal("40.00")));
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    // 2021-03-01
    clock.addMonths(1);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 3, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2021, 03, 01), new LocalDate(2021, 04, 01), InvoiceItemType.RECURRING, new BigDecimal("40.00")));
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    // 2021-04-01
    clock.addMonths(1);
    assertListenerStatus();
    // Fixed term duration of 100 days ends on 2021-04-11
    invoiceChecker.checkInvoice(account.getId(), 4, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2021, 04, 01), new LocalDate(2021, 04, 11), InvoiceItemType.RECURRING, new BigDecimal("13.33")));
    checkNoMoreInvoiceToGenerate(account.getId(), testCallContext);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) UUID(java.util.UUID) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 17 with DefaultEntitlementSpecifier

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

the class TestIntegrationInvoiceWithRepairLogic method testWithWrongInitialItem.

// This is a beatrix level test matching ur invoice TestSubscriptionItemTree#testWithWrongInitialItem
@Test(groups = "slow")
public void testWithWrongInitialItem() throws Exception {
    final DateTime initialDate = new DateTime(2016, 9, 8, 0, 0, 0, 0, testTimeZone);
    final LocalDate correctStartDate = initialDate.toLocalDate();
    final LocalDate wrongStartDate = new LocalDate(2016, 9, 9);
    final LocalDate endDate = new LocalDate(2016, 10, 8);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(8));
    assertNotNull(account);
    add_AUTO_INVOICING_OFF_Tag(account.getId(), ObjectType.ACCOUNT);
    add_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT);
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial");
    busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE);
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, null, null), null, correctStartDate, correctStartDate, false, false, ImmutableList.<PluginProperty>of(), callContext);
    final Entitlement bpEntitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    assertListenerStatus();
    final InvoiceModelDao existingBadInvoice = new InvoiceModelDao(UUID.randomUUID(), clock.getUTCNow(), account.getId(), null, correctStartDate, correctStartDate, Currency.USD, false, InvoiceStatus.COMMITTED, false);
    final InvoiceItemModelDao wrongRecurring = new InvoiceItemModelDao(initialDate, InvoiceItemType.RECURRING, existingBadInvoice.getId(), existingBadInvoice.getAccountId(), bpEntitlement.getBundleId(), entitlementId, "", "Pistol", "pistol-monthly-notrial", "pistol-monthly-notrial-evergreen", null, null, new LocalDate(2016, 9, 9), new LocalDate(2016, 10, 8), new BigDecimal("19.29"), new BigDecimal("19.95"), account.getCurrency(), null);
    existingBadInvoice.addInvoiceItem(wrongRecurring);
    insertInvoiceItems(existingBadInvoice);
    existingBadInvoice.getInvoiceItems().clear();
    final InvoiceItemModelDao adj = new InvoiceItemModelDao(clock.getUTCNow(), InvoiceItemType.ITEM_ADJ, existingBadInvoice.getId(), existingBadInvoice.getAccountId(), null, null, null, wrongRecurring.getProductName(), wrongRecurring.getPlanName(), wrongRecurring.getPhaseName(), wrongRecurring.getUsageName(), wrongRecurring.getCatalogEffectiveDate(), clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("-19.29"), null, wrongRecurring.getCurrency(), wrongRecurring.getId());
    existingBadInvoice.addInvoiceItem(adj);
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_ADJUSTMENT);
    insertInvoiceItems(existingBadInvoice);
    assertListenerStatus();
    busHandler.pushExpectedEvents(NextEvent.INVOICE);
    remove_AUTO_INVOICING_OFF_Tag(account.getId(), ObjectType.ACCOUNT);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 9, 8), new LocalDate(2016, 9, 9), InvoiceItemType.RECURRING, new BigDecimal("0.66")));
    checkNoMoreInvoiceToGenerate(account);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) InvoiceItemModelDao(org.killbill.billing.invoice.dao.InvoiceItemModelDao) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) UUID(java.util.UUID) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 18 with DefaultEntitlementSpecifier

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

the class TestEntitlementUtils method testChangePlanEOT.

@Test(groups = "slow", description = "Verify add-ons blocking states are added for EOT change plans")
public void testChangePlanEOT() throws Exception {
    // Change plan EOT to Assault-Rifle (Telescopic-Scope is included)
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultEntitlement changedBaseEntitlement = (DefaultEntitlement) baseEntitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec), new LocalDate(2013, 10, 7), ImmutableList.<PluginProperty>of(), callContext);
    // No blocking event (EOT)
    assertListenerStatus();
    // Verify we compute the right blocking states for the "read" path...
    checkFutureBlockingStatesToCancel(addOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(changedBaseEntitlement, addOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime);
    // ...and for the "write" path (which will be exercised when the future notification kicks in).
    checkActualBlockingStatesToCancel(changedBaseEntitlement, addOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime, false);
    // Verify also the blocking states DAO adds events not on disk
    checkBlockingStatesDAO(changedBaseEntitlement, addOnEntitlement, baseEffectiveCancellationOrChangeDate, false);
    // Verify the notification kicks in
    testListener.pushExpectedEvents(NextEvent.CHANGE, NextEvent.CANCEL, NextEvent.BLOCK);
    clock.addDays(30);
    assertListenerStatus();
    // Refresh the state
    final DefaultEntitlement cancelledAddOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlement.getId(), callContext);
    // Verify we compute the right blocking states for the "read" path...
    checkFutureBlockingStatesToCancel(changedBaseEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(changedBaseEntitlement, cancelledAddOnEntitlement, null);
    // ...and for the "write" path (which has been exercised when the notification kicked in).
    checkActualBlockingStatesToCancel(changedBaseEntitlement, cancelledAddOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime, false);
    // Verify also the blocking states API doesn't add too many events (now on disk)
    checkBlockingStatesDAO(changedBaseEntitlement, cancelledAddOnEntitlement, baseEffectiveCancellationOrChangeDate, false);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 19 with DefaultEntitlementSpecifier

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

the class TestBlockingApi method testCreateAOSubscriptionOnFutureBlockedChangeAcount.

@Test(groups = "slow")
public void testCreateAOSubscriptionOnFutureBlockedChangeAcount() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
    final LocalDate initialDate = new LocalDate(2017, 5, 1);
    clock.setDay(initialDate);
    final Account account = createAccount(getAccountData(1));
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("shotgun-monthly", null);
    testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE);
    final UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "xyzqe", null, initialDate.minusDays(3), false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext);
    // Create future BlockingState
    final LocalDate blockingChange = initialDate.plusDays(3);
    final BlockingState blockChangeAccount = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "State1", "Service1", true, false, false, null);
    subscriptionApi.addBlockingState(blockChangeAccount, blockingChange, ImmutableList.<PluginProperty>of(), callContext);
    // Create ADD_ON in the future as well
    try {
        final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
        testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
        entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), blockingChange, null, false, ImmutableList.<PluginProperty>of(), callContext);
        assertListenerStatus();
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode());
    }
    // Create ADD_ON now (prior future BlockingState)
    final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), null, null, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 20 with DefaultEntitlementSpecifier

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

the class TestBlockingApi method testCreateAOSubscriptionOnBlockedChangeAcount.

@Test(groups = "slow")
public void testCreateAOSubscriptionOnBlockedChangeAcount() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
    final LocalDate initialDate = new LocalDate(2017, 5, 1);
    clock.setDay(initialDate);
    final Account account = createAccount(getAccountData(1));
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("shotgun-monthly", null);
    testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE);
    final UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "xyzqe", null, initialDate.minusDays(3), false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState blockChangeAccount = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "State1", "Service1", true, false, false, clock.getUTCNow());
    subscriptionApi.addBlockingState(blockChangeAccount, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Try create subscription right now
    try {
        final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
        entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), null, null, false, ImmutableList.<PluginProperty>of(), callContext);
        fail("Should fail to create ADD_ON");
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode());
    }
    // Try create subscription in the future
    try {
        final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
        entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), null, initialDate.plusDays(2), false, ImmutableList.<PluginProperty>of(), callContext);
        fail("Should fail to create ADD_ON");
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode());
    }
    // Try create subscription in the past
    final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), initialDate.minusDays(2), null, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Aggregations

DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)141 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)140 Test (org.testng.annotations.Test)129 LocalDate (org.joda.time.LocalDate)105 Account (org.killbill.billing.account.api.Account)98 UUID (java.util.UUID)87 Entitlement (org.killbill.billing.entitlement.api.Entitlement)64 BigDecimal (java.math.BigDecimal)62 DateTime (org.joda.time.DateTime)61 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)59 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)56 Invoice (org.killbill.billing.invoice.api.Invoice)40 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)27 ArrayList (java.util.ArrayList)24 AccountData (org.killbill.billing.account.api.AccountData)23 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)20 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)14 BlockingState (org.killbill.billing.entitlement.api.BlockingState)13 Interval (org.joda.time.Interval)12 Period (org.joda.time.Period)12