Search in sources :

Example 36 with BillingEvent

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

the class TestDefaultBillingEvent method testToString.

@Test(groups = "fast")
public void testToString() throws Exception {
    // Simple test to ensure we have an easy to read toString representation
    final BillingEvent event = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z", DateTimeZone.UTC), SubscriptionBaseTransitionType.CREATE);
    Assert.assertEquals(event.toString(), "DefaultBillingEvent{type=CREATE, effectiveDate=2012-01-01T00:02:04.000Z, planPhaseName=Test-trial, subscriptionId=00000000-0000-0000-0000-000000000000, totalOrdering=1}");
}
Also used : BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 37 with BillingEvent

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

the class TestDefaultBillingEvent method testEdgeCaseAllEventsHappenAtTheSameTime.

@Test(groups = "fast")
public void testEdgeCaseAllEventsHappenAtTheSameTime() throws Exception {
    final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
    final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE, 1);
    final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionBaseTransitionType.CHANGE, 2);
    // Note the time delta here. Having a blocking duration of zero and events at the same time won't work as the backing tree set does local
    // comparisons (and not global), making the END_BILLING_DISABLED start the first one in the set
    final BillingEvent event3 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:05.000Z"), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
    final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>();
    set.add(event0);
    set.add(event1);
    set.add(event2);
    set.add(event3);
    final Iterator<BillingEvent> it = set.iterator();
    Assert.assertEquals(event1, it.next());
    Assert.assertEquals(event2, it.next());
    Assert.assertEquals(event0, it.next());
    Assert.assertEquals(event3, it.next());
}
Also used : TreeSet(java.util.TreeSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 38 with BillingEvent

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

the class TestDefaultBillingEvent method testEventTotalOrdering.

@Test(groups = "fast")
public void testEventTotalOrdering() {
    final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE, 1L);
    final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CANCEL, 2L);
    final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CANCEL, 3L);
    final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>();
    set.add(event2);
    set.add(event1);
    set.add(event0);
    final Iterator<BillingEvent> it = set.iterator();
    Assert.assertEquals(event0, it.next());
    Assert.assertEquals(event1, it.next());
    Assert.assertEquals(event2, it.next());
}
Also used : TreeSet(java.util.TreeSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 39 with BillingEvent

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

the class TestDefaultBillingEvent method testEventOrderingDate.

@Test(groups = "fast")
public void testEventOrderingDate() {
    final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE);
    final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-02-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE);
    final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-03-01T00:02:04.000Z"), SubscriptionBaseTransitionType.CREATE);
    final SortedSet<BillingEvent> set = new TreeSet<BillingEvent>();
    set.add(event2);
    set.add(event1);
    set.add(event0);
    final Iterator<BillingEvent> it = set.iterator();
    Assert.assertEquals(event0, it.next());
    Assert.assertEquals(event1, it.next());
    Assert.assertEquals(event2, it.next());
}
Also used : TreeSet(java.util.TreeSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 40 with BillingEvent

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

the class BlockingCalculator method precedingBillingEventForSubscription.

protected BillingEvent precedingBillingEventForSubscription(final DateTime datetime, final SortedSet<BillingEvent> billingEvents, final SubscriptionBase subscription) {
    if (datetime == null) {
        //second of a pair can be null if there's no re-enabling
        return null;
    }
    final SortedSet<BillingEvent> filteredBillingEvents = filter(billingEvents, subscription);
    BillingEvent result = filteredBillingEvents.first();
    if (datetime.isBefore(result.getEffectiveDate())) {
        //This case can happen, for example, if we have an add on and the bundle goes into disabled before the add on is created
        return null;
    }
    for (final BillingEvent event : filteredBillingEvents) {
        if (!event.getEffectiveDate().isBefore(datetime)) {
            // found it its the previous event
            return result;
        } else {
            // still looking
            result = event;
        }
    }
    return result;
}
Also used : BillingEvent(org.killbill.billing.junction.BillingEvent)

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