Search in sources :

Example 6 with DefaultBlockingState

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

the class TestBlockingApi method testCreateBaseSubscriptionOnBlockedChangeAcount.

@Test(groups = "slow")
public void testCreateBaseSubscriptionOnBlockedChangeAcount() throws AccountApiException, EntitlementApiException, SubscriptionApiException {
    final LocalDate initialDate = new LocalDate(2017, 5, 1);
    clock.setDay(initialDate);
    final Account account = createAccount(getAccountData(1));
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState blockChangeAccount = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "State1", "Service1", true, false, false, clock.getUTCNow());
    subscriptionApi.addBlockingState(blockChangeAccount, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Try create subscription right now
    try {
        final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("shotgun-monthly", null);
        entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "xyzqe", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
        fail("Should fail to create entitlement when ACCOUNT has been 'change' blocked");
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode());
    }
    // Try create subscription in the future
    try {
        final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("shotgun-monthly", null);
        entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "xyzqe", null, initialDate.plusDays(3), false, true, ImmutableList.<PluginProperty>of(), callContext);
        fail("Should fail to create entitlement when ACCOUNT has been 'change' blocked");
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode());
    }
    // Try create subscription in the past
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("shotgun-monthly", null);
    testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE);
    entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "xyzqe", initialDate.minusDays(3), null, false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) Account(org.killbill.billing.account.api.Account) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) LocalDate(org.joda.time.LocalDate) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 7 with DefaultBlockingState

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

the class TestDefaultBlockingStateDao method testUnnecessaryEventsAreNotAdded.

@Test(groups = "slow", description = "Verify we don't insert extra add-on events")
public void testUnnecessaryEventsAreNotAdded() throws Exception {
    // This is a simple smoke test at the dao level only to make sure we do sane
    // things in case there are no future add-on cancellation events to add in the stream.
    // See TestEntitlementUtils for a more comprehensive test
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    final BlockingStateType type = BlockingStateType.SUBSCRIPTION;
    final String state = "state";
    final String service = "service";
    // Verify initial state
    Assert.assertEquals(blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext).size(), 1);
    // Set a state in the future so no event
    final DateTime stateDateTime = new DateTime(2013, 5, 6, 10, 11, 12, DateTimeZone.UTC);
    final BlockingState blockingState = new DefaultBlockingState(entitlement.getId(), type, state, service, false, false, false, stateDateTime);
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState, Optional.<UUID>of(entitlement.getBundleId())), internalCallContext);
    assertListenerStatus();
    Assert.assertEquals(blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext).size(), 2);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) BlockingStateType(org.killbill.billing.entitlement.api.BlockingStateType) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) DateTime(org.joda.time.DateTime) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 8 with DefaultBlockingState

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

the class TestDefaultBlockingStateDao method testSetBlockingState.

// See https://github.com/killbill/killbill/issues/111
@Test(groups = "slow", description = "Verify we don't insert duplicate blocking states")
public void testSetBlockingState() throws Exception {
    final UUID blockableId = UUID.randomUUID();
    final BlockingStateType type = BlockingStateType.ACCOUNT;
    final String state = "state";
    final String state2 = "state-2";
    final String serviceA = "service-A";
    final String serviceB = "service-B";
    // Verify initial state
    Assert.assertEquals(blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext).size(), 0);
    // Note: the checkers below rely on record_id ordering, not effective date
    // Set a state for service A
    final DateTime stateDateTime = new DateTime(2013, 5, 6, 10, 11, 12, DateTimeZone.UTC);
    final BlockingState blockingState1 = new DefaultBlockingState(blockableId, type, state, serviceA, false, false, false, stateDateTime);
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState1, Optional.<UUID>absent()), internalCallContext);
    final List<BlockingState> blockingStates1 = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
    Assert.assertEquals(blockingStates1.size(), 1);
    Assert.assertEquals(blockingStates1.get(0).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates1.get(0).getStateName(), state);
    Assert.assertEquals(blockingStates1.get(0).getService(), serviceA);
    Assert.assertEquals(blockingStates1.get(0).getEffectiveDate(), stateDateTime);
    // Set the same state again - no change
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState1, Optional.<UUID>absent()), internalCallContext);
    final List<BlockingState> blockingStates2 = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
    Assert.assertEquals(blockingStates2.size(), 1);
    Assert.assertEquals(blockingStates2.get(0).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates2.get(0).getStateName(), state);
    Assert.assertEquals(blockingStates2.get(0).getService(), serviceA);
    Assert.assertEquals(blockingStates2.get(0).getEffectiveDate(), stateDateTime);
    // Set the state for service B
    final BlockingState blockingState2 = new DefaultBlockingState(blockableId, type, state, serviceB, false, false, false, stateDateTime);
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState2, Optional.<UUID>absent()), internalCallContext);
    final List<BlockingState> blockingStates3 = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
    Assert.assertEquals(blockingStates3.size(), 2);
    Assert.assertEquals(blockingStates3.get(0).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates3.get(0).getStateName(), state);
    Assert.assertEquals(blockingStates3.get(0).getService(), serviceA);
    Assert.assertEquals(blockingStates3.get(0).getEffectiveDate(), stateDateTime);
    Assert.assertEquals(blockingStates3.get(1).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates3.get(1).getStateName(), state);
    Assert.assertEquals(blockingStates3.get(1).getService(), serviceB);
    Assert.assertEquals(blockingStates3.get(1).getEffectiveDate(), stateDateTime);
    // Set the state for service A in the future - there should be no change (already effective)
    final DateTime stateDateTime2 = new DateTime(2013, 6, 6, 10, 11, 12, DateTimeZone.UTC);
    final BlockingState blockingState3 = new DefaultBlockingState(blockableId, type, state, serviceA, false, false, false, stateDateTime2);
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState3, Optional.<UUID>absent()), internalCallContext);
    final List<BlockingState> blockingStates4 = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
    Assert.assertEquals(blockingStates4.size(), 2);
    Assert.assertEquals(blockingStates4.get(0).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates4.get(0).getStateName(), state);
    Assert.assertEquals(blockingStates4.get(0).getService(), serviceA);
    Assert.assertEquals(blockingStates4.get(0).getEffectiveDate(), stateDateTime);
    Assert.assertEquals(blockingStates4.get(1).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates4.get(1).getStateName(), state);
    Assert.assertEquals(blockingStates4.get(1).getService(), serviceB);
    Assert.assertEquals(blockingStates4.get(1).getEffectiveDate(), stateDateTime);
    // Set the state for service A in the past - the new effective date should be respected
    final DateTime stateDateTime3 = new DateTime(2013, 2, 6, 10, 11, 12, DateTimeZone.UTC);
    final BlockingState blockingState4 = new DefaultBlockingState(blockableId, type, state, serviceA, false, false, false, stateDateTime3);
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState4, Optional.<UUID>absent()), internalCallContext);
    final List<BlockingState> blockingStates5 = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
    Assert.assertEquals(blockingStates5.size(), 2);
    Assert.assertEquals(blockingStates5.get(0).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates5.get(0).getStateName(), state);
    Assert.assertEquals(blockingStates5.get(0).getService(), serviceA);
    Assert.assertEquals(blockingStates5.get(0).getEffectiveDate(), stateDateTime3);
    Assert.assertEquals(blockingStates5.get(1).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates5.get(1).getStateName(), state);
    Assert.assertEquals(blockingStates5.get(1).getService(), serviceB);
    Assert.assertEquals(blockingStates5.get(1).getEffectiveDate(), stateDateTime);
    // Set a new state for service A
    final DateTime state2DateTime = new DateTime(2013, 12, 6, 10, 11, 12, DateTimeZone.UTC);
    final BlockingState blockingState5 = new DefaultBlockingState(blockableId, type, state2, serviceA, false, false, false, state2DateTime);
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState5, Optional.<UUID>absent()), internalCallContext);
    final List<BlockingState> blockingStates6 = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
    Assert.assertEquals(blockingStates6.size(), 3);
    Assert.assertEquals(blockingStates6.get(0).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates6.get(0).getStateName(), state);
    Assert.assertEquals(blockingStates6.get(0).getService(), serviceA);
    Assert.assertEquals(blockingStates6.get(0).getEffectiveDate(), stateDateTime3);
    Assert.assertEquals(blockingStates6.get(1).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates6.get(1).getStateName(), state);
    Assert.assertEquals(blockingStates6.get(1).getService(), serviceB);
    Assert.assertEquals(blockingStates6.get(1).getEffectiveDate(), stateDateTime);
    Assert.assertEquals(blockingStates6.get(2).getBlockedId(), blockableId);
    Assert.assertEquals(blockingStates6.get(2).getStateName(), state2);
    Assert.assertEquals(blockingStates6.get(2).getService(), serviceA);
    Assert.assertEquals(blockingStates6.get(2).getEffectiveDate(), state2DateTime);
}
Also used : BlockingStateType(org.killbill.billing.entitlement.api.BlockingStateType) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 9 with DefaultBlockingState

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

the class TestDefaultSubscriptionBundleTimeline method testOneEntitlementWithInitialBlockingStateImpl.

private void testOneEntitlementWithInitialBlockingStateImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
    clock.setDay(new LocalDate(2013, 1, 1));
    final DateTimeZone accountTimeZone = DateTimeZone.UTC;
    final UUID accountId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final String externalKey = "foo";
    final UUID entitlementId = UUID.randomUUID();
    final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
    final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
    final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, clock.getUTCNow(), clock.getUTCNow(), clock.getUTCNow(), 0L);
    blockingStates.add(bs1);
    clock.addDays(1);
    DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
    final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
    allTransitions.add(tr1);
    if (!regressionFlagForOlderVersionThan_0_17_X) {
        final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
        blockingStates.add(bsCreate);
    }
    effectiveDate = effectiveDate.plusDays(30);
    clock.addDays(30);
    final SubscriptionBaseTransition tr2 = createTransition(entitlementId, EventType.PHASE, null, effectiveDate, clock.getUTCNow(), "trial", "phase");
    allTransitions.add(tr2);
    final String service = "boo";
    final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, "NothingUseful", service, false, false, false, clock.getUTCNow(), clock.getUTCNow(), clock.getUTCNow(), 1L);
    blockingStates.add(bs2);
    effectiveDate = effectiveDate.plusDays(15);
    clock.addDays(15);
    final SubscriptionBaseTransition tr3 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "phase", null);
    allTransitions.add(tr3);
    final List<Entitlement> entitlements = new ArrayList<Entitlement>();
    final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
    entitlements.add(entitlement);
    final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
    assertEquals(timeline.getAccountId(), accountId);
    assertEquals(timeline.getBundleId(), bundleId);
    assertEquals(timeline.getExternalKey(), externalKey);
    final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
    assertEquals(events.size(), 5);
    assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE);
    assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE);
    assertEquals(events.get(4).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
    assertEquals(events.get(0).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertEquals(events.get(2).getServiceName(), EntitlementOrderingBase.ENT_BILLING_SERVICE_NAME);
    assertEquals(events.get(3).getServiceName(), service);
    assertEquals(events.get(4).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertNull(events.get(0).getPrevPhase());
    assertNull(events.get(1).getPrevPhase());
    assertEquals(events.get(1).getNextPhase().getName(), "trial");
    assertEquals(events.get(2).getPrevPhase().getName(), "trial");
    assertEquals(events.get(2).getNextPhase().getName(), "phase");
    assertEquals(events.get(3).getPrevPhase().getName(), "phase");
    assertEquals(events.get(3).getNextPhase().getName(), "phase");
    assertEquals(events.get(4).getPrevPhase().getName(), "phase");
    assertNull(events.get(4).getNextPhase());
}
Also used : ArrayList(java.util.ArrayList) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) LocalDate(org.joda.time.LocalDate) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) UUID(java.util.UUID) SubscriptionBaseTransition(org.killbill.billing.subscription.api.user.SubscriptionBaseTransition) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Example 10 with DefaultBlockingState

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

the class TestDefaultSubscriptionBundleTimeline method testCancelBundleBeforeSubscriptionImpl.

private void testCancelBundleBeforeSubscriptionImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
    clock.setDay(new LocalDate(2013, 1, 1));
    final DateTimeZone accountTimeZone = DateTimeZone.UTC;
    final UUID accountId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final String externalKey = "foo";
    final UUID entitlementId = UUID.randomUUID();
    final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
    final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
    DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
    final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
    allTransitions.add(tr1);
    if (!regressionFlagForOlderVersionThan_0_17_X) {
        final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
        blockingStates.add(bsCreate);
    }
    // Block the bundle before the subscription
    effectiveDate = effectiveDate.plusDays(15);
    clock.addDays(15);
    final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CANCELLED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
    blockingStates.add(bs1);
    effectiveDate = effectiveDate.plusDays(15);
    clock.addDays(15);
    final SubscriptionBaseTransition tr2 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "trial", null);
    allTransitions.add(tr2);
    final List<Entitlement> entitlements = new ArrayList<Entitlement>();
    final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
    entitlements.add(entitlement);
    final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
    assertEquals(timeline.getAccountId(), accountId);
    assertEquals(timeline.getBundleId(), bundleId);
    assertEquals(timeline.getExternalKey(), externalKey);
    final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
    assertEquals(events.size(), 4);
    assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
    assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
    assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
    assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
    assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
    assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
    assertEquals(events.get(0).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertEquals(events.get(2).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
    assertEquals(events.get(3).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
    assertNull(events.get(0).getPrevPhase());
    assertNull(events.get(1).getPrevPhase());
    assertEquals(events.get(1).getNextPhase().getName(), "trial");
    assertEquals(events.get(3).getPrevPhase().getName(), "trial");
    assertNull(events.get(3).getNextPhase());
}
Also used : ArrayList(java.util.ArrayList) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) LocalDate(org.joda.time.LocalDate) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) UUID(java.util.UUID) SubscriptionBaseTransition(org.killbill.billing.subscription.api.user.SubscriptionBaseTransition) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Aggregations

DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)63 UUID (java.util.UUID)46 DateTime (org.joda.time.DateTime)38 BlockingState (org.killbill.billing.entitlement.api.BlockingState)37 Test (org.testng.annotations.Test)35 LocalDate (org.joda.time.LocalDate)34 Account (org.killbill.billing.account.api.Account)23 ArrayList (java.util.ArrayList)21 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)19 DateTimeZone (org.joda.time.DateTimeZone)14 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)14 SubscriptionBaseTransition (org.killbill.billing.subscription.api.user.SubscriptionBaseTransition)11 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)9 Entitlement (org.killbill.billing.entitlement.api.Entitlement)8 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)7 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)7 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)7 BigDecimal (java.math.BigDecimal)6 BillingEvent (org.killbill.billing.junction.BillingEvent)6