use of org.killbill.billing.entitlement.api.BlockingStateType 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.BlockingStateType 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.BlockingStateType 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(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(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(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(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(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(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(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);
}
Aggregations