protected Response addBlockingState(final BlockingStateJson json, final UUID accountId, final UUID blockableId, final BlockingStateType type, final String requestedDate, final List<String> pluginPropertiesString, final String createdBy, final String reason, final String comment, final HttpServletRequest request, @Nullable final UriInfo uriInfo) throws SubscriptionApiException, EntitlementApiException, AccountApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request); final boolean isBlockBilling = (json.isBlockBilling() != null && json.isBlockBilling()); final boolean isBlockEntitlement = (json.isBlockEntitlement() != null && json.isBlockEntitlement()); final boolean isBlockChange = (json.isBlockChange() != null && json.isBlockChange()); final LocalDate resolvedRequestedDate = toLocalDate(requestedDate); final BlockingState input = new DefaultBlockingState(blockableId, type, json.getStateName(), json.getService(), isBlockChange, isBlockEntitlement, isBlockBilling, null); subscriptionApi.addBlockingState(input, resolvedRequestedDate, pluginProperties, callContext); return uriInfo != null ? uriBuilder.buildResponse(uriInfo, AccountResource.class, "getBlockingStates", accountId, ImmutableMap.<String, String>of(QUERY_BLOCKING_STATE_TYPES, type.name()) , request) : null; }
subscriptionApi.addBlockingState(blockingState, new LocalDate(2016, 5, 1), ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(unblockingState, new LocalDate(2016, 5, 16), ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
@Test(groups = "slow") public void testBlockingStatesV2() throws Exception { final DateTime initialDate = new DateTime(2017, 3, 1, 0, 1, 35, 0, DateTimeZone.UTC); clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis()); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0)); assertNotNull(account); final BlockingState blockingState1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state1", "Service", false, false, true, null); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null); // Unlike the previous scenario, we create the subscription and set the blocking state at the same time busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE, NextEvent.BLOCK); subscriptionApi.addBlockingState(blockingState1, null, ImmutableList.<PluginProperty>of(), callContext); entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addMonths(1); busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); final BlockingState blockingState2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state2", "Service", false, false, false, null); subscriptionApi.addBlockingState(blockingState2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); }
@Test(groups = "slow") public void testBlockingStatesV1() throws Exception { final DateTime initialDate = new DateTime(2017, 3, 1, 0, 1, 35, 0, DateTimeZone.UTC); clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis()); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0)); assertNotNull(account); busHandler.pushExpectedEvents(NextEvent.BLOCK); final BlockingState blockingState1 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state1", "Service", false, false, true, null); subscriptionApi.addBlockingState(blockingState1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addDays(1); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null); busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addMonths(1); busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); final BlockingState blockingState2 = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "state2", "Service", false, false, false, null); subscriptionApi.addBlockingState(blockingState2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); clock.addMonths(1); assertListenerStatus(); }
subscriptionApi.addBlockingState(state1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); 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(); subscriptionApi.addBlockingState(state3, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(state4, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(state5, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
subscriptionApi.addBlockingState(state1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(state2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(state3, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(state4, internalCallContext.toLocalDate(futureEffectiveDate), ImmutableList.<PluginProperty>of(), callContext);
subscriptionApi.addBlockingState(blockChangeAccount, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
subscriptionApi.addBlockingState(state1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); 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(); 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(); 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();
subscriptionApi.addBlockingState(blockingState1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(blockingState2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
@Test(groups = "slow") public void testCreateAOSubscriptionOnFutureBlockedChangeAcount() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2017, 5, 1); clock.setDay(initialDate); final Account account = createAccount(getAccountData(1)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("shotgun-monthly", null); testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE); final UUID baseEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "xyzqe", null, initialDate.minusDays(3), false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext); // Create future BlockingState final LocalDate blockingChange = initialDate.plusDays(3); final BlockingState blockChangeAccount = new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "State1", "Service1", true, false, false, null); subscriptionApi.addBlockingState(blockChangeAccount, blockingChange, ImmutableList.<PluginProperty>of(), callContext); // Create ADD_ON in the future as well try { final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), blockingChange, null, false, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); } catch (final EntitlementApiException e) { assertEquals(e.getCode(), ErrorCode.BLOCK_BLOCKED_ACTION.getCode()); } // Create ADD_ON now (prior future BlockingState) final PlanPhaseSpecifier addOnSpec = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); entitlementApi.addEntitlement(entitlement.getBundleId(), new DefaultEntitlementSpecifier(addOnSpec), null, null, false, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); }
subscriptionApi.addBlockingState(blockChangeAccount, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
subscriptionApi.addBlockingState(blockingState1, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); subscriptionApi.addBlockingState(blockingState2, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
subscriptionApi.addBlockingState(state, null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();