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); }
public DefaultBlockingState(final BlockingState input, final DateTime effectiveDate) { this(input.getBlockedId(), input.getType(), input.getStateName(), input.getService(), input.isBlockChange(), input.isBlockEntitlement(), input.isBlockBilling(), effectiveDate); }
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; }
public void checkStateApplied(final BlockingState result, final OverdueState state) { Assert.assertEquals(result.getStateName(), state.getName()); Assert.assertEquals(result.isBlockChange(), state.isBlockChanges()); Assert.assertEquals(result.isBlockEntitlement(), state.isDisableEntitlementAndChangesBlocked()); Assert.assertEquals(result.isBlockBilling(), state.isDisableEntitlementAndChangesBlocked()); }
private void verifySortedCopy(final BlockingState bs1, final BlockingState bs2, final BlockingState bs3, final BlockingState bs4, final BlockingState a, final BlockingState b, final BlockingState c, final BlockingState d) { final List<BlockingState> sortedCopy = ProxyBlockingStateDao.sortedCopy(ImmutableList.<BlockingState>of(a, b, c, d)); Assert.assertEquals(sortedCopy.get(0).getStateName(), bs1.getStateName()); Assert.assertEquals(sortedCopy.get(1).getStateName(), bs2.getStateName()); Assert.assertEquals(sortedCopy.get(2).getStateName(), bs3.getStateName()); Assert.assertEquals(sortedCopy.get(3).getStateName(), bs4.getStateName()); } }
@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 doCheckFutureBlockingStatesToCancel(final DefaultEntitlement addOnEntitlement, final DateTime effectiveCancellationDateTime, final Collection<BlockingState> blockingStatesForCancellation) { if (addOnEntitlement == null || effectiveCancellationDateTime == null) { Assert.assertEquals(blockingStatesForCancellation.size(), 0); } else { Assert.assertEquals(blockingStatesForCancellation.size(), 1); final BlockingState blockingState = blockingStatesForCancellation.iterator().next(); Assert.assertEquals(blockingState.getBlockedId(), addOnEntitlement.getId()); Assert.assertEquals(blockingState.getEffectiveDate(), effectiveCancellationDateTime); Assert.assertEquals(blockingState.getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingState.getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingState.getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } }
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); }
public DefaultBlockingState(final BlockingState input, final DateTime effectiveDate) { this(input.getBlockedId(), input.getType(), input.getStateName(), input.getService(), input.isBlockChange(), input.isBlockEntitlement(), input.isBlockBilling(), effectiveDate); }
private void checkBlockingStatesDAO(final DefaultEntitlement baseEntitlement, final DefaultEntitlement addOnEntitlement, final LocalDate effectiveBaseCancellationDate, final LocalDate effectiveAddOnCancellationDate, final boolean isBaseCancelled) { final List<BlockingState> blockingStatesForBaseEntitlement = blockingStatesForBlockedId(baseEntitlement.getId()); Assert.assertEquals(blockingStatesForBaseEntitlement.size(), isBaseCancelled ? 2 : 1); if (isBaseCancelled) { Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getBlockedId(), baseEntitlement.getId()); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getEffectiveDate().toLocalDate(), effectiveBaseCancellationDate); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } final List<BlockingState> blockingStatesForAddOn = blockingStatesForBlockedId(addOnEntitlement.getId()); Assert.assertEquals(blockingStatesForAddOn.size(), 2); Assert.assertEquals(blockingStatesForAddOn.get(1).getBlockedId(), addOnEntitlement.getId()); Assert.assertEquals(blockingStatesForAddOn.get(1).getEffectiveDate().toLocalDate(), effectiveAddOnCancellationDate); Assert.assertEquals(blockingStatesForAddOn.get(1).getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingStatesForAddOn.get(1).getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingStatesForAddOn.get(1).getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); }
private void verifyBlockingStates(final Iterable<BlockingState> result, final List<BlockingState> expected) { int i = 0; final Iterator<BlockingState> iterator = result.iterator(); while (iterator.hasNext()) { final BlockingState cur = iterator.next(); final BlockingState expectedItem = expected.get(i); assertEquals(cur.isBlockBilling(), expectedItem.isBlockBilling()); assertEquals(cur.isBlockEntitlement(), expectedItem.isBlockEntitlement()); assertEquals(cur.isBlockChange(), expectedItem.isBlockChange()); assertEquals(cur.getService(), expectedItem.getService()); assertEquals(cur.getStateName(), expectedItem.getStateName()); assertEquals(cur.getBlockedId(), expectedItem.getBlockedId()); assertEquals(internalCallContext.toLocalDate(cur.getEffectiveDate()).compareTo(internalCallContext.toLocalDate(expectedItem.getEffectiveDate())), 0); i++; } assertEquals(i, expected.size()); }
private void doCheckActualBlockingStatesToCancel(final DefaultEntitlement addOnEntitlement, final DateTime effectiveCancellationDateTime, final boolean approximateDateCheck, final Collection<BlockingState> blockingStatesForCancellation) { if (effectiveCancellationDateTime == null) { Assert.assertEquals(blockingStatesForCancellation.size(), 0); } else { Assert.assertEquals(blockingStatesForCancellation.size(), 1); final BlockingState blockingState = blockingStatesForCancellation.iterator().next(); Assert.assertEquals(blockingState.getBlockedId(), addOnEntitlement.getId()); if (approximateDateCheck) { Assert.assertEquals(blockingState.getEffectiveDate().toLocalDate(), effectiveCancellationDateTime.toLocalDate()); Assert.assertEquals(blockingState.getEffectiveDate().getMinuteOfDay(), effectiveCancellationDateTime.getMinuteOfDay()); } else { Assert.assertEquals(blockingState.getEffectiveDate(), effectiveCancellationDateTime); } Assert.assertEquals(blockingState.getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingState.getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingState.getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } }
@Test(groups = "slow", description = "Check BlockingStateDao with a single service") public void testDaoWithOneService() throws AccountApiException { final UUID uuid = createAccount(getAccountData(1)).getId(); 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(catalog, internalCallContext); Assert.assertEquals(states.size(), 2); Assert.assertEquals(states.get(0).getStateName(), overdueStateName); Assert.assertEquals(states.get(1).getStateName(), overdueStateName2); }
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()); } }
Assert.assertEquals(history2.get(0).getStateName(), overdueStateName); Assert.assertEquals(history2.get(1).getStateName(), overdueStateName2);
public BlockingStateJson(final BlockingState input, final AccountAuditLogs accountAuditLogs) { this(input.getBlockedId(), input.getStateName(), input.getService(), input.isBlockChange(), input.isBlockEntitlement(), input.isBlockBilling(), input.getEffectiveDate(), input.getType(), toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForBlockingState(input.getId()))); }
@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); }