Search in sources :

Example 66 with BillingEvent

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

the class TestDefaultInternalBillingApi method testUnblockThenBlockBlockingStatesWithSameEffectiveDate.

// See https://github.com/killbill/killbill/commit/92042843e38a67f75495b207385e4c1f9ca60990#commitcomment-4749967
@Test(groups = "slow", description = "Check unblock then block states with same effective date are correctly handled", invocationCount = 10)
public void testUnblockThenBlockBlockingStatesWithSameEffectiveDate() throws Exception {
    final LocalDate initialDate = new LocalDate(2013, 8, 7);
    clock.setDay(initialDate);
    final Account account = createAccount(getAccountData(7));
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
    final SubscriptionBase subscription = subscriptionInternalApi.getSubscriptionFromId(entitlement.getId(), internalCallContext);
    assertListenerStatus();
    final DateTime block1Date = clock.getUTCNow();
    testListener.pushExpectedEvents(NextEvent.BLOCK);
    final DefaultBlockingState state1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_BLOCKED, EntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, true, block1Date);
    blockingInternalApi.setBlockingState(state1, internalCallContext);
    clock.addDays(1);
    final DateTime block2Date = clock.getUTCNow();
    testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
    final DefaultBlockingState state2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_CLEAR, EntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, block2Date);
    blockingInternalApi.setBlockingState(state2, internalCallContext);
    // Same date
    final DefaultBlockingState state3 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, DefaultEntitlementApi.ENT_STATE_BLOCKED, EntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, true, block2Date);
    blockingInternalApi.setBlockingState(state3, internalCallContext);
    assertListenerStatus();
    // Nothing should happen
    clock.addDays(3);
    assertListenerStatus();
    // Expected blocking duration:
    // * 2013-08-07 to now [2013-08-07 to 2013-08-08 then 2013-08-08 to now]
    final List<BillingEvent> events = ImmutableList.<BillingEvent>copyOf(billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext));
    Assert.assertEquals(events.size(), 2);
    Assert.assertEquals(events.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE);
    Assert.assertEquals(events.get(0).getEffectiveDate(), subscription.getStartDate());
    Assert.assertEquals(events.get(1).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
    Assert.assertEquals(events.get(1).getEffectiveDate(), block1Date);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) Account(org.killbill.billing.account.api.Account) BillingEvent(org.killbill.billing.junction.BillingEvent) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 67 with BillingEvent

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

the class TestBillingApi method testBillingEventsAccountAligned.

@Test(groups = "fast")
public void testBillingEventsAccountAligned() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
    final Plan nextPlan = catalog.findPlan("3-PickupTrialEvergreen10USD", clock.getUTCNow());
    final PlanPhase nextPhase = nextPlan.getAllPhases()[1];
    final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
    final Account account = createAccount(32);
    final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
    // The expected BCD is the account BCD (account aligned by default)
    checkFirstEvent(events, nextPlan, 32, subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString());
}
Also used : 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) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 68 with BillingEvent

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

the class TestBillingApi method testBillingEventsEmpty.

@Test(groups = "fast")
public void testBillingEventsEmpty() throws AccountApiException, CatalogApiException, SubscriptionBaseApiException {
    final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(new UUID(0L, 0L), null, internalCallContext);
    Assert.assertEquals(events.size(), 0);
}
Also used : BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 69 with BillingEvent

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

the class TestBlockingCalculator method testEventsToRemoveClosedFollow.

// Closed duration with only following
// -----[------------]-------Z-------------
@Test(groups = "fast")
public void testEventsToRemoveClosedFollow() {
    final DateTime now = clock.getUTCNow();
    final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>();
    final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>();
    disabledDuration.add(new DisabledDuration(now, now.plusDays(2)));
    final BillingEvent e3 = createRealEvent(now.plusDays(3), subscription1);
    billingEvents.add(e3);
    final SortedSet<BillingEvent> results = blockingCalculator.eventsToRemove(disabledDuration, billingEvents, subscription1);
    assertEquals(results.size(), 0);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 70 with BillingEvent

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

the class TestBlockingCalculator method testCreateNewEventsClosedFollow.

// Closed duration with only following
// -----[------------]-------Z-------------
@Test(groups = "fast")
public void testCreateNewEventsClosedFollow() throws CatalogApiException {
    final DateTime now = clock.getUTCNow();
    final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>();
    final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>();
    disabledDuration.add(new DisabledDuration(now, now.plusDays(2)));
    billingEvents.add(createRealEvent(now.plusDays(3), subscription1));
    final SortedSet<BillingEvent> results = blockingCalculator.createNewEvents(disabledDuration, billingEvents, subscription1, internalCallContext);
    assertEquals(results.size(), 0);
}
Also used : DisabledDuration(org.killbill.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

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