Search in sources :

Example 96 with BillingEvent

use of org.killbill.billing.junction.BillingEvent 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 97 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestUsageInArrearBase method createContiguousIntervalConsumableInArrear.

protected ContiguousIntervalUsageInArrear createContiguousIntervalConsumableInArrear(final DefaultUsage usage, final List<RawUsage> rawUsages, final LocalDate targetDate, final boolean closedInterval, final BillingEvent... events) {
    final ContiguousIntervalUsageInArrear intervalConsumableInArrear = new ContiguousIntervalUsageInArrear(usage, accountId, invoiceId, rawUsages, targetDate, new LocalDate(events[0].getEffectiveDate()), internalCallContext);
    for (final BillingEvent event : events) {
        intervalConsumableInArrear.addBillingEvent(event);
    }
    intervalConsumableInArrear.build(closedInterval);
    return intervalConsumableInArrear;
}
Also used : BillingEvent(org.killbill.billing.junction.BillingEvent) LocalDate(org.joda.time.LocalDate)

Example 98 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestUsageInArrearBase method createMockBillingEvent.

protected BillingEvent createMockBillingEvent(final DateTime effectiveDate, final BillingPeriod billingPeriod, final List<Usage> usages) {
    final BillingEvent result = Mockito.mock(BillingEvent.class);
    Mockito.when(result.getCurrency()).thenReturn(Currency.BTC);
    Mockito.when(result.getBillCycleDayLocal()).thenReturn(BCD);
    Mockito.when(result.getTimeZone()).thenReturn(DateTimeZone.UTC);
    Mockito.when(result.getEffectiveDate()).thenReturn(effectiveDate);
    Mockito.when(result.getBillingPeriod()).thenReturn(billingPeriod);
    final Account account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(accountId);
    final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class);
    Mockito.when(subscription.getId()).thenReturn(subscriptionId);
    Mockito.when(subscription.getBundleId()).thenReturn(bundleId);
    Mockito.when(result.getSubscription()).thenReturn(subscription);
    final Plan plan = Mockito.mock(Plan.class);
    Mockito.when(plan.getName()).thenReturn(planName);
    Mockito.when(result.getPlan()).thenReturn(plan);
    final PlanPhase phase = Mockito.mock(PlanPhase.class);
    Mockito.when(phase.getName()).thenReturn(phaseName);
    Mockito.when(result.getPlanPhase()).thenReturn(phase);
    Mockito.when(result.getUsages()).thenReturn(usages);
    return result;
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) Account(org.killbill.billing.account.api.Account) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) BillingEvent(org.killbill.billing.junction.BillingEvent) Plan(org.killbill.billing.catalog.api.Plan)

Aggregations

BillingEvent (org.killbill.billing.junction.BillingEvent)98 Test (org.testng.annotations.Test)82 DateTime (org.joda.time.DateTime)52 LocalDate (org.joda.time.LocalDate)49 Plan (org.killbill.billing.catalog.api.Plan)42 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)41 MockPlan (org.killbill.billing.catalog.MockPlan)40 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)40 BigDecimal (java.math.BigDecimal)36 ArrayList (java.util.ArrayList)36 UUID (java.util.UUID)35 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)35 BillingEventSet (org.killbill.billing.junction.BillingEventSet)33 Invoice (org.killbill.billing.invoice.api.Invoice)32 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)32 TreeSet (java.util.TreeSet)30 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)27 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)26 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)25 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)25