private void clearWithLock(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { final BlockingState blockingStateForService = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context); final String previousOverdueStateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; final OverdueState previousOverdueState = overdueStateSet.findState(previousOverdueStateName); overdueStateApplicator.clear(effectiveDate, overdueable, previousOverdueState, overdueStateSet.getClearState(), context); }
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); }
final SortedSet<BillingEvent> billingEventsToRemove = new TreeSet<BillingEvent>(); final List<BlockingState> blockingEvents = blockingApi.getBlockingAllForAccount(catalog, context);
assertEquals(baseEntitlement.getState(), EntitlementState.ACTIVE); final List<BlockingState> blockingAll = blockingInternalApi.getBlockingAllForAccount(catalog, internalCallContext); final List<BlockingState> history = ImmutableList.<BlockingState>copyOf(Collections2.<BlockingState>filter(blockingAll, new Predicate<BlockingState>() {
@Override public OverdueState getOverdueStateFor(final UUID accountId, final TenantContext tenantContext) throws OverdueApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(accountId, tenantContext); final BlockingState blockingStateForService = blockingInternalApi.getBlockingStateForService(accountId, BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalTenantContext); final String stateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; final OverdueConfig overdueConfig = overdueConfigCache.getOverdueConfig(internalTenantContext); final OverdueStateSet states = ((DefaultOverdueConfig) overdueConfig).getOverdueStatesAccount(); return states.findState(stateName); }
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()); } }
private OverdueState refreshWithLock(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { final BillingState billingState = billingState(context); final BlockingState blockingStateForService = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context); final String previousOverdueStateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; final OverdueState currentOverdueState = overdueStateSet.findState(previousOverdueStateName); final OverdueState nextOverdueState = overdueStateSet.calculateOverdueState(billingState, context.toLocalDate(context.getCreatedDate())); overdueStateApplicator.apply(effectiveDate, overdueStateSet, billingState, overdueable, currentOverdueState, nextOverdueState, context); return nextOverdueState; }
@Override public Boolean call() throws Exception { final BlockingState blockingStateForService = blockingApi.getBlockingStateForService(accountId, BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContext); final String stateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; return expected.equals(stateName); } });
private void clearWithLock(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { final BlockingState blockingStateForService = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context); final String previousOverdueStateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; final OverdueState previousOverdueState = overdueStateSet.findState(previousOverdueStateName); overdueStateApplicator.clear(effectiveDate, overdueable, previousOverdueState, overdueStateSet.getClearState(), context); }
@Override public OverdueState getOverdueStateFor(final UUID accountId, final TenantContext tenantContext) throws OverdueApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(accountId, tenantContext); final BlockingState blockingStateForService = blockingInternalApi.getBlockingStateForService(accountId, BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalTenantContext); final String stateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; final OverdueConfig overdueConfig = overdueConfigCache.getOverdueConfig(internalTenantContext); final OverdueStateSet states = ((DefaultOverdueConfig) overdueConfig).getOverdueStatesAccount(); return states.findState(stateName); }
private OverdueState refreshWithLock(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { final BillingState billingState = billingState(context); final BlockingState blockingStateForService = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context); final String previousOverdueStateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; final OverdueState currentOverdueState = overdueStateSet.findState(previousOverdueStateName); final OverdueState nextOverdueState = overdueStateSet.calculateOverdueState(billingState, context.toLocalDate(context.getCreatedDate())); overdueStateApplicator.apply(effectiveDate, overdueStateSet, billingState, overdueable, currentOverdueState, nextOverdueState, context); return nextOverdueState; }
protected void checkODState(final String expected, final UUID accountId) { try { // This will test the overdue notification queue: when we move the clock, the overdue system // should get notified to refresh its state. // Calling explicitly refresh here (overdueApi.refreshOverdueStateFor(account)) would not fully // test overdue. // Since we're relying on the notification queue, we may need to wait a bit (hence await()). await().atMost(10, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { final BlockingState blockingStateForService = blockingApi.getBlockingStateForService(accountId, BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContext); final String stateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; return expected.equals(stateName); } }); } catch (final Exception e) { final BlockingState blockingStateForService = blockingApi.getBlockingStateForService(accountId, BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContext); final String stateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME; Assert.assertEquals(stateName, expected, "Got exception: " + e.toString()); } }
assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.BLOCKED); final BlockingState blockingState = blockingInternalApi.getBlockingStateForService(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "foo", internalCallContext); assertTrue(blockingState.isBlockBilling()); assertTrue(blockingState.isBlockChange()); assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.ACTIVE); blockingInternalApi.getBlockingStateForService(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "foo", internalCallContext); clock.addDays(1);