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);
}
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);
}
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());
}
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);
}
}
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);
}
Aggregations