use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestDefaultInternalBillingApi method testBlockingStatesWithSameEffectiveDate.
// This test was originally for https://github.com/killbill/killbill/issues/123.
// The invocationCount > 0 was to trigger an issue where events would come out-of-order randomly.
// While the bug shouldn't occur anymore, we're keeping it just in case (the test will also try to insert the events out-of-order manually).
// This test also checks we don't generate billing events for blocking durations less than a day (https://github.com/killbill/killbill/issues/267).
@Test(groups = "slow", description = "Check blocking states with same effective date are correctly handled", invocationCount = 10)
public void testBlockingStatesWithSameEffectiveDate() throws Exception {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
final SubscriptionBase subscription = subscriptionInternalApi.getSubscriptionFromId(entitlement.getId(), internalCallContext);
assertListenerStatus();
final DateTime block1Date = clock.getUTCNow();
testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
final DefaultBlockingState state1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, true, block1Date);
blockingInternalApi.setBlockingState(state1, internalCallContext);
// Same date, we'll order by record id asc
final DefaultBlockingState state2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_CLEAR, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, block1Date);
blockingInternalApi.setBlockingState(state2, internalCallContext);
assertListenerStatus();
clock.addDays(5);
final DateTime block2Date = clock.getUTCNow();
testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
final DefaultBlockingState state3 = new DefaultBlockingState(entitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, true, block2Date);
blockingInternalApi.setBlockingState(state3, internalCallContext);
// Same date, we'll order by record id asc
final DefaultBlockingState state4 = new DefaultBlockingState(entitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CLEAR, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, block2Date);
blockingInternalApi.setBlockingState(state4, internalCallContext);
assertListenerStatus();
final DateTime block3Date = block2Date.plusDays(3);
// Pass the phase
testListener.pushExpectedEvent(NextEvent.PHASE);
clock.addDays(50);
assertListenerStatus();
final DateTime block4Date = clock.getUTCNow();
final DateTime block5Date = block4Date.plusDays(3);
// Only one event on the bus (for state5)
testListener.pushExpectedEvents(NextEvent.BLOCK);
// Insert the clear state first, to make sure the order in which we insert blocking states doesn't matter
// Since we are already in an ENT_STATE_CLEAR state for service ENTITLEMENT_SERVICE_NAME, we need to use a different
// state name to simulate this behavior (otherwise, by design, this event won't be created)
final DefaultBlockingState state6 = new DefaultBlockingState(entitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CLEAR + "-something", KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, block5Date);
blockingInternalApi.setBlockingState(state6, internalCallContext);
final DefaultBlockingState state5 = new DefaultBlockingState(entitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_BLOCKED + "-something", KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, true, block4Date);
blockingInternalApi.setBlockingState(state5, internalCallContext);
assertListenerStatus();
// Now, add back blocking states at an earlier date, for a different blockable id, to make sure the effective
// date ordering is correctly respected when computing blocking durations
testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
final DefaultBlockingState state7 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_BLOCKED + "-something2", KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, true, block3Date);
blockingInternalApi.setBlockingState(state7, internalCallContext);
final DefaultBlockingState state8 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_CLEAR + "-something2", KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, block4Date);
blockingInternalApi.setBlockingState(state8, internalCallContext);
assertListenerStatus();
// Advance for state6 to be active
testListener.pushExpectedEvents(NextEvent.BLOCK);
clock.addDays(5);
assertListenerStatus();
// Expected blocking duration:
// * 2013-08-15 to 2013-10-04 [2013-08-15 to 2013-10-01 (block3Date -> block4Date) and 2013-10-01 to 2013-10-04 (block4Date -> block5Date)]
final List<BillingEvent> events = ImmutableList.<BillingEvent>copyOf(billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, null, internalCallContext));
Assert.assertEquals(events.size(), 3);
Assert.assertEquals(events.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE);
Assert.assertEquals(events.get(0).getEffectiveDate(), subscription.getStartDate());
Assert.assertEquals(events.get(1).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
Assert.assertEquals(events.get(1).getEffectiveDate().compareTo(block3Date), 0);
Assert.assertEquals(events.get(2).getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
Assert.assertEquals(events.get(2).getEffectiveDate().compareTo(block5Date), 0);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestDefaultInternalBillingApi method testUsageInArrear.
@Test(groups = "slow")
public void testUsageInArrear() throws Exception {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
// Account with no BCD
final Account account = createAccount(getAccountData(0));
Assert.assertEquals(account.getBillCycleDayLocal(), (Integer) 0);
// Create base entitlement
final String bundleKey = UUID.randomUUID().toString();
final EntitlementSpecifier entitlementSpecifierBase = new DefaultEntitlementSpecifier(new PlanPhaseSpecifier("Trebuchet", BillingPeriod.NO_BILLING_PERIOD, PriceListSet.DEFAULT_PRICELIST_NAME, null));
final BaseEntitlementWithAddOnsSpecifier specifier = new DefaultBaseEntitlementWithAddOnsSpecifier(null, bundleKey, ImmutableList.of(entitlementSpecifierBase), null, null, false);
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
entitlementApi.createBaseEntitlementsWithAddOns(account.getId(), ImmutableList.of(specifier), false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final List<Entitlement> entitlements = entitlementApi.getAllEntitlementsForAccountId(account.getId(), callContext);
Assert.assertEquals(entitlements.size(), 1);
Assert.assertEquals(entitlements.get(0).getLastActiveProduct().getName(), "Trebuchet");
Assert.assertNull(entitlements.get(0).getBillCycleDayLocal());
// Account still has no BCD
final Account accountNoBCD = accountApi.getAccountById(account.getId(), callContext);
Assert.assertEquals(accountNoBCD.getBillCycleDayLocal(), (Integer) 0);
List<BillingEvent> events = ImmutableList.<BillingEvent>copyOf(billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, null, internalCallContext));
Assert.assertEquals(events.size(), 1);
Assert.assertEquals(events.get(0).getBillCycleDayLocal(), 7);
// Verify BCD
final Account accountWithBCD = accountApi.getAccountById(account.getId(), callContext);
Assert.assertEquals(accountWithBCD.getBillCycleDayLocal(), (Integer) 7);
// Verify GET
final List<Entitlement> entitlementsUpdated = entitlementApi.getAllEntitlementsForAccountId(account.getId(), callContext);
Assert.assertEquals(entitlementsUpdated.size(), 1);
Assert.assertEquals(entitlementsUpdated.get(0).getLastActiveProduct().getName(), "Trebuchet");
Assert.assertEquals(entitlementsUpdated.get(0).getBillCycleDayLocal(), (Integer) 7);
events = ImmutableList.<BillingEvent>copyOf(billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, null, internalCallContext));
Assert.assertEquals(events.size(), 1);
Assert.assertEquals(events.get(0).getBillCycleDayLocal(), 7);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestWithInvoiceHardening method testBasicBlockUnblock.
@Test(groups = "slow")
public void testBasicBlockUnblock() throws Exception {
final DateTimeZone testTimeZone = DateTimeZone.UTC;
final DateTime initialDate = new DateTime(2019, 4, 27, 0, 13, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
assertNotNull(account);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "Something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 4, 27), new LocalDate(2019, 5, 27), InvoiceItemType.RECURRING, new BigDecimal("29.95")));
// 2019-05-03
clock.addDays(6);
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState blockingState1 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "SOMETHING_BLOCK", "company.a.b.c", true, true, true, null);
subscriptionApi.addBlockingState(blockingState1, new LocalDate(2019, 5, 3), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 03), new LocalDate(2019, 5, 27), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-23.96")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 03), new LocalDate(2019, 5, 03), InvoiceItemType.CBA_ADJ, new BigDecimal("23.96")));
final BlockingState blockingState2 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "SOMETHING_UNBLOCK", "company.a.b.c", false, false, false, null);
subscriptionApi.addBlockingState(blockingState2, new LocalDate(2019, 5, 17), ImmutableList.<PluginProperty>of(), callContext);
// 2019-05-17
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
clock.addDays(14);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 27), InvoiceItemType.RECURRING, new BigDecimal("9.98")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 17), InvoiceItemType.CBA_ADJ, new BigDecimal("-9.98")));
int remainingBlockUnblockIterations = 3;
int curInvoiceNumber = 3;
do {
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState somethingBlockAgain = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "SOMETHING_BLOCK_AGAIN", "company.a.b.c", true, true, true, null);
subscriptionApi.addBlockingState(somethingBlockAgain, new LocalDate(2019, 5, 17), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Block again on the same date
invoiceChecker.checkInvoice(account.getId(), ++curInvoiceNumber, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 27), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-9.98")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 17), InvoiceItemType.CBA_ADJ, new BigDecimal("9.98")));
verifyNoInvoiceDueOnDate(account.getId(), new LocalDate(2019, 5, 27));
verifyNoInvoiceDueOnDate(account.getId(), new LocalDate(2019, 6, 27));
// Unblock again on the same date
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState somethingUnblockAgain = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "SOMETHING_UNBLOCK_AGAIN", "company.a.b.c", false, false, false, null);
subscriptionApi.addBlockingState(somethingUnblockAgain, new LocalDate(2019, 5, 17), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), ++curInvoiceNumber, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 27), InvoiceItemType.RECURRING, new BigDecimal("9.98")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 17), InvoiceItemType.CBA_ADJ, new BigDecimal("-9.98")));
} while (remainingBlockUnblockIterations-- > 0);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestWithInvoiceHardening method testFor1205.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1205")
public void testFor1205() throws Exception {
final DateTimeZone testTimeZone = DateTimeZone.UTC;
final DateTime initialDate = new DateTime(2019, 4, 27, 0, 13, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
assertNotNull(account);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "Something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 4, 27), new LocalDate(2019, 5, 27), InvoiceItemType.RECURRING, new BigDecimal("29.95")));
// 2019-05-03
clock.addDays(6);
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState blockingState1 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "BLOCK_5_3", "SERVICE_5_3", true, true, true, null);
subscriptionApi.addBlockingState(blockingState1, new LocalDate(2019, 5, 3), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 03), new LocalDate(2019, 5, 27), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-23.96")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 03), new LocalDate(2019, 5, 03), InvoiceItemType.CBA_ADJ, new BigDecimal("23.96")));
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState blockingState2 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "BLOCK_4_27", "SERVICE_4_27", true, true, true, null);
subscriptionApi.addBlockingState(blockingState2, new LocalDate(2019, 4, 27), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 4, 27), new LocalDate(2019, 5, 03), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-5.99")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 03), new LocalDate(2019, 5, 03), InvoiceItemType.CBA_ADJ, new BigDecimal("5.99")));
busHandler.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState blockingState4 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "UNBLOCK_5_3", "SERVICE_5_3", false, false, false, null);
subscriptionApi.addBlockingState(blockingState4, new LocalDate(2019, 5, 3), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// 2019-05-17
clock.addDays(14);
busHandler.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState blockingState3 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "BLOCK_5_17", "SERVICE_5_17", true, true, true, null);
subscriptionApi.addBlockingState(blockingState3, new LocalDate(2019, 5, 17), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState blockingState5 = new DefaultBlockingState(entitlementId, BlockingStateType.SUBSCRIPTION, "UNBLOCK_4_27", "SERVICE_4_27", false, false, false, null);
subscriptionApi.addBlockingState(blockingState5, new LocalDate(2019, 4, 27), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 4, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2019, 4, 27), new LocalDate(2019, 5, 17), InvoiceItemType.RECURRING, new BigDecimal("19.97")), new ExpectedInvoiceItemCheck(new LocalDate(2019, 5, 17), new LocalDate(2019, 5, 17), InvoiceItemType.CBA_ADJ, new BigDecimal("-19.97")));
// 2019-05-27
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE);
clock.addDays(10);
assertListenerStatus();
}
use of org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier in project killbill by killbill.
the class TestUnknownUsageUnits method testWithUnknownUsage.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1275")
public void testWithUnknownUsage() throws Exception {
// We take april as it has 30 days (easier to play with BCD)
// Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
clock.setDay(new LocalDate(2012, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
// Catalog-v1.xml
final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Server", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
// Check bundle after BP got created otherwise we get an error from auditApi.
subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext);
// Record known usage for April
recordUsageData(bpSubscription.getId(), "tracking-1", "server-hourly-type-1", new LocalDate(2012, 4, 1), 99L, callContext);
recordUsageData(bpSubscription.getId(), "tracking-2", "bandwidth-type-1", new LocalDate(2012, 4, 15), 100L, callContext);
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.addDays(30);
assertListenerStatus();
Invoice curInvoice = invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), new LocalDate(2012, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), new LocalDate(2012, 5, 1), InvoiceItemType.USAGE, new BigDecimal("99")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), new LocalDate(2012, 5, 1), InvoiceItemType.USAGE, new BigDecimal("10")));
invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of("tracking-1", "tracking-2"), internalCallContext);
Assert.assertFalse(parkedAccountsManager.isParked(internalCallContext));
// Enable strict mode
invoiceConfig.setShouldParkAccountsWithUnknownUsage(true);
// Record known consumable usage but unknown capacity usage for May
recordUsageData(bpSubscription.getId(), "tracking-3", "server-hourly-type-1", new LocalDate(2012, 5, 1), 99L, callContext);
recordUsageData(bpSubscription.getId(), "tracking-4", "bandwidth-type-2", new LocalDate(2012, 5, 15), 100L, callContext);
busHandler.pushExpectedEvents(NextEvent.TAG);
clock.addMonths(1);
assertListenerStatus();
// Account is parked because of the unknown usage
Assert.assertTrue(parkedAccountsManager.isParked(internalCallContext));
// Trigger a change plan on the same plan, to force the new catalog version (Catalog-v2.xml)
busHandler.pushExpectedEvents(NextEvent.CHANGE);
bpSubscription.changePlanWithDate(new DefaultEntitlementSpecifier(new PlanPhaseSpecifier("server-monthly")), new LocalDate("2012-05-01"), null, callContext);
assertListenerStatus();
// Trigger an invoice generation
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
invoiceUserApi.triggerInvoiceGeneration(account.getId(), clock.getUTCToday(), callContext);
assertListenerStatus();
// Now unparked
Assert.assertFalse(parkedAccountsManager.isParked(internalCallContext));
curInvoice = invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.USAGE, new BigDecimal("99")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.USAGE, new BigDecimal("12")));
invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of("tracking-3", "tracking-4"), internalCallContext);
// Record known capacity usage but unknown consumable usage for June
recordUsageData(bpSubscription.getId(), "tracking-5", "server-hourly-type-2", new LocalDate(2012, 6, 1), 99L, callContext);
recordUsageData(bpSubscription.getId(), "tracking-6", "bandwidth-type-1", new LocalDate(2012, 6, 15), 100L, callContext);
busHandler.pushExpectedEvents(NextEvent.TAG);
clock.addMonths(1);
assertListenerStatus();
// Account is parked because of the unknown usage
Assert.assertTrue(parkedAccountsManager.isParked(internalCallContext));
// Trigger a change plan on the same plan, to force the new catalog version (Catalog-v3.xml)
busHandler.pushExpectedEvents(NextEvent.CHANGE);
bpSubscription.changePlanWithDate(new DefaultEntitlementSpecifier(new PlanPhaseSpecifier("server-monthly")), new LocalDate("2012-06-01"), null, callContext);
assertListenerStatus();
// Trigger an invoice generation
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
invoiceUserApi.triggerInvoiceGeneration(account.getId(), clock.getUTCToday(), callContext);
assertListenerStatus();
// Now unparked
Assert.assertFalse(parkedAccountsManager.isParked(internalCallContext));
curInvoice = invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.RECURRING, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.USAGE, new BigDecimal("198")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 1), new LocalDate(2012, 7, 1), InvoiceItemType.USAGE, new BigDecimal("10")));
invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of("tracking-5", "tracking-6"), internalCallContext);
// Disable strict mode
invoiceConfig.setShouldParkAccountsWithUnknownUsage(false);
// Record unknown usage for July
recordUsageData(bpSubscription.getId(), "tracking-7", "server-hourly-type-3", new LocalDate(2012, 4, 1), 99L, callContext);
recordUsageData(bpSubscription.getId(), "tracking-8", "bandwidth-type-3", new LocalDate(2012, 4, 15), 100L, callContext);
busHandler.pushExpectedEvents(NextEvent.INVOICE);
clock.addMonths(1);
assertListenerStatus();
curInvoice = invoiceChecker.checkInvoice(account.getId(), 4, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 1), new LocalDate(2012, 8, 1), InvoiceItemType.RECURRING, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 1), new LocalDate(2012, 8, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 1), new LocalDate(2012, 8, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 1), new LocalDate(2012, 8, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 1), new LocalDate(2012, 8, 1), InvoiceItemType.USAGE, new BigDecimal("0")));
invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of(), internalCallContext);
Assert.assertFalse(parkedAccountsManager.isParked(internalCallContext));
// Re-enable strict mode
invoiceConfig.setShouldParkAccountsWithUnknownUsage(true);
// Trigger a change plan on the same plan, to force the new catalog version (Catalog-v4.xml)
busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.NULL_INVOICE);
bpSubscription.changePlanWithDate(new DefaultEntitlementSpecifier(new PlanPhaseSpecifier("server-monthly")), new LocalDate("2012-08-01"), null, callContext);
assertListenerStatus();
// Record unknown usage for August (the unit has been retired)
recordUsageData(bpSubscription.getId(), "tracking-9", "server-hourly-type-1", new LocalDate(2012, 8, 1), 99L, callContext);
busHandler.pushExpectedEvents(NextEvent.TAG);
clock.addMonths(1);
assertListenerStatus();
// Account is parked because of the unknown usage
Assert.assertTrue(parkedAccountsManager.isParked(internalCallContext));
// Record retroactively additional known usage for August
recordUsageData(bpSubscription.getId(), "tracking-10", "server-hourly-type-2", new LocalDate(2012, 8, 1), 99L, callContext);
recordUsageData(bpSubscription.getId(), "tracking-11", "bandwidth-type-2", new LocalDate(2012, 8, 15), 100L, callContext);
busHandler.pushExpectedEvents(NextEvent.BLOCK);
entitlementApi.pause(bpSubscription.getBundleId(), new LocalDate(2012, 8, 1), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.BLOCK);
entitlementApi.resume(bpSubscription.getBundleId(), new LocalDate(2012, 8, 2), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Disable strict mode
invoiceConfig.setShouldParkAccountsWithUnknownUsage(false);
// Trigger an invoice generation
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
invoiceUserApi.triggerInvoiceGeneration(account.getId(), clock.getUTCToday(), callContext);
assertListenerStatus();
Assert.assertFalse(parkedAccountsManager.isParked(internalCallContext));
curInvoice = invoiceChecker.checkInvoice(account.getId(), 5, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 8, 2), new LocalDate(2012, 9, 1), InvoiceItemType.RECURRING, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 8, 2), new LocalDate(2012, 9, 1), InvoiceItemType.USAGE, new BigDecimal("12")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 8, 2), new LocalDate(2012, 9, 1), InvoiceItemType.USAGE, new BigDecimal("0")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 8, 2), new LocalDate(2012, 9, 1), InvoiceItemType.USAGE, new BigDecimal("0")));
invoiceChecker.checkTrackingIds(curInvoice, ImmutableSet.of("tracking-11"), internalCallContext);
}
Aggregations