protected void storeNewState(final DateTime effectiveDate, final ImmutableAccountData blockable, final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueException { try { blockingApi.setBlockingState(new DefaultBlockingState(blockable.getId(), BlockingStateType.ACCOUNT, nextOverdueState.getName(), OverdueService.OVERDUE_SERVICE_NAME, blockChanges(nextOverdueState), blockEntitlement(nextOverdueState), blockBilling(nextOverdueState), effectiveDate), context); } catch (final Exception e) { throw new OverdueException(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED, blockable.getId(), blockable.getClass().getName()); } }
protected void storeNewState(final DateTime effectiveDate, final ImmutableAccountData blockable, final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueException { try { blockingApi.setBlockingState(new DefaultBlockingState(blockable.getId(), BlockingStateType.ACCOUNT, nextOverdueState.getName(), OverdueService.OVERDUE_SERVICE_NAME, blockChanges(nextOverdueState), blockEntitlement(nextOverdueState), blockBilling(nextOverdueState), effectiveDate), context); } catch (final Exception e) { throw new OverdueException(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED, blockable.getId(), blockable.getClass().getName()); } }
@Test(groups = "slow") public void testApi() { 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; testListener.pushExpectedEvent(NextEvent.BLOCK); final BlockingState state1 = new DefaultBlockingState(uuid, BlockingStateType.ACCOUNT, overdueStateName, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow()); blockingInternalApi.setBlockingState(state1, internalCallContext); assertListenerStatus(); clock.setDeltaFromReality(1000 * 3600 * 24); testListener.pushExpectedEvent(NextEvent.BLOCK); final String overdueStateName2 = "NoReallyThisCantGoOn"; final BlockingState state2 = new DefaultBlockingState(uuid, BlockingStateType.ACCOUNT, overdueStateName2, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow()); blockingInternalApi.setBlockingState(state2, internalCallContext); assertListenerStatus(); Assert.assertEquals(blockingInternalApi.getBlockingStateForService(uuid, BlockingStateType.ACCOUNT, service, internalCallContext).getStateName(), overdueStateName2); }
@Test(groups = "slow") public void testApiHistory() throws Exception { final String overdueStateName = "WayPassedItMan"; final String service = "TEST"; final boolean blockChange = true; final boolean blockEntitlement = false; final boolean blockBilling = false; final Account account = createAccount(getAccountData(7)); testListener.pushExpectedEvent(NextEvent.BLOCK); final BlockingState state1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, overdueStateName, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow()); blockingInternalApi.setBlockingState(state1, internalCallContext); assertListenerStatus(); clock.setDeltaFromReality(1000 * 3600 * 24); testListener.pushExpectedEvent(NextEvent.BLOCK); final String overdueStateName2 = "NoReallyThisCantGoOn"; final BlockingState state2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, overdueStateName2, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow()); blockingInternalApi.setBlockingState(state2, internalCallContext); assertListenerStatus(); final List<BlockingState> blockingAll = blockingInternalApi.getBlockingAllForAccount(catalog, internalCallContext); final List<BlockingState> history = ImmutableList.<BlockingState>copyOf(Collections2.<BlockingState>filter(blockingAll, new Predicate<BlockingState>() { @Override public boolean apply(final BlockingState input) { return input.getService().equals(service); } })); Assert.assertEquals(history.size(), 2); Assert.assertEquals(history.get(0).getStateName(), overdueStateName); Assert.assertEquals(history.get(1).getStateName(), overdueStateName2); }