use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.
the class TestBlockingChecker method setStateAccount.
private void setStateAccount(final boolean bC, final boolean bE, final boolean bB) {
final BlockingState accountState = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state", "test-service", bC, bE, bB, clock.getUTCNow());
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(accountState, Optional.<UUID>absent()), internalCallContext);
}
use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.
the class TestBlockingDao method testWithMultipleAccountBlockingStates.
@Test(groups = "slow", description = "Check BlockingStateDao for a subscription with events at all level (subscription, bundle, account)")
public void testWithMultipleAccountBlockingStates() throws AccountApiException {
final UUID accountId = 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(accountId, 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);
final UUID bundleId = UUID.randomUUID();
testListener.pushExpectedEvent(NextEvent.BLOCK);
final String overdueStateName2 = "NoReallyThisCantGoOn";
final BlockingState state2 = new DefaultBlockingState(bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, overdueStateName2, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(state2, Optional.<UUID>absent()), internalCallContext);
assertListenerStatus();
clock.addDays(1);
final UUID subscriptionId = UUID.randomUUID();
testListener.pushExpectedEvent(NextEvent.BLOCK);
final String overdueStateName3 = "OhBoy!";
final BlockingState state3 = new DefaultBlockingState(subscriptionId, BlockingStateType.SUBSCRIPTION, overdueStateName3, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(state3, Optional.<UUID>absent()), internalCallContext);
assertListenerStatus();
clock.addDays(1);
// Add a blocking state for a different subscription as well but for the same account
final UUID subscriptionId2 = UUID.randomUUID();
testListener.pushExpectedEvent(NextEvent.BLOCK);
final BlockingState state4 = new DefaultBlockingState(subscriptionId2, BlockingStateType.SUBSCRIPTION, overdueStateName3, service, blockChange, blockEntitlement, blockBilling, clock.getUTCNow());
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(state4, Optional.<UUID>absent()), internalCallContext);
assertListenerStatus();
Assert.assertEquals(blockingStateDao.getBlockingStateForService(accountId, BlockingStateType.ACCOUNT, service, internalCallContext).getStateName(), state1.getStateName());
final List<BlockingState> states = blockingStateDao.getBlockingAllForAccountRecordId(catalog, internalCallContext);
Assert.assertEquals(states.size(), 4);
Assert.assertEquals(states.get(0).getStateName(), overdueStateName);
Assert.assertEquals(states.get(1).getStateName(), overdueStateName2);
Assert.assertEquals(states.get(2).getStateName(), overdueStateName3);
final List<BlockingState> states2 = blockingStateDao.getByBlockingIds(ImmutableList.of(accountId, bundleId, subscriptionId), internalCallContext);
Assert.assertEquals(states2.size(), 3);
}
use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.
the class TestDefaultSubscriptionApi method testBlockedEntitlementChange.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/452")
public void testBlockedEntitlementChange() throws AccountApiException, EntitlementApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
// Create entitlement and check each field
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
clock.addDays(1);
clock.addDeltaFromReality(5000);
assertListenerStatus();
testListener.pushExpectedEvent(NextEvent.BLOCK);
final BlockingState state = new DefaultBlockingState(entitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "MY_BLOCK", "test", true, false, false, null);
subscriptionApi.addBlockingState(state, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
try {
final PlanPhaseSpecifier spec1 = new PlanPhaseSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
entitlement.changePlan(new DefaultEntitlementSpecifier(spec1), ImmutableList.<PluginProperty>of(), callContext);
fail();
} catch (final EntitlementApiException e) {
assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode());
final Entitlement latestEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
assertEquals(latestEntitlement.getLastActivePlan().getProduct().getName(), "Shotgun");
}
// If a LocalDate is passed, it will align with the reference time (2013-08-08T00:00:00.000Z), which will fall before the blocking state above (+5s added above)
testListener.pushExpectedEvent(NextEvent.CHANGE);
final PlanPhaseSpecifier spec2 = new PlanPhaseSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), clock.getUTCToday(), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Entitlement latestEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
assertEquals(latestEntitlement.getLastActivePlan().getProduct().getName(), "Assault-Rifle");
}
use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.
the class TestDefaultSubscriptionApi method testBlockBundle.
@Test(groups = "slow")
public void testBlockBundle() throws AccountApiException, EntitlementApiException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null);
// Create entitlement and check each field
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext);
clock.addDays(5);
testListener.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState state1 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "BLOCK", "foo", true, true, true, null);
subscriptionApi.addBlockingState(state1, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
List<Entitlement> bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(baseEntitlement.getBundleId(), callContext);
assertEquals(bundleEntitlements.size(), 1);
assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.BLOCKED);
final BlockingState blockingState = blockingInternalApi.getBlockingStateForService(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "foo", internalCallContext);
assertTrue(blockingState.isBlockBilling());
assertTrue(blockingState.isBlockChange());
assertTrue(blockingState.isBlockEntitlement());
// Check unblocking on another service will not bring the state back to ACTIVE
clock.addDays(1);
testListener.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState state2 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "UNBLOCK", "bar", false, false, false, null);
subscriptionApi.addBlockingState(state2, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(baseEntitlement.getBundleId(), callContext);
assertEquals(bundleEntitlements.size(), 1);
assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.BLOCKED);
testListener.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState state3 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "UNBLOCK", "foo", false, false, false, null);
subscriptionApi.addBlockingState(state3, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(baseEntitlement.getBundleId(), callContext);
assertEquals(bundleEntitlements.size(), 1);
assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.ACTIVE);
blockingInternalApi.getBlockingStateForService(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "foo", internalCallContext);
clock.addDays(1);
testListener.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState state4 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "BLOCK", "foo", true, true, true, null);
subscriptionApi.addBlockingState(state4, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(baseEntitlement.getBundleId(), callContext);
assertEquals(bundleEntitlements.size(), 1);
assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.BLOCKED);
// Same day but happened after so should take precedence
testListener.pushExpectedEvents(NextEvent.BLOCK);
final BlockingState state5 = new DefaultBlockingState(baseEntitlement.getBundleId(), BlockingStateType.SUBSCRIPTION_BUNDLE, "UNBLOCK", "foo", false, false, false, null);
subscriptionApi.addBlockingState(state5, null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(baseEntitlement.getBundleId(), callContext);
assertEquals(bundleEntitlements.size(), 1);
assertEquals(bundleEntitlements.get(0).getState(), EntitlementState.ACTIVE);
}
use of org.killbill.billing.junction.DefaultBlockingState in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method testOneEntitlementWithBlockingStatesSubscriptionImpl.
private void testOneEntitlementWithBlockingStatesSubscriptionImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
clock.setDay(new LocalDate(2013, 1, 1));
final DateTimeZone accountTimeZone = DateTimeZone.UTC;
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final String externalKey = "foo";
final UUID entitlementId = UUID.randomUUID();
final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
allTransitions.add(tr1);
if (!regressionFlagForOlderVersionThan_0_17_X) {
final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStates.add(bsCreate);
}
effectiveDate = effectiveDate.plusDays(30);
clock.addDays(30);
final SubscriptionBaseTransition tr2 = createTransition(entitlementId, EventType.PHASE, null, effectiveDate, clock.getUTCNow(), "trial", "phase");
allTransitions.add(tr2);
effectiveDate = effectiveDate.plusDays(5);
clock.addDays(5);
final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStates.add(bs1);
effectiveDate = effectiveDate.plusDays(15);
clock.addDays(15);
final SubscriptionBaseTransition tr3 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "phase", null);
allTransitions.add(tr3);
final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 1L);
blockingStates.add(bs2);
final List<Entitlement> entitlements = new ArrayList<Entitlement>();
final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
entitlements.add(entitlement);
final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
assertEquals(events.size(), 6);
assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE);
assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
assertEquals(events.get(4).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
assertEquals(events.get(5).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
assertEquals(events.get(0).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(2).getServiceName(), EntitlementOrderingBase.ENT_BILLING_SERVICE_NAME);
assertEquals(events.get(3).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
assertEquals(events.get(4).getServiceName(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName());
assertEquals(events.get(5).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertNull(events.get(0).getPrevPhase());
assertNull(events.get(1).getPrevPhase());
assertEquals(events.get(1).getNextPhase().getName(), "trial");
assertEquals(events.get(2).getPrevPhase().getName(), "trial");
assertEquals(events.get(2).getNextPhase().getName(), "phase");
assertEquals(events.get(3).getPrevPhase().getName(), "phase");
assertEquals(events.get(3).getNextPhase().getName(), "phase");
assertEquals(events.get(4).getPrevPhase().getName(), "phase");
assertNull(events.get(4).getNextPhase());
assertEquals(events.get(5).getPrevPhase().getName(), "phase");
assertNull(events.get(5).getNextPhase());
}
Aggregations