Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new policy to define how to compute usage price for consumable in…
… arrear model. See #719
- Loading branch information
Showing
8 changed files
with
132 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -31,6 +31,7 @@ | ||
import org.killbill.billing.catalog.api.BillingPeriod; | import org.killbill.billing.catalog.api.BillingPeriod; | ||
import org.killbill.billing.catalog.api.CatalogApiException; | import org.killbill.billing.catalog.api.CatalogApiException; | ||
import org.killbill.billing.catalog.api.Currency; | import org.killbill.billing.catalog.api.Currency; | ||
import org.killbill.billing.catalog.api.TierBlockPolicy; | |||
import org.killbill.billing.catalog.api.Usage; | import org.killbill.billing.catalog.api.Usage; | ||
import org.killbill.billing.invoice.api.InvoiceItem; | import org.killbill.billing.invoice.api.InvoiceItem; | ||
import org.killbill.billing.invoice.model.FixedPriceInvoiceItem; | import org.killbill.billing.invoice.model.FixedPriceInvoiceItem; | ||
|
@@ -84,7 +85,7 @@ public void testComputeToBeBilledUsage() { | ||
|
|
||
final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE); | final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE); | ||
final DefaultTier tier = createDefaultTierWithBlocks(block); | final DefaultTier tier = createDefaultTierWithBlocks(block); | ||
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, tier); | final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier); | ||
|
|
||
final LocalDate targetDate = startDate.plusDays(1); | final LocalDate targetDate = startDate.plusDays(1); | ||
final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, ImmutableList.<RawUsage>of(), targetDate, false, | final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, ImmutableList.<RawUsage>of(), targetDate, false, | ||
|
@@ -116,21 +117,21 @@ public void testComputeToBeBilledUsage() { | ||
} | } | ||
|
|
||
@Test(groups = "fast") | @Test(groups = "fast") | ||
public void testComputeBilledUsage() throws CatalogApiException { | public void testComputeBilledUsageWith_ALL_TIERS() throws CatalogApiException { | ||
|
|
||
final DefaultTieredBlock block1 = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE); | final DefaultTieredBlock block1 = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE); | ||
final DefaultTier tier1 = createDefaultTierWithBlocks(block1); | final DefaultTier tier1 = createDefaultTierWithBlocks(block1); | ||
|
|
||
final DefaultTieredBlock block2 = createDefaultTieredBlock("unit", 1000, 100, BigDecimal.ONE); | final DefaultTieredBlock block2 = createDefaultTieredBlock("unit", 1000, 100, BigDecimal.ONE); | ||
final DefaultTier tier2 = createDefaultTierWithBlocks(block2); | final DefaultTier tier2 = createDefaultTierWithBlocks(block2); | ||
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, tier1, tier2); | final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier1, tier2); | ||
|
|
||
final LocalDate targetDate = new LocalDate(2014, 03, 20); | final LocalDate targetDate = new LocalDate(2014, 03, 20); | ||
|
|
||
final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, ImmutableList.<RawUsage>of(), targetDate, false, | final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, ImmutableList.<RawUsage>of(), targetDate, false, | ||
createMockBillingEvent(targetDate.toDateTimeAtStartOfDay(DateTimeZone.UTC), | createMockBillingEvent(targetDate.toDateTimeAtStartOfDay(DateTimeZone.UTC), | ||
BillingPeriod.MONTHLY, | BillingPeriod.MONTHLY, | ||
Collections.<Usage>emptyList()) | Collections.<Usage>emptyList()) | ||
); | ); | ||
|
|
||
final BigDecimal result = intervalConsumableInArrear.computeToBeBilledConsumableInArrear(new DefaultRolledUpUnit("unit", 5325L)); | final BigDecimal result = intervalConsumableInArrear.computeToBeBilledConsumableInArrear(new DefaultRolledUpUnit("unit", 5325L)); | ||
|
@@ -139,6 +140,51 @@ public void testComputeBilledUsage() throws CatalogApiException { | ||
assertEquals(result, new BigDecimal("15")); | assertEquals(result, new BigDecimal("15")); | ||
} | } | ||
|
|
||
@Test(groups = "fast") | |||
public void testComputeBilledUsageWith_TOP_TIER() throws CatalogApiException { | |||
|
|||
final DefaultTieredBlock block1 = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE); | |||
final DefaultTier tier1 = createDefaultTierWithBlocks(block1); | |||
|
|||
final DefaultTieredBlock block2 = createDefaultTieredBlock("unit", 1000, 100, BigDecimal.ONE); | |||
final DefaultTier tier2 = createDefaultTierWithBlocks(block2); | |||
|
|||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sbrossie
Author
Member
|
|||
final DefaultTieredBlock block3 = createDefaultTieredBlock("unit", 1000, 100, new BigDecimal("0.5")); | |||
final DefaultTier tier3 = createDefaultTierWithBlocks(block3); | |||
|
|||
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.TOP_TIER, tier1, tier2, tier3); | |||
|
|||
final LocalDate targetDate = new LocalDate(2014, 03, 20); | |||
|
|||
final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, ImmutableList.<RawUsage>of(), targetDate, false, | |||
createMockBillingEvent(targetDate.toDateTimeAtStartOfDay(DateTimeZone.UTC), | |||
BillingPeriod.MONTHLY, | |||
Collections.<Usage>emptyList()) | |||
); | |||
// | |||
// In this model unit amount is first used to figure out which tier we are in, and then we price all unit at that 'target' tier | |||
// | |||
final BigDecimal inputTier1 = intervalConsumableInArrear.computeToBeBilledConsumableInArrear(new DefaultRolledUpUnit("unit", 1000L)); | |||
// 1000 units => (tier1) : 1000 / 100 + 1000 % 100 = 10 | |||
assertEquals(inputTier1, new BigDecimal("10")); | |||
|
|||
final BigDecimal inputTier2 = intervalConsumableInArrear.computeToBeBilledConsumableInArrear(new DefaultRolledUpUnit("unit", 101000L)); | |||
// 101000 units => (tier2) : 101000 / 1000 + 101000 % 1000 = 101 + 0 = 101 | |||
assertEquals(inputTier2, new BigDecimal("101")); | |||
|
|||
final BigDecimal inputTier3 = intervalConsumableInArrear.computeToBeBilledConsumableInArrear(new DefaultRolledUpUnit("unit", 101001L)); | |||
// 101001 units => (tier3) : 101001 / 1000 + 101001 % 1000 = 101 + 1 = 102 units => $51 | |||
assertEquals(inputTier3, new BigDecimal("51.0")); | |||
|
|||
// If we pass the maximum of the last tier, we price all units at the last tier | |||
final BigDecimal inputLastTier = intervalConsumableInArrear.computeToBeBilledConsumableInArrear(new DefaultRolledUpUnit("unit", 300000L)); | |||
// 300000 units => (tier3) : 300000 / 1000 + 300000 % 1000 = 300 units => $150 | |||
assertEquals(inputLastTier, new BigDecimal("150.0")); | |||
|
|||
} | |||
|
|||
|
|||
|
|||
@Test(groups = "fast") | @Test(groups = "fast") | ||
public void testComputeMissingItems() throws CatalogApiException { | public void testComputeMissingItems() throws CatalogApiException { | ||
|
|
||
|
@@ -155,7 +201,7 @@ public void testComputeMissingItems() throws CatalogApiException { | ||
|
|
||
final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE); | final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE); | ||
final DefaultTier tier = createDefaultTierWithBlocks(block); | final DefaultTier tier = createDefaultTierWithBlocks(block); | ||
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, tier); | final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier); | ||
|
|
||
final LocalDate targetDate = endDate; | final LocalDate targetDate = endDate; | ||
|
|
||
|
@@ -216,7 +262,7 @@ public void testGetRolledUpUsage() { | ||
final DefaultTier tier = createDefaultTierWithBlocks(tieredBlock1, tieredBlock2); | final DefaultTier tier = createDefaultTierWithBlocks(tieredBlock1, tieredBlock2); | ||
|
|
||
|
|
||
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, tier); | final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier); | ||
|
|
||
|
|
||
final LocalDate t0 = new LocalDate(2015, 03, BCD); | final LocalDate t0 = new LocalDate(2015, 03, BCD); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Nit: typo (
Unknwon
).