Search in sources :

Example 1 with DefaultOverdueConfig

use of org.killbill.billing.overdue.config.DefaultOverdueConfig in project killbill by killbill.

the class TestOverdueWrapper method testWrapperBasic.

@Test(groups = "slow")
public void testWrapperBasic() throws Exception {
    final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
    final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
    ((MockOverdueConfigCache) overdueConfigCache).loadOverwriteDefaultOverdueConfig(config);
    Account account;
    OverdueWrapper wrapper;
    OverdueState state;
    state = config.getOverdueStatesAccount().findState("OD1");
    account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
    wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
    wrapper.refresh(clock.getUTCNow(), internalCallContext);
    testOverdueHelper.checkStateApplied(state);
    state = config.getOverdueStatesAccount().findState("OD2");
    account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(41));
    wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
    wrapper.refresh(clock.getUTCNow(), internalCallContext);
    testOverdueHelper.checkStateApplied(state);
    state = config.getOverdueStatesAccount().findState("OD3");
    account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(51));
    wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
    wrapper.refresh(clock.getUTCNow(), internalCallContext);
    testOverdueHelper.checkStateApplied(state);
}
Also used : Account(org.killbill.billing.account.api.Account) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) MockOverdueConfigCache(org.killbill.billing.overdue.caching.MockOverdueConfigCache) OverdueState(org.killbill.billing.overdue.api.OverdueState) Test(org.testng.annotations.Test)

Example 2 with DefaultOverdueConfig

use of org.killbill.billing.overdue.config.DefaultOverdueConfig in project killbill by killbill.

the class EhCacheOverdueConfigCache method initializeCacheLoaderArgument.

private CacheLoaderArgument initializeCacheLoaderArgument() {
    final LoaderCallback loaderCallback = new LoaderCallback() {

        @Override
        public Object loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException {
            final InputStream overdueConfigStream = new ByteArrayInputStream(overdueConfigXML.getBytes());
            final URI uri;
            try {
                uri = new URI("/overdueConfig");
                final DefaultOverdueConfig overdueConfig = XMLLoader.getObjectFromStream(uri, overdueConfigStream, DefaultOverdueConfig.class);
                return overdueConfig;
            } catch (final Exception e) {
                throw new OverdueApiException(ErrorCode.OVERDUE_INVALID_FOR_TENANT, "Problem encountered loading overdue config ", e);
            }
        }
    };
    final Object[] args = new Object[1];
    args[0] = loaderCallback;
    final ObjectType irrelevant = null;
    final InternalTenantContext notUsed = null;
    return new CacheLoaderArgument(irrelevant, args, notUsed);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URI(java.net.URI) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) LoaderCallback(org.killbill.billing.util.cache.TenantOverdueConfigCacheLoader.LoaderCallback) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException) ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext)

Example 3 with DefaultOverdueConfig

use of org.killbill.billing.overdue.config.DefaultOverdueConfig in project killbill by killbill.

the class EhCacheOverdueConfigCache method loadDefaultOverdueConfig.

@Override
public void loadDefaultOverdueConfig(@Nullable final String configURI) throws OverdueApiException {
    boolean missingOrCorruptedDefaultConfig;
    try {
        if (configURI == null || configURI.isEmpty()) {
            missingOrCorruptedDefaultConfig = true;
        } else {
            final URI u = new URI(configURI);
            defaultOverdueConfig = XMLLoader.getObjectFromUri(u, DefaultOverdueConfig.class);
            missingOrCorruptedDefaultConfig = (defaultOverdueConfig == null);
        }
    } catch (final Exception e) {
        missingOrCorruptedDefaultConfig = true;
        log.warn("Exception loading default overdue config from " + configURI, e);
    }
    if (missingOrCorruptedDefaultConfig) {
        log.warn("Overdue system disabled: unable to load the overdue config from " + configURI);
    }
}
Also used : URI(java.net.URI) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException)

Example 4 with DefaultOverdueConfig

use of org.killbill.billing.overdue.config.DefaultOverdueConfig in project killbill by killbill.

the class DefaultOverdueApi method getOverdueStateFor.

@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);
}
Also used : OverdueStateSet(org.killbill.billing.overdue.config.api.OverdueStateSet) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) BlockingState(org.killbill.billing.entitlement.api.BlockingState) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig)

Example 5 with DefaultOverdueConfig

use of org.killbill.billing.overdue.config.DefaultOverdueConfig in project killbill by killbill.

the class TestOverdueBase method beforeMethod.

@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
    super.beforeMethod();
    final String configXml = getOverdueConfig();
    final InputStream is = new ByteArrayInputStream(configXml.getBytes());
    final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
    overdueConfigCache.loadDefaultOverdueConfig(config);
    productName = "Shotgun";
    term = BillingPeriod.MONTHLY;
    paymentPlugin.clear();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

DefaultOverdueConfig (org.killbill.billing.overdue.config.DefaultOverdueConfig)14 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Test (org.testng.annotations.Test)9 InputStream (java.io.InputStream)8 Account (org.killbill.billing.account.api.Account)5 Invoice (org.killbill.billing.invoice.api.Invoice)5 BigDecimal (java.math.BigDecimal)3 URI (java.net.URI)3 LocalDate (org.joda.time.LocalDate)3 AccountData (org.killbill.billing.account.api.AccountData)3 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)3 OverdueState (org.killbill.billing.overdue.api.OverdueState)3 Payment (org.killbill.billing.payment.api.Payment)3 DateTime (org.joda.time.DateTime)2 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 OverdueApiException (org.killbill.billing.overdue.api.OverdueApiException)2 OverdueStateSet (org.killbill.billing.overdue.config.api.OverdueStateSet)2 ObjectType (org.killbill.billing.ObjectType)1 ImmutableAccountData (org.killbill.billing.account.api.ImmutableAccountData)1 BlockingState (org.killbill.billing.entitlement.api.BlockingState)1