Search in sources :

Example 1 with OverdueState

use of org.killbill.billing.overdue.api.OverdueState 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 OverdueState

use of org.killbill.billing.overdue.api.OverdueState in project killbill by killbill.

the class OverdueWrapper method refreshWithLock.

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, clock.getToday(billingState.getAccountTimeZone()));
    overdueStateApplicator.apply(effectiveDate, overdueStateSet, billingState, overdueable, currentOverdueState, nextOverdueState, context);
    return nextOverdueState;
}
Also used : BlockingState(org.killbill.billing.entitlement.api.BlockingState) BillingState(org.killbill.billing.overdue.config.api.BillingState) OverdueState(org.killbill.billing.overdue.api.OverdueState)

Example 3 with OverdueState

use of org.killbill.billing.overdue.api.OverdueState in project killbill by killbill.

the class OverdueWrapper method clearWithLock.

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);
}
Also used : BlockingState(org.killbill.billing.entitlement.api.BlockingState) OverdueState(org.killbill.billing.overdue.api.OverdueState)

Example 4 with OverdueState

use of org.killbill.billing.overdue.api.OverdueState in project killbill by killbill.

the class TestOverdueStateApplicator method testApplicator.

@Test(groups = "slow")
public void testApplicator() throws Exception {
    final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
    final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
    final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
    Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
    final OverdueStateSet overdueStateSet = config.getOverdueStatesAccount();
    final OverdueState clearState = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
    OverdueState state;
    state = config.getOverdueStatesAccount().findState("OD1");
    applicator.apply(clock.getUTCNow(), overdueStateSet, null, account, clearState, state, internalCallContext);
    testOverdueHelper.checkStateApplied(state);
    checkBussEvent("OD1");
    state = config.getOverdueStatesAccount().findState("OD2");
    applicator.apply(clock.getUTCNow(), overdueStateSet, null, account, clearState, state, internalCallContext);
    testOverdueHelper.checkStateApplied(state);
    checkBussEvent("OD2");
    state = config.getOverdueStatesAccount().findState("OD3");
    applicator.apply(clock.getUTCNow(), overdueStateSet, null, account, clearState, state, internalCallContext);
    testOverdueHelper.checkStateApplied(state);
    checkBussEvent("OD3");
}
Also used : ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) OverdueStateSet(org.killbill.billing.overdue.config.api.OverdueStateSet) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) OverdueState(org.killbill.billing.overdue.api.OverdueState) Test(org.testng.annotations.Test)

Example 5 with OverdueState

use of org.killbill.billing.overdue.api.OverdueState in project killbill by killbill.

the class TestOverdueWrapper method testWrapperNoConfig.

@Test(groups = "slow")
public void testWrapperNoConfig() throws Exception {
    final Account account;
    final OverdueWrapper wrapper;
    final OverdueState state;
    final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
    final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
    state = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
    account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
    wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
    final OverdueState result = wrapper.refresh(clock.getUTCNow(), internalCallContext);
    Assert.assertEquals(result.getName(), state.getName());
    Assert.assertEquals(result.isBlockChanges(), state.isBlockChanges());
    Assert.assertEquals(result.isDisableEntitlementAndChangesBlocked(), state.isDisableEntitlementAndChangesBlocked());
}
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) OverdueState(org.killbill.billing.overdue.api.OverdueState) Test(org.testng.annotations.Test)

Aggregations

OverdueState (org.killbill.billing.overdue.api.OverdueState)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Account (org.killbill.billing.account.api.Account)3 DefaultOverdueConfig (org.killbill.billing.overdue.config.DefaultOverdueConfig)3 Test (org.testng.annotations.Test)3 BlockingState (org.killbill.billing.entitlement.api.BlockingState)2 MustacheException (com.samskivert.mustache.MustacheException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Period (org.joda.time.Period)1 AccountApiException (org.killbill.billing.account.api.AccountApiException)1 ImmutableAccountData (org.killbill.billing.account.api.ImmutableAccountData)1 BlockingApiException (org.killbill.billing.entitlement.api.BlockingApiException)1 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)1 OverdueChangeInternalEvent (org.killbill.billing.events.OverdueChangeInternalEvent)1