Search in sources :

Example 1 with DefaultRawUsage

use of org.killbill.billing.usage.api.svcs.DefaultRawUsage in project killbill by killbill.

the class TestContiguousIntervalConsumableInArrear method testMultipleItemsAndTiersWithExistingItemsAllTiers_DETAIL.

@Test(groups = "fast")
public void testMultipleItemsAndTiersWithExistingItemsAllTiers_DETAIL() throws Exception {
    // 
    // Create usage data points (will include already billed + add new usage data)
    // 
    List<RawUsageRecord> rawUsageRecords = new ArrayList<RawUsageRecord>();
    // tier 3
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 20), "FOO", 50L + /* already built */
    20L, "tracking-1"));
    // tier 2
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 21), "BAR", 80L + /* already built */
    120L, "tracking-1"));
    // FOO : 10 (tier 1) + 40 (tier 2) = 50
    final UsageConsumableInArrearTierUnitAggregate existingFooUsageTier1 = new UsageConsumableInArrearTierUnitAggregate(1, "FOO", BigDecimal.ONE, 1L, 10L, new BigDecimal("10.00"));
    final String usageInArrearDetail1 = objectMapper.writeValueAsString(existingFooUsageTier1);
    final UsageConsumableInArrearTierUnitAggregate existingFooUsageTier2 = new UsageConsumableInArrearTierUnitAggregate(2, "FOO", BigDecimal.TEN, 1L, 40L, new BigDecimal("400.00"));
    final String usageInArrearDetail2 = objectMapper.writeValueAsString(existingFooUsageTier2);
    // BAR : 10 (tier 1) + 40 (tier 2)
    final UsageConsumableInArrearTierUnitAggregate existingBarUsageTier1 = new UsageConsumableInArrearTierUnitAggregate(1, "BAR", new BigDecimal("2.00"), 1L, 80L, new BigDecimal("160.00"));
    final String usageInArrearDetail3 = objectMapper.writeValueAsString(existingBarUsageTier1);
    // Same as previous example bu instead of creating JSON we create one item per type/tier
    final List<InvoiceItem> existingItems = new ArrayList<InvoiceItem>();
    final InvoiceItem i1 = new UsageInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, usageName, null, new LocalDate(2014, 03, 20), new LocalDate(2014, 04, 15), new BigDecimal("10.00"), /* amount */
    new BigDecimal("1.00"), /* rate = tierPrice*/
    currency, 10, /* # units*/
    usageInArrearDetail1);
    final InvoiceItem i2 = new UsageInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, usageName, null, new LocalDate(2014, 03, 20), new LocalDate(2014, 04, 15), new BigDecimal("400.00"), new BigDecimal("10.00"), currency, 40, usageInArrearDetail2);
    final InvoiceItem i3 = new UsageInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, usageName, null, new LocalDate(2014, 03, 20), new LocalDate(2014, 04, 15), new BigDecimal("160.00"), new BigDecimal("2.00"), currency, 80, usageInArrearDetail3);
    existingItems.addAll(ImmutableList.<InvoiceItem>of(i1, i2, i3));
    List<InvoiceItem> result = produceInvoiceItems(rawUsageRecords, TierBlockPolicy.ALL_TIERS, UsageDetailMode.DETAIL, existingItems);
    assertEquals(result.size(), 4);
    final UsageConsumableInArrearTierUnitAggregate resultUsageInArrearDetail0 = objectMapper.readValue(result.get(0).getItemDetails(), new TypeReference<UsageConsumableInArrearTierUnitAggregate>() {
    });
    assertEquals(resultUsageInArrearDetail0.getTierUnit(), "BAR");
    assertEquals(resultUsageInArrearDetail0.getTier(), 1);
    assertEquals(resultUsageInArrearDetail0.getQuantity().intValue(), 20);
    assertEquals(resultUsageInArrearDetail0.getTierPrice().compareTo(new BigDecimal("2.00")), 0);
    assertEquals(result.get(0).getRate().compareTo(new BigDecimal("2.00")), 0);
    assertEquals(result.get(0).getAmount().compareTo(new BigDecimal("40.00")), 0);
    assertEquals(result.get(0).getQuantity().intValue(), 20);
    final UsageConsumableInArrearTierUnitAggregate resultUsageInArrearDetail1 = objectMapper.readValue(result.get(1).getItemDetails(), new TypeReference<UsageConsumableInArrearTierUnitAggregate>() {
    });
    assertEquals(resultUsageInArrearDetail1.getTierUnit(), "BAR");
    assertEquals(resultUsageInArrearDetail1.getTier(), 2);
    assertEquals(resultUsageInArrearDetail1.getQuantity().intValue(), 100);
    assertEquals(resultUsageInArrearDetail1.getTierPrice().compareTo(new BigDecimal("20.00")), 0);
    assertEquals(result.get(1).getRate().compareTo(new BigDecimal("20.00")), 0);
    assertEquals(result.get(1).getAmount().compareTo(new BigDecimal("2000.00")), 0);
    assertEquals(result.get(1).getQuantity().intValue(), 100);
    final UsageConsumableInArrearTierUnitAggregate resultUsageInArrearDetail2 = objectMapper.readValue(result.get(2).getItemDetails(), new TypeReference<UsageConsumableInArrearTierUnitAggregate>() {
    });
    assertEquals(resultUsageInArrearDetail2.getTierUnit(), "FOO");
    assertEquals(resultUsageInArrearDetail2.getTier(), 2);
    assertEquals(resultUsageInArrearDetail2.getQuantity().intValue(), 10);
    assertEquals(resultUsageInArrearDetail2.getTierPrice().compareTo(new BigDecimal("10.00")), 0);
    assertEquals(result.get(2).getRate().compareTo(new BigDecimal("10.00")), 0);
    assertEquals(result.get(2).getAmount().compareTo(new BigDecimal("100.00")), 0);
    assertEquals(result.get(2).getQuantity().intValue(), 10);
    final UsageConsumableInArrearTierUnitAggregate resultUsageInArrearDetail3 = objectMapper.readValue(result.get(3).getItemDetails(), new TypeReference<UsageConsumableInArrearTierUnitAggregate>() {
    });
    assertEquals(resultUsageInArrearDetail3.getTierUnit(), "FOO");
    assertEquals(resultUsageInArrearDetail3.getTier(), 3);
    assertEquals(resultUsageInArrearDetail3.getQuantity().intValue(), 10);
    assertEquals(resultUsageInArrearDetail3.getTierPrice().compareTo(new BigDecimal("100.00")), 0);
    assertEquals(result.get(3).getRate().compareTo(new BigDecimal("100.00")), 0);
    assertEquals(result.get(3).getAmount().compareTo(new BigDecimal("1000.00")), 0);
    assertEquals(result.get(3).getQuantity().intValue(), 10);
}
Also used : RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) UsageConsumableInArrearTierUnitAggregate(org.killbill.billing.invoice.usage.details.UsageConsumableInArrearTierUnitAggregate) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) ArrayList(java.util.ArrayList) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with DefaultRawUsage

use of org.killbill.billing.usage.api.svcs.DefaultRawUsage in project killbill by killbill.

the class TestContiguousIntervalConsumableInArrear method testGetRolledUpUsageUsageAtTransitionTimes.

@Test(groups = "fast")
public void testGetRolledUpUsageUsageAtTransitionTimes() throws Exception {
    final DefaultTieredBlock tieredBlock1 = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE);
    final DefaultTier tier = createDefaultTierWithBlocks(tieredBlock1);
    final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier);
    // 2015-03-15T18:10:17Z
    final LocalDate t0 = new LocalDate(2015, 03, BCD);
    final BillingEvent eventT0 = createMockBillingEvent(t0.toDateTime(new LocalTime(18, 10, 17), DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList(), catalogEffectiveDate);
    Mockito.when(eventT0.getTransitionType()).thenReturn(SubscriptionBaseTransitionType.CREATE);
    // 2015-04-01T11:22:30Z
    final LocalDate t1 = new LocalDate(2015, 04, 01);
    final BillingEvent eventT1 = createMockBillingEvent(t1.toDateTime(new LocalTime(11, 22, 30), DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList(), catalogEffectiveDate);
    Mockito.when(eventT1.getTransitionType()).thenReturn(SubscriptionBaseTransitionType.CANCEL);
    final LocalDate targetDate = t1;
    // At t0
    final RawUsageRecord raw1 = new DefaultRawUsage(subscriptionId, t0, "unit", 12L, "tracking-1");
    // At t1
    final RawUsageRecord raw2 = new DefaultRawUsage(subscriptionId, t1, "unit", 10L, "tracking-2");
    // Should be ignored
    final RawUsageRecord raw3 = new DefaultRawUsage(subscriptionId, new LocalDate(2015, 04, 02), "unit", 100L, "tracking-3");
    final List<RawUsageRecord> rawUsageRecord = ImmutableList.of(raw1, raw2, raw3);
    final ContiguousIntervalUsageInArrear intervalConsumableInArrear = createContiguousIntervalConsumableInArrear(usage, rawUsageRecord, targetDate, true, eventT0, eventT1);
    final List<RolledUpUsageWithMetadata> rolledUpUsage = intervalConsumableInArrear.getRolledUpUsage().getUsage();
    assertEquals(rolledUpUsage.size(), 1);
    assertEquals(rolledUpUsage.get(0).getSubscriptionId(), subscriptionId);
    assertEquals(rolledUpUsage.get(0).getStart().compareTo(t0), 0);
    assertEquals(rolledUpUsage.get(0).getEnd().compareTo(t1), 0);
    assertEquals(rolledUpUsage.get(0).getRolledUpUnits().size(), 1);
    assertEquals(rolledUpUsage.get(0).getRolledUpUnits().get(0).getUnitType(), "unit");
    assertEquals(rolledUpUsage.get(0).getRolledUpUnits().get(0).getAmount().longValue(), 22L);
}
Also used : RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) LocalTime(org.joda.time.LocalTime) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) DefaultTieredBlock(org.killbill.billing.catalog.DefaultTieredBlock) DefaultTier(org.killbill.billing.catalog.DefaultTier) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 3 with DefaultRawUsage

use of org.killbill.billing.usage.api.svcs.DefaultRawUsage in project killbill by killbill.

the class TestContiguousIntervalConsumableInArrear method testComputeMissingItemsDetailModeAllTier_DETAIL.

@Test(groups = "fast")
public void testComputeMissingItemsDetailModeAllTier_DETAIL() throws Exception {
    // Case 1
    List<RawUsageRecord> rawUsageRecords = new ArrayList<RawUsageRecord>();
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 20), "FOO", 5L, "tracking-1"));
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 21), "BAR", 99L, "tracking-1"));
    List<InvoiceItem> result = produceInvoiceItems(rawUsageRecords, TierBlockPolicy.ALL_TIERS, UsageDetailMode.DETAIL, ImmutableList.<InvoiceItem>of());
    assertEquals(result.size(), 2);
    // BAR: 99 * 2 = 198
    assertEquals(result.get(0).getAmount().compareTo(new BigDecimal("198")), 0);
    assertEquals(result.get(0).getQuantity().intValue(), 99);
    assertEquals(result.get(0).getRate().compareTo(new BigDecimal("2.0")), 0);
    // FOO: 5 * 1 = 5
    assertEquals(result.get(1).getAmount().compareTo(new BigDecimal("5")), 0);
    assertEquals(result.get(1).getQuantity().intValue(), 5);
    assertEquals(result.get(1).getRate().compareTo(BigDecimal.ONE), 0);
    // Case 2
    rawUsageRecords = new ArrayList<RawUsageRecord>();
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 20), "FOO", 5L, "tracking-1"));
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 21), "BAR", 101L, "tracking-1"));
    result = produceInvoiceItems(rawUsageRecords, TierBlockPolicy.ALL_TIERS, UsageDetailMode.DETAIL, ImmutableList.<InvoiceItem>of());
    assertEquals(result.size(), 3);
    // BAR: 100 * 2 = 200
    assertEquals(result.get(0).getAmount().compareTo(new BigDecimal("200.0")), 0);
    assertEquals(result.get(0).getQuantity().intValue(), 100);
    assertEquals(result.get(0).getRate().compareTo(new BigDecimal("2.0")), 0);
    // BAR: 1 * 20 = 20
    assertEquals(result.get(1).getAmount().compareTo(new BigDecimal("20.0")), 0);
    assertEquals(result.get(1).getQuantity().intValue(), 1);
    assertEquals(result.get(1).getRate().compareTo(new BigDecimal("20.0")), 0);
    // FOO: 5 * 1 = 5
    assertEquals(result.get(2).getAmount().compareTo(new BigDecimal("5")), 0);
    assertEquals(result.get(2).getQuantity().intValue(), 5);
    assertEquals(result.get(2).getRate().compareTo(BigDecimal.ONE), 0);
    // Case 3
    rawUsageRecords = new ArrayList<RawUsageRecord>();
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 20), "FOO", 75L, "tracking-2"));
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 21), "BAR", 101L, "tracking-2"));
    result = produceInvoiceItems(rawUsageRecords, TierBlockPolicy.ALL_TIERS, UsageDetailMode.DETAIL, ImmutableList.<InvoiceItem>of());
    assertEquals(result.size(), 5);
    // BAR: 100 * 2 = 200
    assertEquals(result.get(0).getAmount().compareTo(new BigDecimal("200.0")), 0);
    assertEquals(result.get(0).getQuantity().intValue(), 100);
    assertEquals(result.get(0).getRate().compareTo(new BigDecimal("2.0")), 0);
    // BAR: 1 * 20 = 20
    assertEquals(result.get(1).getAmount().compareTo(new BigDecimal("20.0")), 0);
    assertEquals(result.get(1).getQuantity().intValue(), 1);
    assertEquals(result.get(1).getRate().compareTo(new BigDecimal("20.0")), 0);
    // FOO: 10 * 1 = 10
    assertEquals(result.get(2).getAmount().compareTo(BigDecimal.TEN), 0);
    assertEquals(result.get(2).getQuantity().intValue(), 10);
    assertEquals(result.get(2).getRate().compareTo(BigDecimal.ONE), 0);
    // FOO: 50 * 10 = 500
    assertEquals(result.get(3).getAmount().compareTo(new BigDecimal("500")), 0);
    assertEquals(result.get(3).getQuantity().intValue(), 50);
    assertEquals(result.get(3).getRate().compareTo(BigDecimal.TEN), 0);
    // FOO: 15 * 100 = 1500
    assertEquals(result.get(4).getAmount().compareTo(new BigDecimal("1500")), 0);
    assertEquals(result.get(4).getQuantity().intValue(), 15);
    assertEquals(result.get(4).getRate().compareTo(new BigDecimal("100.0")), 0);
}
Also used : RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ArrayList(java.util.ArrayList) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 4 with DefaultRawUsage

use of org.killbill.billing.usage.api.svcs.DefaultRawUsage in project killbill by killbill.

the class TestContiguousIntervalConsumableInArrear method testWithRawUsageRecordStartDateAfterEndDate.

@Test(groups = "fast", description = "See https://github.com/killbill/killbill/issues/706")
public void testWithRawUsageRecordStartDateAfterEndDate() throws Exception {
    final LocalDate startDate = new LocalDate(2014, 10, 16);
    final LocalDate endDate = startDate;
    final LocalDate targetDate = endDate;
    final LocalDate rawUsageRecordStartDate = new LocalDate(2015, 10, 16);
    final List<RawUsageRecord> rawUsageRecords = new ArrayList<RawUsageRecord>();
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, startDate, "unit", 130L, "tracking-1"));
    final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 10, BigDecimal.ONE);
    final DefaultTier tier = createDefaultTierWithBlocks(block);
    final DefaultUsage usage = createConsumableInArrearUsage(usageName, BillingPeriod.MONTHLY, TierBlockPolicy.ALL_TIERS, tier);
    final BillingEvent event1 = createMockBillingEvent(startDate.toDateTimeAtStartOfDay(DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList(), catalogEffectiveDate);
    final BillingEvent event2 = createMockBillingEvent(new LocalDate(2014, 10, 16).toDateTimeAtStartOfDay(DateTimeZone.UTC), BillingPeriod.MONTHLY, Collections.<Usage>emptyList(), catalogEffectiveDate);
    final ContiguousIntervalUsageInArrear intervalConsumableInArrear = new ContiguousIntervalConsumableUsageInArrear(usage, accountId, invoiceId, rawUsageRecords, EMPTY_EXISTING_TRACKING_IDS, targetDate, rawUsageRecordStartDate, usageDetailMode, invoiceConfig, false, internalCallContext);
    intervalConsumableInArrear.addBillingEvent(event1);
    intervalConsumableInArrear.addAllSeenUnitTypesForBillingEvent(event1, ImmutableSet.<String>of("unit"));
    intervalConsumableInArrear.addBillingEvent(event2);
    intervalConsumableInArrear.addAllSeenUnitTypesForBillingEvent(event2, ImmutableSet.<String>of("unit"));
    final ContiguousIntervalUsageInArrear res = intervalConsumableInArrear.build(true);
    assertEquals(res.getTransitionTimes().size(), 0);
}
Also used : RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) ArrayList(java.util.ArrayList) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) DefaultUsage(org.killbill.billing.catalog.DefaultUsage) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultTieredBlock(org.killbill.billing.catalog.DefaultTieredBlock) LocalDate(org.joda.time.LocalDate) DefaultTier(org.killbill.billing.catalog.DefaultTier) Test(org.testng.annotations.Test)

Example 5 with DefaultRawUsage

use of org.killbill.billing.usage.api.svcs.DefaultRawUsage in project killbill by killbill.

the class TestContiguousIntervalConsumableInArrear method testMultipleItemsAndTiersWithExistingItemsAllTiers_AGGREGATE.

@Test(groups = "fast")
public void testMultipleItemsAndTiersWithExistingItemsAllTiers_AGGREGATE() throws Exception {
    // 
    // Let's assume we were already billed on the previous period
    // 
    // FOO : 10 (tier 1) + 40 (tier 2) = 50
    final UsageConsumableInArrearTierUnitAggregate existingFooUsageTier1 = new UsageConsumableInArrearTierUnitAggregate(1, "FOO", BigDecimal.ONE, 1L, 10L, new BigDecimal("10.00"));
    final UsageConsumableInArrearTierUnitAggregate existingFooUsageTier2 = new UsageConsumableInArrearTierUnitAggregate(2, "FOO", BigDecimal.TEN, 1L, 40L, new BigDecimal("400.00"));
    // BAR : 10 (tier 1) + 40 (tier 2)
    final UsageConsumableInArrearTierUnitAggregate existingBarUsageTier1 = new UsageConsumableInArrearTierUnitAggregate(1, "BAR", new BigDecimal("2.00"), 1L, 80L, new BigDecimal("160.00"));
    final List<UsageConsumableInArrearTierUnitAggregate> existingUsage = ImmutableList.of(existingFooUsageTier1, existingFooUsageTier2, existingBarUsageTier1);
    final UsageConsumableInArrearAggregate usageConsumableInArrearDetail = new UsageConsumableInArrearAggregate(existingUsage);
    final String existingUsageJson = objectMapper.writeValueAsString(usageConsumableInArrearDetail);
    // 
    // Create usage data points (will include already billed + add new usage data)
    // 
    List<RawUsageRecord> rawUsageRecords = new ArrayList<RawUsageRecord>();
    // tier 3
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 20), "FOO", 50L + /* already built */
    20L, "tracking-1"));
    // tier 2
    rawUsageRecords.add(new DefaultRawUsage(subscriptionId, new LocalDate(2014, 03, 21), "BAR", 80L + /* already built */
    120L, "tracking-1"));
    final List<InvoiceItem> existingItems = new ArrayList<InvoiceItem>();
    final InvoiceItem ii1 = new UsageInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, usageName, null, new LocalDate(2014, 03, 20), new LocalDate(2014, 04, 15), new BigDecimal("570.00"), null, currency, null, existingUsageJson);
    existingItems.add(ii1);
    List<InvoiceItem> result = produceInvoiceItems(rawUsageRecords, TierBlockPolicy.ALL_TIERS, UsageDetailMode.AGGREGATE, existingItems);
    assertEquals(result.size(), 1);
    assertEquals(result.get(0).getAmount().compareTo(new BigDecimal("3140.00")), 0, String.format("%s != 3140.0", result.get(0).getAmount()));
    UsageConsumableInArrearAggregate usageDetail = objectMapper.readValue(result.get(0).getItemDetails(), new TypeReference<UsageConsumableInArrearAggregate>() {
    });
    List<UsageConsumableInArrearTierUnitAggregate> itemDetails = usageDetail.getTierDetails();
    // We get same total than AGGREGATE : 3140
    // BAR item detail
    assertEquals(itemDetails.get(0).getTierUnit(), "BAR");
    assertEquals(itemDetails.get(0).getTier(), 1);
    assertEquals(itemDetails.get(0).getTierBlockSize(), 1);
    assertEquals(itemDetails.get(0).getQuantity().intValue(), 20);
    assertEquals(itemDetails.get(0).getTierPrice().compareTo(new BigDecimal("2.00")), 0);
    assertEquals(itemDetails.get(0).getAmount().compareTo(new BigDecimal("40.00")), 0);
    assertEquals(itemDetails.get(1).getTierUnit(), "BAR");
    assertEquals(itemDetails.get(1).getTier(), 2);
    assertEquals(itemDetails.get(1).getTierBlockSize(), 1);
    assertEquals(itemDetails.get(1).getQuantity().intValue(), 100);
    assertEquals(itemDetails.get(1).getTierPrice().compareTo(new BigDecimal("20.00")), 0);
    assertEquals(itemDetails.get(1).getAmount().compareTo(new BigDecimal("2000.00")), 0);
    // FOO item detail
    assertEquals(itemDetails.get(2).getTierUnit(), "FOO");
    assertEquals(itemDetails.get(2).getTier(), 1);
    assertEquals(itemDetails.get(2).getTierBlockSize(), 1);
    assertEquals(itemDetails.get(2).getQuantity().intValue(), 0);
    assertEquals(itemDetails.get(2).getTierPrice().compareTo(new BigDecimal("1.00")), 0);
    assertEquals(itemDetails.get(2).getAmount().compareTo(new BigDecimal("0.00")), 0);
    assertEquals(itemDetails.get(3).getTierUnit(), "FOO");
    assertEquals(itemDetails.get(3).getTier(), 2);
    assertEquals(itemDetails.get(3).getTierBlockSize(), 1);
    assertEquals(itemDetails.get(3).getQuantity().intValue(), 10);
    assertEquals(itemDetails.get(3).getTierPrice().compareTo(new BigDecimal("10.00")), 0);
    assertEquals(itemDetails.get(3).getAmount().compareTo(new BigDecimal("100.00")), 0);
    assertEquals(itemDetails.get(4).getTierUnit(), "FOO");
    assertEquals(itemDetails.get(4).getTier(), 3);
    assertEquals(itemDetails.get(4).getTierBlockSize(), 1);
    assertEquals(itemDetails.get(4).getQuantity().intValue(), 10);
    assertEquals(itemDetails.get(4).getTierPrice().compareTo(new BigDecimal("100.00")), 0);
    assertEquals(itemDetails.get(4).getAmount().compareTo(new BigDecimal("1000.00")), 0);
}
Also used : UsageConsumableInArrearAggregate(org.killbill.billing.invoice.usage.details.UsageConsumableInArrearAggregate) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) UsageInvoiceItem(org.killbill.billing.invoice.model.UsageInvoiceItem) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) UsageConsumableInArrearTierUnitAggregate(org.killbill.billing.invoice.usage.details.UsageConsumableInArrearTierUnitAggregate) DefaultRawUsage(org.killbill.billing.usage.api.svcs.DefaultRawUsage) Test(org.testng.annotations.Test)

Aggregations

LocalDate (org.joda.time.LocalDate)16 RawUsageRecord (org.killbill.billing.usage.api.RawUsageRecord)16 DefaultRawUsage (org.killbill.billing.usage.api.svcs.DefaultRawUsage)16 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)12 BigDecimal (java.math.BigDecimal)11 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)11 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)11 UsageInvoiceItem (org.killbill.billing.invoice.model.UsageInvoiceItem)11 DefaultTier (org.killbill.billing.catalog.DefaultTier)8 DefaultUsage (org.killbill.billing.catalog.DefaultUsage)8 BillingEvent (org.killbill.billing.junction.BillingEvent)8 DefaultTieredBlock (org.killbill.billing.catalog.DefaultTieredBlock)7 UsageConsumableInArrearTierUnitAggregate (org.killbill.billing.invoice.usage.details.UsageConsumableInArrearTierUnitAggregate)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 UsageConsumableInArrearAggregate (org.killbill.billing.invoice.usage.details.UsageConsumableInArrearAggregate)4 UsageInArrearItemsAndNextNotificationDate (org.killbill.billing.invoice.usage.ContiguousIntervalUsageInArrear.UsageInArrearItemsAndNextNotificationDate)3 LocalTime (org.joda.time.LocalTime)2 UsageCapacityInArrearAggregate (org.killbill.billing.invoice.usage.details.UsageCapacityInArrearAggregate)2 UsageInArrearTierUnitDetail (org.killbill.billing.invoice.usage.details.UsageInArrearTierUnitDetail)2