Search in sources :

Example 36 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestEntitlementUtils method doCheckFutureBlockingStatesToCancel.

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(), EntitlementService.ENTITLEMENT_SERVICE_NAME);
        Assert.assertEquals(blockingState.getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED);
    }
}
Also used : BlockingState(org.killbill.billing.entitlement.api.BlockingState)

Example 37 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestBlockingApi method testApi.

@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);
}
Also used : DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 38 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestBlockingApi method testApiHistory.

@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(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);
}
Also used : Account(org.killbill.billing.account.api.Account) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 39 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestBlockingApi method testBlockingAcrossTypes.

@Test(groups = "slow")
public void testBlockingAcrossTypes() throws Exception {
    final String stateNameBlock = "stateBlock";
    final String stateNameUnBlock = "stateUnBlock";
    final String service = "SVC_BLOC_TYPES";
    final boolean blockChange = false;
    final boolean blockEntitlement = true;
    final boolean blockBilling = false;
    final Account account = createAccount(getAccountData(7));
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, stateNameBlock, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
    subscriptionApi.addBlockingState(state1, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    Entitlement baseEntitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    assertEquals(baseEntitlement.getState(), EntitlementState.BLOCKED);
    // Add blocking at bundle level.
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state2 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, stateNameBlock, service, blockChange, blockEntitlement, blockBilling, null);
    subscriptionApi.addBlockingState(state2, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
    assertEquals(baseEntitlement.getState(), EntitlementState.BLOCKED);
    // Remove blocking at account level
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state3 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, stateNameUnBlock, service, false, false, false, clock.getUTCNow());
    subscriptionApi.addBlockingState(state3, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
    assertEquals(baseEntitlement.getState(), EntitlementState.BLOCKED);
    // Remove blocking at bundle level.
    clock.addDays(1);
    testListener.pushExpectedEvent(NextEvent.BLOCK);
    final BlockingState state4 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, stateNameUnBlock, service, false, false, false, null);
    subscriptionApi.addBlockingState(state4, null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
    assertEquals(baseEntitlement.getState(), EntitlementState.ACTIVE);
    final List<BlockingState> blockingAll = blockingInternalApi.getBlockingAllForAccount(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(), 4);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) Entitlement(org.killbill.billing.entitlement.api.Entitlement) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 40 with BlockingState

use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.

the class TestBlockingChecker method setStateSubscription.

private void setStateSubscription(final boolean bC, final boolean bE, final boolean bB) {
    final BlockingState subscriptionState = new DefaultBlockingState(subscription.getId(), BlockingStateType.SUBSCRIPTION, "state", "test-service", bC, bE, bB, clock.getUTCNow());
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(subscriptionState, Optional.<UUID>of(subscription.getBundleId())), internalCallContext);
}
Also used : DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState)

Aggregations

BlockingState (org.killbill.billing.entitlement.api.BlockingState)46 UUID (java.util.UUID)24 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)22 Test (org.testng.annotations.Test)15 DateTime (org.joda.time.DateTime)13 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)6 LocalDate (org.joda.time.LocalDate)5 ImmutableList (com.google.common.collect.ImmutableList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Account (org.killbill.billing.account.api.Account)4 BillingEvent (org.killbill.billing.junction.BillingEvent)4 Optional (com.google.common.base.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 TreeSet (java.util.TreeSet)3 AccountApiException (org.killbill.billing.account.api.AccountApiException)3 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)3 BlockingStateType (org.killbill.billing.entitlement.api.BlockingStateType)3