Search in sources :

Example 11 with DefaultTier

use of org.killbill.billing.catalog.DefaultTier 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);
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) DefaultTieredBlock(org.killbill.billing.catalog.DefaultTieredBlock) LocalDate(org.joda.time.LocalDate) DefaultTier(org.killbill.billing.catalog.DefaultTier) Test(org.testng.annotations.Test)

Example 12 with DefaultTier

use of org.killbill.billing.catalog.DefaultTier 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);
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) DefaultTieredBlock(org.killbill.billing.catalog.DefaultTieredBlock) LocalDate(org.joda.time.LocalDate) DefaultTier(org.killbill.billing.catalog.DefaultTier) Test(org.testng.annotations.Test)

Example 13 with DefaultTier

use of org.killbill.billing.catalog.DefaultTier in project killbill by killbill.

the class TestSubscriptionConsumableInArrear method testComputeInArrearUsageInterval.

@Test(groups = "fast")
public void testComputeInArrearUsageInterval() {
    final List<BillingEvent> billingEvents = Lists.newArrayList();
    final String usageName1 = "erw";
    final DefaultTieredBlock block1 = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE);
    final DefaultTier tier1 = createDefaultTierWithBlocks(block1);
    final Usage usage1 = createConsumableInArrearUsage(usageName1, BillingPeriod.MONTHLY, tier1);
    final String usageName2 = "hghg";
    final DefaultTieredBlock block2 = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE);
    final DefaultTier tier2 = createDefaultTierWithBlocks(block2);
    final Usage usage2 = createConsumableInArrearUsage(usageName2, BillingPeriod.MONTHLY, tier2);
    final DateTime dt1 = new DateTime(2013, 3, 23, 4, 34, 59, DateTimeZone.UTC);
    final BillingEvent evt1 = createMockBillingEvent(dt1, BillingPeriod.MONTHLY, ImmutableList.<Usage>builder().add(usage1).add(usage2).build());
    billingEvents.add(evt1);
    final DateTime dt2 = new DateTime(2013, 4, 23, 4, 34, 59, DateTimeZone.UTC);
    final BillingEvent evt2 = createMockBillingEvent(dt2, BillingPeriod.MONTHLY, ImmutableList.<Usage>builder().add(usage1).build());
    billingEvents.add(evt2);
    final DateTime dt3 = new DateTime(2013, 5, 23, 4, 34, 59, DateTimeZone.UTC);
    final BillingEvent evt3 = createMockBillingEvent(dt3, BillingPeriod.MONTHLY, ImmutableList.<Usage>builder().add(usage1).add(usage2).build());
    billingEvents.add(evt3);
    LocalDate targetDate = new LocalDate(2013, 6, 23);
    final SubscriptionUsageInArrear foo = new SubscriptionUsageInArrear(accountId, invoiceId, billingEvents, ImmutableList.<RawUsage>of(), targetDate, new LocalDate(dt1, DateTimeZone.UTC), internalCallContext);
    final List<ContiguousIntervalUsageInArrear> result = foo.computeInArrearUsageInterval();
    assertEquals(result.size(), 3);
    assertEquals(result.get(0).getUsage().getName(), usageName2);
    assertEquals(result.get(0).getTransitionTimes().size(), 3);
    assertTrue(result.get(0).getTransitionTimes().get(0).compareTo(new LocalDate(2013, 3, 23)) == 0);
    assertTrue(result.get(0).getTransitionTimes().get(1).compareTo(new LocalDate(2013, 4, 15)) == 0);
    assertTrue(result.get(0).getTransitionTimes().get(2).compareTo(new LocalDate(2013, 4, 23)) == 0);
    assertEquals(result.get(1).getUsage().getName(), usageName1);
    assertEquals(result.get(1).getTransitionTimes().size(), 4);
    assertTrue(result.get(1).getTransitionTimes().get(0).compareTo(new LocalDate(2013, 3, 23)) == 0);
    assertTrue(result.get(1).getTransitionTimes().get(1).compareTo(new LocalDate(2013, 4, 15)) == 0);
    assertTrue(result.get(1).getTransitionTimes().get(2).compareTo(new LocalDate(2013, 5, 15)) == 0);
    assertTrue(result.get(1).getTransitionTimes().get(3).compareTo(new LocalDate(2013, 6, 15)) == 0);
    assertEquals(result.get(2).getUsage().getName(), usageName2);
    assertEquals(result.get(2).getTransitionTimes().size(), 2);
    assertTrue(result.get(2).getTransitionTimes().get(0).compareTo(new LocalDate(2013, 5, 23)) == 0);
    assertTrue(result.get(2).getTransitionTimes().get(1).compareTo(new LocalDate(2013, 6, 15)) == 0);
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) RawUsage(org.killbill.billing.usage.RawUsage) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultTieredBlock(org.killbill.billing.catalog.DefaultTieredBlock) DefaultTier(org.killbill.billing.catalog.DefaultTier) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 14 with DefaultTier

use of org.killbill.billing.catalog.DefaultTier in project killbill by killbill.

the class TestUsageInArrearBase method createDefaultTierWithLimits.

protected DefaultTier createDefaultTierWithLimits(final BigDecimal recurringAmountInCurrency, final DefaultLimit... limits) {
    final DefaultTier tier = new DefaultTier();
    tier.setLimits(limits);
    final DefaultPrice[] prices = new DefaultPrice[1];
    prices[0] = new DefaultPrice().setCurrency(currency).setValue(recurringAmountInCurrency);
    final DefaultInternationalPrice price = new DefaultInternationalPrice().setPrices(prices);
    tier.setRecurringPrice(price);
    return tier;
}
Also used : DefaultInternationalPrice(org.killbill.billing.catalog.DefaultInternationalPrice) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) DefaultTier(org.killbill.billing.catalog.DefaultTier)

Aggregations

DefaultTier (org.killbill.billing.catalog.DefaultTier)14 LocalDate (org.joda.time.LocalDate)12 Test (org.testng.annotations.Test)12 DefaultUsage (org.killbill.billing.catalog.DefaultUsage)11 DefaultTieredBlock (org.killbill.billing.catalog.DefaultTieredBlock)9 Usage (org.killbill.billing.catalog.api.Usage)9 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)8 UsageInvoiceItem (org.killbill.billing.invoice.model.UsageInvoiceItem)8 RawUsage (org.killbill.billing.usage.RawUsage)8 DefaultRawUsage (org.killbill.billing.usage.api.svcs.DefaultRawUsage)7 BigDecimal (java.math.BigDecimal)6 ArrayList (java.util.ArrayList)6 RolledUpUsage (org.killbill.billing.usage.api.RolledUpUsage)5 HashMap (java.util.HashMap)4 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)4 BillingEvent (org.killbill.billing.junction.BillingEvent)4 DefaultLimit (org.killbill.billing.catalog.DefaultLimit)3 DefaultUnit (org.killbill.billing.catalog.DefaultUnit)3 Predicate (com.google.common.base.Predicate)2 UsageInArrearItemsAndNextNotificationDate (org.killbill.billing.invoice.usage.ContiguousIntervalUsageInArrear.UsageInArrearItemsAndNextNotificationDate)2