Search in sources :

Example 6 with RolledUpUnit

use of org.killbill.billing.usage.api.RolledUpUnit in project killbill by killbill.

the class TestContiguousIntervalCapacityInArrear method testComputeBilledUsage.

@Test(groups = "fast")
public void testComputeBilledUsage() throws CatalogApiException {
    final DefaultUnit unit1 = new DefaultUnit().setName("unit1");
    final DefaultUnit unit2 = new DefaultUnit().setName("unit2");
    final DefaultLimit limit1_1 = new DefaultLimit().setUnit(unit1).setMax((double) 100).setMin((double) -1);
    final DefaultLimit limit1_2 = new DefaultLimit().setUnit(unit2).setMax((double) 1000).setMin((double) -1);
    final DefaultTier tier1 = createDefaultTierWithLimits(BigDecimal.TEN, limit1_1, limit1_2);
    final DefaultLimit limit2_1 = new DefaultLimit().setUnit(unit1).setMax((double) 200).setMin((double) -1);
    final DefaultLimit limit2_2 = new DefaultLimit().setUnit(unit2).setMax((double) 2000).setMin((double) -1);
    final DefaultTier tier2 = createDefaultTierWithLimits(new BigDecimal("20.0"), limit2_1, limit2_2);
    // Don't define any max for last tier to allow any number
    final DefaultLimit limit3_1 = new DefaultLimit().setUnit(unit1).setMin((double) -1).setMax((double) -1);
    final DefaultLimit limit3_2 = new DefaultLimit().setUnit(unit2).setMin((double) -1).setMax((double) -1);
    final DefaultTier tier3 = createDefaultTierWithLimits(new BigDecimal("30.0"), limit3_1, limit3_2);
    final DefaultUsage usage = createCapacityInArrearUsage(usageName, BillingPeriod.MONTHLY, tier1, tier2, tier3);
    final LocalDate targetDate = new LocalDate(2014, 03, 20);
    final ContiguousIntervalUsageInArrear intervalCapacityInArrear = createContiguousIntervalConsumableInArrear(usage, ImmutableList.<RawUsage>of(), targetDate, false, createMockBillingEvent(targetDate.toDateTimeAtStartOfDay(DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList()));
    // Tier 1 (both units from tier 1)
    BigDecimal result = intervalCapacityInArrear.computeToBeBilledCapacityInArrear(ImmutableList.<RolledUpUnit>of(new DefaultRolledUpUnit("unit1", 100L), new DefaultRolledUpUnit("unit2", 1000L)));
    assertEquals(result, BigDecimal.TEN);
    // Tier 2 (only one unit from tier 1)
    result = intervalCapacityInArrear.computeToBeBilledCapacityInArrear(ImmutableList.<RolledUpUnit>of(new DefaultRolledUpUnit("unit1", 100L), new DefaultRolledUpUnit("unit2", 1001L)));
    assertEquals(result, new BigDecimal("20.0"));
    // Tier 2 (only one unit from tier 1)
    result = intervalCapacityInArrear.computeToBeBilledCapacityInArrear(ImmutableList.<RolledUpUnit>of(new DefaultRolledUpUnit("unit1", 101L), new DefaultRolledUpUnit("unit2", 1000L)));
    assertEquals(result, new BigDecimal("20.0"));
    // Tier 2 (both units from tier 2)
    result = intervalCapacityInArrear.computeToBeBilledCapacityInArrear(ImmutableList.<RolledUpUnit>of(new DefaultRolledUpUnit("unit1", 101L), new DefaultRolledUpUnit("unit2", 1001L)));
    assertEquals(result, new BigDecimal("20.0"));
    // Tier 3 (only one unit from tier 3)
    result = intervalCapacityInArrear.computeToBeBilledCapacityInArrear(ImmutableList.<RolledUpUnit>of(new DefaultRolledUpUnit("unit1", 10L), new DefaultRolledUpUnit("unit2", 2001L)));
    assertEquals(result, new BigDecimal("30.0"));
}
Also used : DefaultLimit(org.killbill.billing.catalog.DefaultLimit) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) RolledUpUsage(org.killbill.billing.usage.api.RolledUpUsage) Usage(org.killbill.billing.catalog.api.Usage) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) RawUsage(org.killbill.billing.usage.RawUsage) RolledUpUnit(org.killbill.billing.usage.api.RolledUpUnit) DefaultUnit(org.killbill.billing.catalog.DefaultUnit) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) DefaultTier(org.killbill.billing.catalog.DefaultTier) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

RolledUpUnit (org.killbill.billing.usage.api.RolledUpUnit)6 LocalDate (org.joda.time.LocalDate)4 RolledUpUsage (org.killbill.billing.usage.api.RolledUpUsage)4 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 RawUsage (org.killbill.billing.usage.RawUsage)2 RolledUpUsageModelDao (org.killbill.billing.usage.dao.RolledUpUsageModelDao)2 Joiner (com.google.common.base.Joiner)1 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)1 DefaultLimit (org.killbill.billing.catalog.DefaultLimit)1 DefaultTier (org.killbill.billing.catalog.DefaultTier)1 DefaultUnit (org.killbill.billing.catalog.DefaultUnit)1 DefaultUsage (org.killbill.billing.catalog.DefaultUsage)1 Limit (org.killbill.billing.catalog.api.Limit)1 Tier (org.killbill.billing.catalog.api.Tier)1 Usage (org.killbill.billing.catalog.api.Usage)1 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)1 UsageInvoiceItem (org.killbill.billing.invoice.model.UsageInvoiceItem)1