use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestWithBCDUpdate method testBCDUpgradeMigrationPath_0_20_to_0_22.
@Test(groups = "slow")
public void testBCDUpgradeMigrationPath_0_20_to_0_22() throws Exception {
// Change to false to verify new behavior
final boolean checkMigrationFrom_0_20_to_0_22 = true;
final DateTime initialDate = new DateTime(2018, 6, 21, 0, 13, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(21));
assertNotNull(account);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial");
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
// We will realign the BCD on the 15 as we create the subscription - ignoring the account setting on 21.
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, null, null), null, null, null, false, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Invoice firstInvoice = invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2018, 6, 21), new LocalDate(2018, 7, 21), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
// Set BCD to be the 1
subscriptionBaseInternalApi.updateBCD(entitlementId, 1, new LocalDate(2018, 7, 1), internalCallContext);
if (checkMigrationFrom_0_20_to_0_22) {
final InvoiceModelDao invoiceForRepair_0_20 = new InvoiceModelDao(UUID.randomUUID(), clock.getUTCNow(), account.getId(), null, clock.getUTCToday(), clock.getUTCToday(), Currency.USD, false, InvoiceStatus.COMMITTED, false);
final UUID originalRecuringItemId = firstInvoice.getInvoiceItems().get(0).getId();
final InvoiceItemModelDao repair = new InvoiceItemModelDao(invoiceForRepair_0_20.getCreatedDate(), InvoiceItemType.REPAIR_ADJ, invoiceForRepair_0_20.getId(), account.getId(), UUID.randomUUID(), entitlementId, null, null, null, null, null, null, new LocalDate(2018, 7, 1), new LocalDate(2018, 7, 21), new BigDecimal("-13.30"), new BigDecimal("-13.30"), account.getCurrency(), originalRecuringItemId);
final InvoiceItemModelDao recurring = new InvoiceItemModelDao(invoiceForRepair_0_20.getCreatedDate(), InvoiceItemType.RECURRING, invoiceForRepair_0_20.getId(), account.getId(), UUID.randomUUID(), entitlementId, "", "Pistol", "pistol-monthly-notrial", "pistol-monthly-notrial-evergreen", null, null, new LocalDate(2018, 7, 1), new LocalDate(2018, 8, 1), new BigDecimal("19.95"), new BigDecimal("19.95"), account.getCurrency(), null);
invoiceForRepair_0_20.addInvoiceItem(repair);
invoiceForRepair_0_20.addInvoiceItem(recurring);
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
insertInvoiceItems(invoiceForRepair_0_20);
assertListenerStatus();
}
// With existing 0_20 data, nothing will be re-generated -> shows new behavior is compatible with old data
if (checkMigrationFrom_0_20_to_0_22) {
busHandler.pushExpectedEvents(NextEvent.BCD_CHANGE, NextEvent.NULL_INVOICE);
} else {
busHandler.pushExpectedEvents(NextEvent.BCD_CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
}
// Verify next month
// 2018-7-1
clock.addDays(10);
assertListenerStatus();
if (!checkMigrationFrom_0_20_to_0_22) {
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2018, 7, 21), new LocalDate(2018, 8, 1), InvoiceItemType.RECURRING, new BigDecimal("7.08")));
}
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestIntegrationWithAutoInvoiceDraft method testWithSubscriptionsInThePast.
@Test(groups = "slow", description = "See https://github.com/killbill/killbill/issues/1357")
public void testWithSubscriptionsInThePast() throws Exception {
final DateTime initialDate = new DateTime(2020, 9, 16, 0, 0, 0, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(21));
assertNotNull(account);
add_AUTO_INVOICING_DRAFT_Tag(account.getId(), ObjectType.ACCOUNT);
add_AUTO_INVOICING_REUSE_DRAFT_Tag(account.getId(), ObjectType.ACCOUNT);
// Subscriptions start date (in the past)
final LocalDate startDate = new LocalDate(2020, 8, 7);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial");
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.BCD_CHANGE);
entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, 1, null, null), null, startDate, startDate, false, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
checkAllNotificationProcessed(internalCallContext.getTenantRecordId());
List<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext);
assertEquals(invoices.size(), 1);
Invoice firstInvoice = invoices.get(0);
assertEquals(firstInvoice.getStatus(), InvoiceStatus.DRAFT);
ImmutableList<ExpectedInvoiceItemCheck> toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2020, 8, 7), new LocalDate(2020, 9, 1), InvoiceItemType.RECURRING, new BigDecimal("16.09")), new ExpectedInvoiceItemCheck(new LocalDate(2020, 9, 1), new LocalDate(2020, 10, 1), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
invoiceChecker.checkInvoice(invoices.get(0).getId(), callContext, toBeChecked);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.BCD_CHANGE);
entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, 1, null, null), null, startDate, startDate, false, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
checkAllNotificationProcessed(internalCallContext.getTenantRecordId());
invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext);
assertEquals(invoices.size(), 1);
firstInvoice = invoices.get(0);
assertEquals(firstInvoice.getStatus(), InvoiceStatus.DRAFT);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2020, 8, 7), new LocalDate(2020, 9, 1), InvoiceItemType.RECURRING, new BigDecimal("16.09")), new ExpectedInvoiceItemCheck(new LocalDate(2020, 9, 1), new LocalDate(2020, 10, 1), InvoiceItemType.RECURRING, new BigDecimal("19.95")), new ExpectedInvoiceItemCheck(new LocalDate(2020, 8, 7), new LocalDate(2020, 9, 1), InvoiceItemType.RECURRING, new BigDecimal("16.09")), new ExpectedInvoiceItemCheck(new LocalDate(2020, 9, 1), new LocalDate(2020, 10, 1), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
invoiceChecker.checkInvoice(invoices.get(0).getId(), callContext, toBeChecked);
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
invoiceApi.commitInvoice(firstInvoice.getId(), callContext);
assertListenerStatus();
try {
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE);
invoiceUserApi.triggerInvoiceGeneration(account.getId(), startDate, callContext);
Assert.fail();
} catch (final InvoiceApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.INVOICE_NOTHING_TO_DO.getCode());
assertListenerStatus();
}
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestIntegrationVoidInvoice method testVoidRepairedInvoice.
@Test(groups = "slow")
public void testVoidRepairedInvoice() throws Exception {
final DateTime initialDate = new DateTime(2013, 6, 15, 0, 0, 0, 0, testTimeZone);
final LocalDate startDate = initialDate.toLocalDate();
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(15));
assertNotNull(account);
add_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial");
busHandler.pushExpectedEvents(NextEvent.INVOICE);
final InvoiceItem inputCredit = new CreditAdjInvoiceItem(null, account.getId(), startDate, "credit invoice", new BigDecimal("20.00"), account.getCurrency(), null);
invoiceUserApi.insertCredits(account.getId(), startDate, ImmutableList.of(inputCredit), true, null, callContext);
assertListenerStatus();
final BigDecimal accountBalance1 = invoiceUserApi.getAccountBalance(account.getId(), callContext);
final BigDecimal accountCBA1 = invoiceUserApi.getAccountCBA(account.getId(), callContext);
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE, NextEvent.INVOICE);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, null, null), null, startDate, startDate, false, false, ImmutableList.<PluginProperty>of(), callContext);
final Entitlement bpEntitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
assertListenerStatus();
final Invoice invoice2 = invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2013, 6, 15), new LocalDate(2013, 7, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")), new ExpectedInvoiceItemCheck(new LocalDate(2013, 6, 15), new LocalDate(2013, 6, 15), InvoiceItemType.CBA_ADJ, new BigDecimal("-19.95")));
// 2013-07-01
clock.addDays(16);
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.INVOICE);
bpEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Invoice invoice3 = invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2013, 7, 1), new LocalDate(2013, 7, 15), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-9.31")), new ExpectedInvoiceItemCheck(new LocalDate(2013, 7, 1), new LocalDate(2013, 7, 1), InvoiceItemType.CBA_ADJ, new BigDecimal("9.31")));
// We disallow to void the invoice as it was repaired
try {
invoiceUserApi.voidInvoice(invoice2.getId(), callContext);
Assert.fail("Should fail to void a repaired invoice");
} catch (final RuntimeException e) {
assertTrue(e.getMessage().contains("because it contains items being repaired"));
}
// Void the invoice where the REPAIR_ADJ occurred first
busHandler.pushExpectedEvents(NextEvent.INVOICE_ADJUSTMENT);
invoiceUserApi.voidInvoice(invoice3.getId(), callContext);
assertListenerStatus();
// NOW check we allow voiding the invoice2
busHandler.pushExpectedEvents(NextEvent.INVOICE_ADJUSTMENT);
invoiceUserApi.voidInvoice(invoice2.getId(), callContext);
assertListenerStatus();
// We were left with an unstable state by VOIDing the previous periods....
busHandler.pushExpectedEvents(NextEvent.INVOICE);
invoiceUserApi.triggerInvoiceGeneration(account.getId(), clock.getUTCToday(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2013, 6, 15), new LocalDate(2013, 7, 1), InvoiceItemType.RECURRING, new BigDecimal("10.64")), new ExpectedInvoiceItemCheck(new LocalDate(2013, 7, 1), new LocalDate(2013, 7, 1), InvoiceItemType.CBA_ADJ, new BigDecimal("-10.64")));
// 20 - 10.64 = 9.36
final BigDecimal accountBalance2 = invoiceUserApi.getAccountBalance(account.getId(), callContext);
Assert.assertEquals(accountBalance2.compareTo(new BigDecimal("-9.36")), 0);
final BigDecimal accountCBA2 = invoiceUserApi.getAccountCBA(account.getId(), callContext);
Assert.assertEquals(accountCBA2.compareTo(new BigDecimal("9.36")), 0);
checkNoMoreInvoiceToGenerate(account.getId());
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method createEntitlement.
private Entitlement createEntitlement(final PlanPhaseSpecifier spec, final List<PlanPhasePriceOverride> overrides, final boolean expectPayment) throws EntitlementApiException {
if (expectPayment) {
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
} else {
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
}
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, null, overrides), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), testCallContext);
assertListenerStatus();
return entitlementApi.getEntitlementForId(entitlementId, testCallContext);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.
@Test(groups = "slow")
public void testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST() throws Exception {
// Create a per-tenant catalog with one plan
final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("zoe-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc1, init, testCallContext);
StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getPlans().size(), 1);
final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("zoe-14-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc2, init, testCallContext);
catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getPlans().size(), 2);
try {
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Zoe", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), testCallContext);
fail("Creating entitlement should fail");
} catch (final EntitlementApiException e) {
assertEquals(e.getCode(), ErrorCode.CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.getCode());
}
}
Aggregations