private void clearOverdue(final UUID accountId, final InternalCallContext context) { try { factory.createOverdueWrapperFor(accountId, context).clear(context); } catch (BillingExceptionBase e) { log.error(String.format("Error processing Overdue for blockable %s (type %s)", accountId), e); } } }
@SuppressWarnings("unchecked") public OverdueWrapper createOverdueWrapperFor(final Account blockable) throws OverdueException { return (OverdueWrapper) new OverdueWrapper(blockable, api, getOverdueStateSet(), clock, billingStateCalculator, overdueStateApplicator); }
@Test(groups = "slow") public void testWrapperNoConfig() throws Exception { overdueWrapperFactory.setOverdueConfig(null); final Account account; final OverdueWrapper wrapper; final OverdueState state; final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); state = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); final OverdueState result = wrapper.refresh(internalCallContext); Assert.assertEquals(result.getName(), state.getName()); Assert.assertEquals(result.blockChanges(), state.blockChanges()); Assert.assertEquals(result.disableEntitlementAndChangesBlocked(), state.disableEntitlementAndChangesBlocked()); } }
@LifecycleHandlerType(LifecycleLevel.LOAD_CATALOG) public synchronized void loadConfig() throws ServiceException { if (!isConfigLoaded) { try { final URI u = new URI(properties.getConfigURI()); overdueConfig = XMLLoader.getObjectFromUri(u, OverdueConfig.class); // File not found? if (overdueConfig == null) { log.warn("Unable to load the overdue config from " + properties.getConfigURI()); overdueConfig = new OverdueConfig(); } isConfigLoaded = true; } catch (final URISyntaxException e) { overdueConfig = new OverdueConfig(); } catch (final IllegalArgumentException e) { overdueConfig = new OverdueConfig(); } catch (final Exception e) { throw new ServiceException(e); } factory.setOverdueConfig(overdueConfig); ((DefaultOverdueUserApi) userApi).setOverdueConfig(overdueConfig); } }
@Test(groups = "slow") public void testWrapperBasic() throws Exception { final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); overdueWrapperFactory.setOverdueConfig(config); Account account; OverdueWrapper wrapper; OverdueState state; state = config.getStateSet().findState("OD1"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); state = config.getStateSet().findState("OD2"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(41)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); state = config.getStateSet().findState("OD3"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(51)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); }
@Test(groups = "slow") public void testApplicator() throws Exception { final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); overdueWrapperFactory.setOverdueConfig(config); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); final OverdueStateSet overdueStateSet = config.getStateSet(); final OverdueState clearState = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME); OverdueState state; state = config.getStateSet().findState("OD1"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD1"); state = config.getStateSet().findState("OD2"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD2"); state = config.getStateSet().findState("OD3"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD3"); }
private void processOverdue(final UUID accountId, final InternalCallContext context) { try { factory.createOverdueWrapperFor(accountId, context).refresh(context); } catch (BillingExceptionBase e) { log.error(String.format("Error processing Overdue for blockable %s", accountId), e); } }
@SuppressWarnings("unchecked") public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(), clock, billingStateCalculator, overdueStateApplicator); } catch (AccountApiException e) { throw new OverdueException(e); } }
@Override public OverdueState refreshOverdueStateFor(final Account blockable, final CallContext context) throws OverdueException, OverdueApiException { log.info("Refresh of blockable {} ({}) requested", blockable.getId(), blockable.getClass()); final OverdueWrapper wrapper = factory.createOverdueWrapperFor(blockable); return wrapper.refresh(createInternalCallContext(blockable, context)); }
@Override public BillingState getBillingStateFor(final Account overdueable, final TenantContext context) throws OverdueException { log.debug("Billing state of of {} requested", overdueable.getId()); final OverdueWrapper wrapper = factory.createOverdueWrapperFor(overdueable); return wrapper.billingState(internalCallContextFactory.createInternalTenantContext(context)); }