Search in sources :

Example 6 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState 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 Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final BlockingStateType type = BlockingStateType.SUBSCRIPTION;
    final String state = "state";
    final String service = "service";
    // Verify initial state
    Assert.assertEquals(blockingStateDao.getBlockingAllForAccountRecordId(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(internalCallContext).size(), 2);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) BlockingStateType(org.killbill.billing.entitlement.api.BlockingStateType) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) Entitlement(org.killbill.billing.entitlement.api.Entitlement) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 7 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestProxyBlockingStateDao method testComparisonSameEffectiveDate.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/174")
public void testComparisonSameEffectiveDate() throws Exception {
    final UUID blockedId = UUID.randomUUID();
    final BlockingStateType blockingStateType = BlockingStateType.ACCOUNT;
    final String service = "test";
    final DateTime effectiveDate = clock.getUTCNow();
    final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), blockedId, blockingStateType, "OD1", service, false, false, false, effectiveDate.minusDays(10), effectiveDate, effectiveDate, 1L);
    final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), blockedId, blockingStateType, "OD2", service, true, true, true, effectiveDate.minusDays(5), effectiveDate, effectiveDate, 2L);
    final BlockingState bs3 = new DefaultBlockingState(UUID.randomUUID(), blockedId, blockingStateType, "OD3", service, true, true, true, effectiveDate, effectiveDate, effectiveDate, 3L);
    final BlockingState bs4 = new DefaultBlockingState(UUID.randomUUID(), blockedId, blockingStateType, "OD4", service, false, false, false, effectiveDate, effectiveDate, effectiveDate, 4L);
    verifySortedCopy(bs1, bs2, bs3, bs4, bs1, bs2, bs3, bs4);
    verifySortedCopy(bs1, bs2, bs3, bs4, bs1, bs3, bs2, bs4);
    verifySortedCopy(bs1, bs2, bs3, bs4, bs2, bs3, bs1, bs4);
    verifySortedCopy(bs1, bs2, bs3, bs4, bs2, bs1, bs3, bs4);
    verifySortedCopy(bs1, bs2, bs3, bs4, bs3, bs1, bs2, bs4);
    verifySortedCopy(bs1, bs2, bs3, bs4, bs3, bs2, bs1, bs4);
}
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 8 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class MockBlockingStateDao method getBlockingState.

@Override
public List<BlockingState> getBlockingState(final UUID blockableId, final BlockingStateType blockingStateType, final DateTime upToDate, final InternalTenantContext context) {
    final List<BlockingState> blockingStatesForId = blockingStates.get(blockableId);
    if (blockingStatesForId == null) {
        return new ArrayList<BlockingState>();
    }
    final Map<String, BlockingState> tmp = new HashMap<String, BlockingState>();
    for (BlockingState cur : blockingStatesForId) {
        final BlockingState curStateForService = tmp.get(cur.getService());
        if (curStateForService == null || curStateForService.getEffectiveDate().compareTo(cur.getEffectiveDate()) < 0) {
            tmp.put(cur.getService(), cur);
        }
    }
    return new ArrayList<BlockingState>(tmp.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockingState(org.killbill.billing.entitlement.api.BlockingState)

Example 9 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class MockBlockingStateDao method setBlockingStatesAndPostBlockingTransitionEvent.

@Override
public synchronized void setBlockingStatesAndPostBlockingTransitionEvent(final Map<BlockingState, Optional<UUID>> states, final InternalCallContext context) {
    for (final BlockingState state : states.keySet()) {
        if (blockingStates.get(state.getBlockedId()) == null) {
            blockingStates.put(state.getBlockedId(), new ArrayList<BlockingState>());
        }
        blockingStates.get(state.getBlockedId()).add(state);
        if (blockingStatesPerAccountRecordId.get(context.getAccountRecordId()) == null) {
            blockingStatesPerAccountRecordId.put(context.getAccountRecordId(), new ArrayList<BlockingState>());
        }
        blockingStatesPerAccountRecordId.get(context.getAccountRecordId()).add(state);
    }
}
Also used : BlockingState(org.killbill.billing.entitlement.api.BlockingState)

Example 10 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestBlockingDao method testDaoWithOneService.

@Test(groups = "slow", description = "Check BlockingStateDao with a single service")
public void testDaoWithOneService() {
    final UUID uuid = UUID.randomUUID();
    final String overdueStateName = "WayPassedItMan";
    final String service = "TEST";
    final boolean blockChange = true;
    final boolean blockEntitlement = false;
    final boolean blockBilling = false;
    clock.setDay(new LocalDate(2012, 4, 1));
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state1 = new DefaultBlockingState(uuid, BlockingStateType.ACCOUNT, overdueStateName, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(state1, Optional.<UUID>absent()), internalCallContext);
    assertListenerStatus();
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final String overdueStateName2 = "NoReallyThisCantGoOn";
    final BlockingState state2 = new DefaultBlockingState(uuid, BlockingStateType.ACCOUNT, overdueStateName2, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(state2, Optional.<UUID>absent()), internalCallContext);
    assertListenerStatus();
    Assert.assertEquals(blockingStateDao.getBlockingStateForService(uuid, BlockingStateType.ACCOUNT, service, internalCallContext).getStateName(), state2.getStateName());
    final List<BlockingState> states = blockingStateDao.getBlockingAllForAccountRecordId(internalCallContext);
    Assert.assertEquals(states.size(), 2);
    Assert.assertEquals(states.get(0).getStateName(), overdueStateName);
    Assert.assertEquals(states.get(1).getStateName(), overdueStateName2);
}
Also used : DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Aggregations

BlockingState (org.killbill.billing.entitlement.api.BlockingState)46 UUID (java.util.UUID)24 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)22 Test (org.testng.annotations.Test)15 DateTime (org.joda.time.DateTime)13 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)6 LocalDate (org.joda.time.LocalDate)5 ImmutableList (com.google.common.collect.ImmutableList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Account (org.killbill.billing.account.api.Account)4 BillingEvent (org.killbill.billing.junction.BillingEvent)4 Optional (com.google.common.base.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 TreeSet (java.util.TreeSet)3 AccountApiException (org.killbill.billing.account.api.AccountApiException)3 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)3 BlockingStateType (org.killbill.billing.entitlement.api.BlockingStateType)3