use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestIntegrationDryRunInvoice method testDryRunWithPendingCancelledSubscription.
@Test(groups = "slow")
public void testDryRunWithPendingCancelledSubscription() throws Exception {
final LocalDate initialDate = new LocalDate(2017, 4, 1);
clock.setDay(initialDate);
// Create account with non BCD to force junction BCD logic to activate
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(null));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null);
final LocalDate futureStartDate = new LocalDate(2017, 5, 1);
// No CREATE event as this is set in the future
final UUID createdEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), futureStartDate, futureStartDate, false, true, ImmutableList.<PluginProperty>of(), callContext);
final Entitlement createdEntitlement = entitlementApi.getEntitlementForId(createdEntitlementId, callContext);
assertEquals(createdEntitlement.getState(), Entitlement.EntitlementState.PENDING);
assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureStartDate), 0);
assertEquals(createdEntitlement.getEffectiveEndDate(), null);
assertListenerStatus();
// Generate an invoice using a future targetDate
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
final Invoice firstInvoice = invoiceUserApi.triggerInvoiceGeneration(createdEntitlement.getAccountId(), futureStartDate, callContext);
assertListenerStatus();
assertEquals(firstInvoice.getInvoiceItems().size(), 1);
assertEquals(firstInvoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(firstInvoice.getInvoiceItems().get(0).getAmount().compareTo(new BigDecimal("19.95")), 0);
assertEquals(firstInvoice.getInvoiceItems().get(0).getStartDate(), futureStartDate);
assertEquals(firstInvoice.getInvoiceItems().get(0).getPlanName(), "pistol-monthly-notrial");
// Cancel subscription on its pending startDate
createdEntitlement.cancelEntitlementWithDate(futureStartDate, true, ImmutableList.<PluginProperty>of(), callContext);
final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2017, 5, 1), new LocalDate(2017, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-19.95")));
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2017, 4, 1), new LocalDate(2017, 4, 1), InvoiceItemType.CBA_ADJ, new BigDecimal("19.95")));
final Invoice dryRunInvoice = invoiceUserApi.triggerDryRunInvoiceGeneration(account.getId(), null, DRY_RUN_UPCOMING_INVOICE_ARG, callContext);
assertEquals(dryRunInvoice.getTargetDate(), new LocalDate(2017, 5, 1));
invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, expectedInvoices);
expectedInvoices.clear();
// Move to startDate/cancel Date
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE, NextEvent.INVOICE);
clock.addMonths(1);
assertListenerStatus();
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext);
assertEquals(invoices.size(), 2);
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2017, 5, 1), new LocalDate(2017, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-19.95")));
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2017, 5, 1), new LocalDate(2017, 5, 1), InvoiceItemType.CBA_ADJ, new BigDecimal("19.95")));
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, expectedInvoices);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestIntegrationDryRunInvoice method testDryRunTargetDatesWith_AUTO_INVOICING_REUSE_DRAFT.
@Test(groups = "slow", description = "See https://github.com/killbill/killbill/issues/1313")
public void testDryRunTargetDatesWith_AUTO_INVOICING_REUSE_DRAFT() throws Exception {
final DateTime initialCreationDate = new DateTime(2020, 6, 15, 0, 0, 0, 0, testTimeZone);
clock.setTime(initialCreationDate);
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
add_AUTO_INVOICING_DRAFT_Tag(account.getId(), ObjectType.ACCOUNT);
add_AUTO_INVOICING_REUSE_DRAFT_Tag(account.getId(), ObjectType.ACCOUNT);
// Create the monthly
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, null, null), "bundleKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2020, 6, 15), new LocalDate(2020, 7, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
final Invoice draftInvoice = invoiceChecker.checkInvoice(account.getId(), 1, callContext, expectedInvoices);
assertEquals(draftInvoice.getStatus(), InvoiceStatus.DRAFT);
// The dryRun items will include the item on the existing DRAFT invoice
final List<ExpectedInvoiceItemCheck> dryRunExpectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
dryRunExpectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2020, 6, 15), new LocalDate(2020, 7, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
dryRunExpectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2020, 7, 15), new LocalDate(2020, 8, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
dryRunExpectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2020, 8, 15), new LocalDate(2020, 9, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
dryRunExpectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2020, 9, 15), new LocalDate(2020, 10, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
dryRunExpectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2020, 10, 15), new LocalDate(2020, 11, 15), InvoiceItemType.RECURRING, new BigDecimal("19.95")));
Invoice dryRunInvoice = invoiceUserApi.triggerDryRunInvoiceGeneration(account.getId(), new LocalDate(2020, 10, 15), DRY_RUN_TARGET_DATE_ARG, callContext);
assertEquals(dryRunInvoice.getInvoiceItems().size(), 5);
invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, dryRunExpectedInvoices);
assertEquals(dryRunInvoice.getId(), draftInvoice.getId());
// We verify that our original DRAFT invoice was left unchanged
final Invoice draftInvoiceAgain = invoiceChecker.checkInvoice(account.getId(), 1, callContext, expectedInvoices);
assertEquals(dryRunInvoice.getId(), draftInvoiceAgain.getId());
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestHardenCatalogPlugin method testCreateWithCatalogPluginRetryableException.
@Test(groups = "slow")
public void testCreateWithCatalogPluginRetryableException() throws Exception {
testCatalogPluginApi.addCatalogVersion("org/killbill/billing/catalog/WeaponsHire.xml");
// We setup the test to throw ONCE a QueueRetryException upon pulling billing events from invoice and ask for a retry 3 days later
testCatalogPluginApi.setupExceptionBehavior(NB_CATALOG_ITERATIONS_FOR_PULLING_BILLING_EVENTS, Period.days(1), true);
clock.setDay(new LocalDate(2019, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
// this plan does not have a TRIAL
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("assault-rifle-annual-rescue");
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, UUID.randomUUID().toString(), null), "something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertNotNull(entitlementId);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDays(1);
assertListenerStatus();
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestHardenCatalogPlugin method testCreateWithCatalogPluginSingleRuntimeException.
@Test(groups = "slow")
public void testCreateWithCatalogPluginSingleRuntimeException() throws Exception {
testCatalogPluginApi.addCatalogVersion("org/killbill/billing/catalog/WeaponsHire.xml");
// We set the test to throw ONCE a RuntimeException upon pulling billing events from invoice
testCatalogPluginApi.setupExceptionBehavior(NB_CATALOG_ITERATIONS_FOR_PULLING_BILLING_EVENTS, null, true);
clock.setDay(new LocalDate(2019, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
// The EffectiveSubscriptionEvent bus event (NextEvent.CREATE) will be retried right away upon RuntimeException and therefore
// we should except to receive this event twice
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
// this plan does not have a TRIAL
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("assault-rifle-annual-rescue");
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, UUID.randomUUID().toString(), null), "something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertNotNull(entitlementId);
assertListenerStatus();
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestHardenCatalogPlugin method testCreateWithCatalogPluginNonSingleRuntimeException.
@Test(groups = "slow")
public void testCreateWithCatalogPluginNonSingleRuntimeException() throws Exception {
testCatalogPluginApi.addCatalogVersion("org/killbill/billing/catalog/WeaponsHire.xml");
// We set the test to keep throwing RuntimeException upon pulling billing events from invoice
testCatalogPluginApi.setupExceptionBehavior(NB_CATALOG_ITERATIONS_FOR_PULLING_BILLING_EVENTS, null, false);
clock.setDay(new LocalDate(2019, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
// We see 4 times the EffectiveSubscriptionEvent (3 retries) along with the BlockingTransitionInternalEvent and nothing else
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.CREATE, NextEvent.CREATE, NextEvent.CREATE, NextEvent.BLOCK);
// this plan does not have a TRIAL
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("assault-rifle-annual-rescue");
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, UUID.randomUUID().toString(), null), "something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertNotNull(entitlementId);
assertListenerStatus();
}
Aggregations