use of org.killbill.billing.catalog.DefaultUsage in project killbill by killbill.
the class TestRawUsageOptimizer method testWithOneMonthlyAndOneNonActiveAnnualUsageSectionAndEnoughUsageItems.
@Test(groups = "fast")
public void testWithOneMonthlyAndOneNonActiveAnnualUsageSectionAndEnoughUsageItems() {
final LocalDate firstEventStartDate = new LocalDate(2014, 03, 15);
final List<InvoiceItem> invoiceItems = new ArrayList<InvoiceItem>();
for (int i = 0; i < 5; i++) {
invoiceItems.add(createUsageItem(firstEventStartDate.plusMonths(i)));
}
final LocalDate targetDate = invoiceItems.get(invoiceItems.size() - 1).getEndDate();
final Map<String, Usage> knownUsage = new HashMap<String, Usage>();
final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE);
final DefaultTier tier = createDefaultTierWithBlocks(block);
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, tier);
knownUsage.put(usageName, usage);
final DefaultTieredBlock block2 = createDefaultTieredBlock("unit2", 10, 10000, BigDecimal.TEN);
final DefaultTier tier2 = createDefaultTierWithBlocks(block2);
final DefaultUsage usage2 = createConsumableInArrearUsage("usageName2", BillingPeriod.ANNUAL, tier2);
knownUsage.put("usageName2", usage2);
final LocalDate result = rawUsageOptimizer.getOptimizedRawUsageStartDate(firstEventStartDate, targetDate, invoiceItems, knownUsage, internalCallContext);
// The same reasoning applies as previously because there is no usage items against the annual and
// so, the largest endDate for ii is 2014-08-15, and by default org.killbill.invoice.readMaxRawUsagePreviousPeriod == 2 => targetDate => 2014-06-15
Assert.assertEquals(result.compareTo(new LocalDate(2014, 06, 15)), 0, "142 got " + result);
}
use of org.killbill.billing.catalog.DefaultUsage in project killbill by killbill.
the class TestRawUsageOptimizer method testWithNoItems.
@Test(groups = "fast")
public void testWithNoItems() {
final LocalDate firstEventStartDate = new LocalDate(2014, 03, 15);
final List<InvoiceItem> invoiceItems = new ArrayList<InvoiceItem>();
final Map<String, Usage> knownUsage = new HashMap<String, Usage>();
final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE);
final DefaultTier tier = createDefaultTierWithBlocks(block);
final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, tier);
knownUsage.put(usageName, usage);
final LocalDate result = rawUsageOptimizer.getOptimizedRawUsageStartDate(firstEventStartDate, firstEventStartDate.plusDays(1), invoiceItems, knownUsage, internalCallContext);
Assert.assertEquals(result.compareTo(firstEventStartDate), 0);
}
use of org.killbill.billing.catalog.DefaultUsage in project killbill by killbill.
the class TestUsageInArrearBase method createCapacityInArrearUsage.
protected DefaultUsage createCapacityInArrearUsage(final String usageName, final BillingPeriod billingPeriod, final DefaultTier... tiers) {
final DefaultUsage usage = new DefaultUsage();
usage.setName(usageName);
usage.setBillingMode(BillingMode.IN_ARREAR);
usage.setUsageType(UsageType.CAPACITY);
usage.setBillingPeriod(billingPeriod);
usage.setTiers(tiers);
return usage;
}
Aggregations