@Override public UUID getEntitlementId() { return subscription.getId(); }
@Override public BlockingState apply(final SubscriptionBase input) { return new DefaultBlockingState(input.getId(), BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, EntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, false, blockingStateEffectiveDate); } });
private SubscriptionBase subscription(final UUID id) { final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getId()).thenReturn(id); return subscription; } }
private SubscriptionBase createSubscription(final UUID subscriptionId, final UUID bundleId) { final SubscriptionBase sub = Mockito.mock(SubscriptionBase.class); Mockito.when(sub.getId()).thenReturn(subscriptionId); Mockito.when(sub.getBundleId()).thenReturn(bundleId); return sub; }
public SubscriptionBase createSubscription() throws SubscriptionBaseApiException { UUID uuid = UUID.randomUUID(); final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getId()).thenReturn(uuid); Mockito.when(subscriptionApi.getSubscriptionFromId(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscription); return subscription; }
private SubscriptionBase getZombieSubscription() { final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getId()).thenReturn(UUID.randomUUID()); Mockito.when(subscription.getBundleId()).thenReturn(UUID.randomUUID()); return subscription; }
@Override public SubscriptionBase getSubscriptionFromId(final UUID subscriptionId, final InternalTenantContext context) { for (final SubscriptionBase cur : subscriptions) { if (cur.getId().equals(subscriptionId)) { return buildSubscription((DefaultSubscriptionBase) cur, context); } } return null; }
@Override public void updateChargedThroughDate(final DefaultSubscriptionBase subscription, final InternalCallContext context) { boolean found = false; final Iterator<SubscriptionBase> it = subscriptions.iterator(); while (it.hasNext()) { final SubscriptionBase cur = it.next(); if (cur.getId().equals(subscription.getId())) { found = true; it.remove(); break; } } if (found) { subscriptions.add(subscription); } }
public EventsStream buildForBaseSubscription(final UUID bundleId, final TenantContext tenantContext) throws EntitlementApiException { final SubscriptionBase baseSubscription; try { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext); baseSubscription = subscriptionInternalApi.getBaseSubscription(bundleId, internalTenantContext); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } return buildForEntitlement(baseSubscription.getId(), tenantContext); }
@Override public boolean apply(final BlockingState input) { return !input.getEffectiveDate().isBefore(utcNow) && typeList.contains(input.getStateName()) && ( // ... for that subscription BlockingStateType.SUBSCRIPTION.equals(input.getType()) && input.getBlockedId().equals(subscription.getId()) || // ... for the associated base subscription BlockingStateType.SUBSCRIPTION.equals(input.getType()) && input.getBlockedId().equals(baseSubscription.getId()) || // ... for that bundle BlockingStateType.SUBSCRIPTION_BUNDLE.equals(input.getType()) && input.getBlockedId().equals(bundle.getId()) || // ... for that account BlockingStateType.ACCOUNT.equals(input.getType()) && input.getBlockedId().equals(account.getId()) ); } });
private void computeEntitlementBlockingStates() { subscriptionEntitlementStates = filterBlockingStatesForEntitlementService(BlockingStateType.SUBSCRIPTION, subscription.getId()); bundleEntitlementStates = filterBlockingStatesForEntitlementService(BlockingStateType.SUBSCRIPTION_BUNDLE, subscription.getBundleId()); accountEntitlementStates = filterBlockingStatesForEntitlementService(BlockingStateType.ACCOUNT, account.getId()); }
@Override public boolean apply(final SubscriptionBase subscription) { return ProductCategory.ADD_ON.equals(subscription.getCategory()) && // Check the entitlement for that add-on hasn't been cancelled yet getEntitlementCancellationEvent(subscription.getId()) == null && ( // Base subscription cancelled baseTransitionTriggerNextProduct == null || ( // Change plan - check which add-ons to cancel includedAddonsForProduct.contains(subscription.getLastActivePlan().getProduct().getName()) || !availableAddonsForProduct.contains(subscription.getLastActivePlan().getProduct().getName()) ) ); } });
@Override public int compareTo(final BillingEvent e1) { if (!getSubscription().getId().equals(e1.getSubscription().getId())) { // First order by subscription return getSubscription().getId().compareTo(e1.getSubscription().getId()); } else { // subscriptions are the same if (!getEffectiveDate().equals(e1.getEffectiveDate())) { // Secondly order by date return getEffectiveDate().compareTo(e1.getEffectiveDate()); } else { // dates and subscriptions are the same return getTotalOrdering().compareTo(e1.getTotalOrdering()); } } } };
@Test(groups = "fast") public void testChangeSubscriptionWithPolicy() throws Exception { final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME); try { subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, BillingActionPolicy.ILLEGAL, callContext); Assert.fail(); } catch (SubscriptionBaseError error) { assertTrue(true); assertEquals(subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext).getCurrentPlan().getBillingPeriod(), BillingPeriod.ANNUAL); } // Assume the call takes less than a second assertEquals(DefaultClock.truncateMs(subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, BillingActionPolicy.IMMEDIATE, callContext)), DefaultClock.truncateMs(clock.getUTCNow())); assertEquals(subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext).getCurrentPlan().getBillingPeriod(), BillingPeriod.MONTHLY); }
private DefaultBlockingAggregator getBlockedStateSubscription(final SubscriptionBase subscription, final InternalTenantContext context) throws BlockingApiException { final DefaultBlockingAggregator result = new DefaultBlockingAggregator(); if (subscription != null) { final DefaultBlockingAggregator subscriptionState = getBlockedStateForId(subscription.getId(), BlockingStateType.SUBSCRIPTION, context); if (subscriptionState != null) { result.or(subscriptionState); } if (subscription.getBundleId() != null) { // Recursive call to also fetch account state result.or(getBlockedStateBundleId(subscription.getBundleId(), context)); } } return result; }
@Override public void doTest() throws SubscriptionBaseRepairException { final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final DeletedEvent de = testUtil.createDeletedEvent(UUID.randomUUID()); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_NON_EXISTENT_DELETE_EVENT);
@Override public List<EntitlementAOStatusDryRun> getDryRunStatusForChange(final UUID bundleId, final String targetProductName, final LocalDate effectiveDate, final TenantContext context) throws EntitlementApiException { final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(context); try { final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, internalContext); final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, internalContext); final InternalTenantContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalTenantContext(bundle.getAccountId(), context); final DateTime requestedDate = dateHelper.fromLocalDateAndReferenceTime(effectiveDate, baseSubscription.getStartDate(), contextWithValidAccountRecordId); return subscriptionBaseInternalApi.getDryRunChangePlanStatus(baseSubscription.getId(), targetProductName, requestedDate, contextWithValidAccountRecordId); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } }
@Test(groups = "fast") public void testAutoInvoiceOffAccount() throws Exception { final MockBillingEventSet events = new MockBillingEventSet(); events.setAccountInvoiceOff(true); final SubscriptionBase sub = createSubscription(); final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1); final Plan plan = new MockPlan(); final BigDecimal rate1 = TEN; final PlanPhase phase = createMockMonthlyPlanPhase(rate1); final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 1); events.add(event); final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3); final UUID accountId = UUID.randomUUID(); final Invoice invoice = generator.generateInvoice(accountId, events, null, targetDate, Currency.USD); assertNull(invoice); }
@Override public void doTest() throws SubscriptionBaseRepairException { // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.<DeletedEvent>emptyList(), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING);