use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestEntitlementUtils method testCancellationIMM.
@Test(groups = "slow", description = "Verify add-ons blocking states are not impacted by IMM cancellations")
public void testCancellationIMM() throws Exception {
// Approximate check, as the blocking state check (checkBlockingStatesDAO) could be a bit off
final DateTime cancellationDateTime = clock.getUTCNow();
final LocalDate cancellationDate = clock.getUTCToday();
// Cancel the base plan
testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.BLOCK);
final DefaultEntitlement cancelledBaseEntitlement = (DefaultEntitlement) baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Refresh the add-on state
final DefaultEntitlement cancelledAddOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlement.getId(), callContext);
// Verify we compute the right blocking states for the "read" path...
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
// ...and for the "write" path (which has been exercised in the cancel call above).
checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
// Verify also the blocking states DAO doesn't add too many events (all on disk)
checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
clock.addDays(30);
// No new event
assertListenerStatus();
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestEntitlementUtils method testCancellationEOT.
@Test(groups = "slow", description = "Verify add-ons blocking states are added for EOT cancellations")
public void testCancellationEOT() throws Exception {
// Cancel the base plan
final DefaultEntitlement cancelledBaseEntitlement = (DefaultEntitlement) baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.END_OF_TERM, BillingActionPolicy.END_OF_TERM, 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(cancelledBaseEntitlement, addOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime);
// and for the "write" path (which will be exercised when the future notification kicks in).
checkActualBlockingStatesToCancel(cancelledBaseEntitlement, addOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime, false);
// Verify also the blocking states DAO adds events not on disk
checkBlockingStatesDAO(baseEntitlement, addOnEntitlement, baseEffectiveCancellationOrChangeDate, true);
// Verify the notification kicks in
testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, 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(cancelledBaseEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
// ...and for the "write" path (which has been exercised when the notification kicked in).
checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime, false);
// Verify also the blocking states API doesn't add too many events (now on disk)
checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, baseEffectiveCancellationOrChangeDate, true);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestEntitlementUtils method testChangePlanEOTWith2AddOns.
@Test(groups = "slow", description = "Verify we don't mix add-ons for EOT changes")
public void testChangePlanEOTWith2AddOns() throws Exception {
// Add a second ADD_ON (Laser-Scope is available, not included)
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final PlanPhaseSpecifier secondAddOnSpec = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
final DefaultEntitlement secondAddOnEntitlement = (DefaultEntitlement) entitlementApi.addEntitlement(baseEntitlement.getBundleId(), secondAddOnSpec, null, clock.getUTCToday(), clock.getUTCToday(), false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Change plan EOT to Assault-Rifle (Telescopic-Scope is included)
final DefaultEntitlement changedBaseEntitlement = (DefaultEntitlement) baseEntitlement.changePlanWithDate(new PlanSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, new LocalDate(2013, 10, 7), ImmutableList.<PluginProperty>of(), callContext);
// No blocking event (EOT)
assertListenerStatus();
// Verify the blocking states DAO adds events not on disk for the first add-on...
checkBlockingStatesDAO(changedBaseEntitlement, addOnEntitlement, baseEffectiveCancellationOrChangeDate, false);
// ...but not for the second one
final List<BlockingState> blockingStatesForSecondAddOn = blockingStatesForBlockedId(secondAddOnEntitlement.getId());
Assert.assertEquals(blockingStatesForSecondAddOn.size(), 1);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestEntitlementUtils method testCancellationIMMBillingEOT.
// See https://github.com/killbill/killbill/issues/121
@Test(groups = "slow", description = "Verify add-ons blocking states are not impacted by EOT billing cancellations")
public void testCancellationIMMBillingEOT() throws Exception {
// Approximate check, as the blocking state check (checkBlockingStatesDAO) could be a bit off
final DateTime cancellationDateTime = clock.getUTCNow();
final LocalDate cancellationDate = clock.getUTCToday();
// Cancel the base plan
testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
final DefaultEntitlement cancelledBaseEntitlement = (DefaultEntitlement) baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Refresh the add-on state
final DefaultEntitlement cancelledAddOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlement.getId(), callContext);
// Verify we compute the right blocking states for the "read" path...
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
// ...and for the "write" path (which has been exercised in the cancel call above).
checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
// Verify also the blocking states DAO doesn't add too many events (all on disk)
checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.CANCEL);
clock.addDays(30);
assertListenerStatus();
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestInvoicePayment method testWithFailedPaymentFixedToSuccess.
@Test(groups = "slow")
public void testWithFailedPaymentFixedToSuccess() throws Exception {
// Verify integration with Overdue in that particular test
final String configXml = "<overdueConfig>" + " <accountOverdueStates>" + " <initialReevaluationInterval>" + " <unit>DAYS</unit><number>1</number>" + " </initialReevaluationInterval>" + " <state name=\"OD1\">" + " <condition>" + " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" + " <unit>DAYS</unit><number>1</number>" + " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" + " </condition>" + " <externalMessage>Reached OD1</externalMessage>" + " <blockChanges>true</blockChanges>" + " <disableEntitlementAndChangesBlocked>false</disableEntitlementAndChangesBlocked>" + " </state>" + " </accountOverdueStates>" + "</overdueConfig>";
final InputStream is = new ByteArrayInputStream(configXml.getBytes());
final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
overdueConfigCache.loadDefaultOverdueConfig(config);
clock.setDay(new LocalDate(2012, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
checkODState(OverdueWrapper.CLEAR_STATE_NAME, account.getId());
paymentPlugin.makeNextPaymentFailWithError();
final DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
addDaysAndCheckForCompletion(30, NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR, NextEvent.INVOICE_PAYMENT_ERROR);
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 1), callContext);
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
assertEquals(invoices.size(), 2);
final Invoice invoice1 = invoices.get(0).getInvoiceItems().get(0).getInvoiceItemType() == InvoiceItemType.RECURRING ? invoices.get(0) : invoices.get(1);
assertTrue(invoice1.getBalance().compareTo(new BigDecimal("249.95")) == 0);
assertTrue(invoice1.getPaidAmount().compareTo(BigDecimal.ZERO) == 0);
assertTrue(invoice1.getChargedAmount().compareTo(new BigDecimal("249.95")) == 0);
assertEquals(invoice1.getPayments().size(), 1);
assertEquals(invoice1.getPayments().get(0).getAmount().compareTo(BigDecimal.ZERO), 0);
assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD);
assertFalse(invoice1.getPayments().get(0).isSuccess());
assertNotNull(invoice1.getPayments().get(0).getPaymentId());
final BigDecimal accountBalance1 = invoiceUserApi.getAccountBalance(account.getId(), callContext);
assertTrue(accountBalance1.compareTo(new BigDecimal("249.95")) == 0);
final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, true, ImmutableList.<PluginProperty>of(), callContext);
assertEquals(payments.size(), 1);
assertEquals(payments.get(0).getPurchasedAmount().compareTo(BigDecimal.ZERO), 0);
assertEquals(payments.get(0).getTransactions().size(), 1);
assertEquals(payments.get(0).getTransactions().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0);
assertEquals(payments.get(0).getTransactions().get(0).getCurrency(), Currency.USD);
assertEquals(payments.get(0).getTransactions().get(0).getProcessedAmount().compareTo(BigDecimal.ZERO), 0);
assertEquals(payments.get(0).getTransactions().get(0).getProcessedCurrency(), Currency.USD);
assertEquals(payments.get(0).getTransactions().get(0).getTransactionStatus(), TransactionStatus.PAYMENT_FAILURE);
assertEquals(payments.get(0).getPaymentAttempts().size(), 2);
assertEquals(payments.get(0).getPaymentAttempts().get(0).getPluginName(), InvoicePaymentControlPluginApi.PLUGIN_NAME);
assertEquals(payments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
assertEquals(payments.get(0).getPaymentAttempts().get(1).getPluginName(), InvoicePaymentControlPluginApi.PLUGIN_NAME);
assertEquals(payments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
// Verify account transitions to OD1
addDaysAndCheckForCompletion(2, NextEvent.BLOCK);
checkODState("OD1", account.getId());
// Transition the payment to success
final PaymentTransaction existingPaymentTransaction = payments.get(0).getTransactions().get(0);
final PaymentTransaction updatedPaymentTransaction = Mockito.mock(PaymentTransaction.class);
Mockito.when(updatedPaymentTransaction.getId()).thenReturn(existingPaymentTransaction.getId());
Mockito.when(updatedPaymentTransaction.getExternalKey()).thenReturn(existingPaymentTransaction.getExternalKey());
Mockito.when(updatedPaymentTransaction.getTransactionType()).thenReturn(existingPaymentTransaction.getTransactionType());
Mockito.when(updatedPaymentTransaction.getProcessedAmount()).thenReturn(new BigDecimal("249.95"));
Mockito.when(updatedPaymentTransaction.getProcessedCurrency()).thenReturn(existingPaymentTransaction.getCurrency());
busHandler.pushExpectedEvents(NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT, NextEvent.BLOCK);
adminPaymentApi.fixPaymentTransactionState(payments.get(0), updatedPaymentTransaction, TransactionStatus.SUCCESS, null, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
checkODState(OverdueWrapper.CLEAR_STATE_NAME, account.getId());
final Invoice invoice2 = invoiceUserApi.getInvoice(invoice1.getId(), callContext);
assertTrue(invoice2.getBalance().compareTo(BigDecimal.ZERO) == 0);
assertTrue(invoice2.getPaidAmount().compareTo(new BigDecimal("249.95")) == 0);
assertTrue(invoice2.getChargedAmount().compareTo(new BigDecimal("249.95")) == 0);
assertEquals(invoice2.getPayments().size(), 1);
assertEquals(invoice2.getPayments().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0);
assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD);
assertTrue(invoice2.getPayments().get(0).isSuccess());
assertNotNull(invoice2.getPayments().get(0).getPaymentId());
final BigDecimal accountBalance2 = invoiceUserApi.getAccountBalance(account.getId(), callContext);
assertTrue(accountBalance2.compareTo(BigDecimal.ZERO) == 0);
final List<Payment> payments2 = paymentApi.getAccountPayments(account.getId(), false, true, ImmutableList.<PluginProperty>of(), callContext);
assertEquals(payments2.size(), 1);
assertEquals(payments2.get(0).getPurchasedAmount().compareTo(new BigDecimal("249.95")), 0);
assertEquals(payments2.get(0).getTransactions().size(), 1);
assertEquals(payments2.get(0).getTransactions().get(0).getAmount().compareTo(new BigDecimal("249.95")), 0);
assertEquals(payments2.get(0).getTransactions().get(0).getCurrency(), Currency.USD);
assertEquals(payments2.get(0).getTransactions().get(0).getProcessedAmount().compareTo(new BigDecimal("249.95")), 0);
assertEquals(payments2.get(0).getTransactions().get(0).getProcessedCurrency(), Currency.USD);
assertEquals(payments2.get(0).getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS);
assertEquals(payments2.get(0).getPaymentAttempts().size(), 1);
assertEquals(payments2.get(0).getPaymentAttempts().get(0).getPluginName(), InvoicePaymentControlPluginApi.PLUGIN_NAME);
assertEquals(payments2.get(0).getPaymentAttempts().get(0).getStateName(), "SUCCESS");
}
Aggregations