Skip to content

Commit

Permalink
beatrix: Add usage test scenario. See 9554a07
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrossie committed Jun 20, 2018
1 parent 021f31d commit 1da32f1
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
Expand Up @@ -46,7 +46,7 @@ protected KillbillConfigSource getConfigSource() {
}

@Test(groups = "slow")
public void testWithNoUsageInPeriodAndOldUsage() throws Exception {
public void testWithChangeAcrossCatalogs() throws Exception {
// 30 days month
clock.setDay(new LocalDate(2016, 4, 1));

Expand Down Expand Up @@ -99,6 +99,62 @@ public void testWithNoUsageInPeriodAndOldUsage() throws Exception {
}


@Test(groups = "slow")
public void testWithChangeWithinCatalog() throws Exception {
// 30 days month
clock.setDay(new LocalDate(2016, 4, 1));

final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);

final PlanPhaseSpecifier spec1 = new PlanPhaseSpecifier("electricity-monthly");
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec1), null, null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();

recordUsageData(entitlementId, "kilowatt-hour", new LocalDate(2016, 4, 1), 143L, callContext);
recordUsageData(entitlementId, "kilowatt-hour", new LocalDate(2016, 4, 18), 57L, callContext);

busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addMonths(1);
assertListenerStatus();

invoiceChecker.checkInvoice(account.getId(), 1, callContext,
new ExpectedInvoiceItemCheck(new LocalDate(2016, 4, 1), new LocalDate(2016, 5, 1), InvoiceItemType.USAGE, new BigDecimal("300.00")));

recordUsageData(entitlementId, "kilowatt-hour", new LocalDate(2016, 5, 2), 100L, callContext); // -> Uses v1 : $150

This comment has been minimized.

Copy link
@pierre

pierre Jun 20, 2018

Member

I suppose that if at this point we send future usage data points for 2016-05-10, the special plan would be used when generating the invoice?


final Entitlement bp = entitlementApi.getEntitlementForId(entitlementId, callContext);

final PlanPhaseSpecifier spec2 = new PlanPhaseSpecifier("electricity-monthly-special");

bp.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), new LocalDate("2016-05-09"), null, callContext);
assertListenerStatus();

busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDays(8);
assertListenerStatus();

invoiceChecker.checkInvoice(account.getId(), 2, callContext,
new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 1), new LocalDate(2016, 5, 9), InvoiceItemType.USAGE, new BigDecimal("150.00")));


recordUsageData(entitlementId, "kilowatt-hour", new LocalDate(2016, 5, 10), 100L, callContext); // -> Uses special plan : $100


busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDays(23);
assertListenerStatus();

invoiceChecker.checkInvoice(account.getId(), 3, callContext,
new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 9), new LocalDate(2016, 6, 1), InvoiceItemType.USAGE, new BigDecimal("100.00")));

}




// We are not using catalog versions in this test but testing the overridden value of 'readMaxRawUsagePreviousPeriod = 0'
@Test(groups = "slow")
public void testWithRemovedData() throws Exception {
Expand Down
Expand Up @@ -98,12 +98,49 @@
</finalPhase>
</plan>

<plan name="electricity-monthly-special">
<product>Electricity</product>
<finalPhase type="EVERGREEN">
<duration>
<unit>UNLIMITED</unit>
</duration>
<usages>
<usage name="electricity-monthly-special-uusage" billingMode="IN_ARREAR" usageType="CONSUMABLE" tierBlockPolicy="ALL_TIERS">
<billingPeriod>MONTHLY</billingPeriod>
<tiers>
<tier>
<blocks>
<tieredBlock>
<unit>kilowatt-hour</unit>
<size>1</size>
<prices>
<price>
<currency>USD</currency>
<value>1.00</value>
</price>
</prices>
<max>1000</max>
</tieredBlock>
</blocks>
</tier>
</tiers>
</usage>
</usages>
</finalPhase>
</plan>

</plans>
<priceLists>
<defaultPriceList name="DEFAULT">
<plans>
<plan>electricity-monthly</plan>
</plans>
</defaultPriceList>
<childPriceList name="Special">
<plans>
<plan>electricity-monthly-special</plan>
</plans>
</childPriceList>

</priceLists>
</catalog>

1 comment on commit 1da32f1

@pierre
Copy link
Member

@pierre pierre commented on 1da32f1 Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.