Search in sources :

Example 1 with DefaultEntitlementSpecifier

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);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) ArrayList(java.util.ArrayList) 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) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with DefaultEntitlementSpecifier

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());
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) ArrayList(java.util.ArrayList) UUID(java.util.UUID) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 3 with DefaultEntitlementSpecifier

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();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) AccountData(org.killbill.billing.account.api.AccountData) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 4 with DefaultEntitlementSpecifier

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();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) AccountData(org.killbill.billing.account.api.AccountData) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 5 with DefaultEntitlementSpecifier

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();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) AccountData(org.killbill.billing.account.api.AccountData) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) 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