@Test(groups = "slow") public void testCancelWithEntitlementDate() throws AccountApiException, EntitlementApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier planPhaseSpecifier = 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(planPhaseSpecifier), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE); clock.addDays(5); testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK); entitlement.cancelEntitlementWithDate(null, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement2.getState(), EntitlementState.CANCELLED); assertEquals(entitlement2.getEffectiveEndDate(), clock.getUTCToday()); assertEquals(entitlement2.getSourceType(), EntitlementSourceType.NATIVE); }
@Override public Response doOperation(final CallContext ctx) throws EntitlementApiException, SubscriptionApiException { final Entitlement current = entitlementApi.getEntitlementForId(subscriptionId, ctx); final LocalDate inputLocalDate = toLocalDate(requestedDate); final Entitlement newEntitlement; if (billingPolicy == null && entitlementPolicy == null) { newEntitlement = current.cancelEntitlementWithDate(inputLocalDate, useRequestedDateForBilling, pluginProperties, ctx); } else if (billingPolicy == null && entitlementPolicy != null) { newEntitlement = current.cancelEntitlementWithPolicy(entitlementPolicy, pluginProperties, ctx); } else if (billingPolicy != null && entitlementPolicy == null) { newEntitlement = current.cancelEntitlementWithDateOverrideBillingPolicy(inputLocalDate, billingPolicy, pluginProperties, ctx); } else { newEntitlement = current.cancelEntitlementWithPolicyOverrideBillingPolicy(entitlementPolicy, billingPolicy, pluginProperties, ctx); } final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(newEntitlement.getId(), ctx); final LocalDate nowInAccountTimeZone = new LocalDate(callContext.getCreatedDate(), subscription.getBillingEndDate().getChronology().getZone()); isImmediateOp = subscription.getBillingEndDate() != null && !subscription.getBillingEndDate().isAfter(nowInAccountTimeZone); return Response.status(Status.NO_CONTENT).build(); }
@Override public Response doOperation(final CallContext ctx) throws EntitlementApiException, AccountApiException { final Entitlement current = entitlementApi.getEntitlementForId(subscriptionId, callContext); final LocalDate inputLocalDate = toLocalDate(requestedDate); final Entitlement newEntitlement; final Account account = accountUserApi.getAccountById(current.getAccountId(), callContext); final PhaseType phaseType = entitlement.getPhaseType(); final PlanPhaseSpecifier planSpec = entitlement.getPlanName() != null ? new PlanPhaseSpecifier(entitlement.getPlanName(), phaseType) : new PlanPhaseSpecifier(entitlement.getProductName(), entitlement.getBillingPeriod(), entitlement.getPriceList(), phaseType); final List<PlanPhasePriceOverride> overrides = buildPlanPhasePriceOverrides(entitlement.getPriceOverrides(), account.getCurrency(), planSpec); if (requestedDate == null && billingPolicy == null) { newEntitlement = current.changePlan(new DefaultEntitlementSpecifier(planSpec, null, overrides), pluginProperties, ctx); } else if (billingPolicy == null) { newEntitlement = current.changePlanWithDate(new DefaultEntitlementSpecifier(planSpec, null, overrides), inputLocalDate, pluginProperties, ctx); } else { newEntitlement = current.changePlanOverrideBillingPolicy(new DefaultEntitlementSpecifier(planSpec, null, overrides), null, billingPolicy, pluginProperties, ctx); } isImmediateOp = newEntitlement.getLastActiveProduct().getName().equals(entitlement.getProductName()) && newEntitlement.getLastActivePlan().getRecurringBillingPeriod() == entitlement.getBillingPeriod() && newEntitlement.getLastActivePriceList().getName().equals(entitlement.getPriceList()); return Response.status(Status.NO_CONTENT).build(); }
@Override public Response doResponseOk(final List<UUID> entitlementIds) { if (responseObject == ObjectType.SUBSCRIPTION) { return uriBuilder.buildResponse(uriInfo, SubscriptionResource.class, "getSubscription", Iterables.getFirst(entitlementIds, null), request); } final Collection<String> bundleIds = new LinkedHashSet<String>(); try { for (final Entitlement entitlement : entitlementApi.getAllEntitlementsForAccountId(account.getId(), callContext)) { if (entitlementIds.contains(entitlement.getId())) { bundleIds.add(entitlement.getBundleId().toString()); } } } catch (final EntitlementApiException e) { return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } if (responseObject == ObjectType.ACCOUNT) { return uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccountBundles", account.getId(), buildQueryParams(bundleIds), request); } else if (responseObject == ObjectType.BUNDLE) { return uriBuilder.buildResponse(uriInfo, BundleResource.class, "getBundle", Iterables.getFirst(bundleIds, null), request); } else { throw new IllegalStateException("Unexpected input responseObject " + responseObject); } } };
@Override public Entitlement apply(@Nullable final Void dontcare) { try { // Need to fetch again to get latest CTD updated from the system Entitlement refreshedEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); refreshedEntitlement = refreshedEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(entitlementActionPolicy, billingActionPolicy, ImmutableList.<PluginProperty>of(), callContext); return refreshedEntitlement; } catch (final EntitlementApiException e) { fail(e.getMessage()); return null; } } }, events);
final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getAccountId(), account.getId()); assertEquals(entitlement.getExternalKey(), account.getExternalKey()); assertEquals(entitlement.getEffectiveStartDate(), initialDate); assertNull(entitlement.getEffectiveEndDate()); assertEquals(entitlement.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(entitlement.getLastActiveProduct().getName(), "Shotgun"); assertEquals(entitlement.getLastActivePhase().getName(), "shotgun-monthly-evergreen"); assertEquals(entitlement.getLastActivePlan().getName(), "shotgun-monthly"); assertEquals(entitlement.getLastActiveProductCategory(), ProductCategory.BASE); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE); assertEquals(entitlement.getLastActivePlan().getName(), "shotgun-monthly"); assertEquals(entitlement.getLastActivePriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(entitlement.getLastActiveProduct().getName(), "Shotgun"); assertEquals(entitlement.getLastActiveProductCategory(), ProductCategory.BASE); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE); List<Entitlement> bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(entitlement.getBundleId(), callContext); assertEquals(bundleEntitlements.size(), 1);
assertEquals(createdEntitlement.getState(), EntitlementState.PENDING); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); assertEquals(createdEntitlement.getLastActiveProduct().getName(), "Shotgun"); assertEquals(createdEntitlement.getLastActivePlan().getName(), "shotgun-annual"); assertEquals(createdEntitlement.getLastActiveProductCategory(), ProductCategory.BASE); assertListenerStatus(); createdEntitlement.cancelEntitlementWithDate(invalidCancelDate, true, null, callContext); Assert.fail("Should not succeed to cancel subscription prior startDate"); } catch (final EntitlementApiException e) { final Entitlement cancelledEntitlement = createdEntitlement.cancelEntitlementWithDate(futureDate, true, null, callContext); assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0); assertListenerStatus();
final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext); assertEquals(baseEntitlement.getAccountId(), account.getId()); assertEquals(baseEntitlement.getExternalKey(), account.getExternalKey()); assertEquals(baseEntitlement.getLastActiveProduct().getName(), "Knife"); assertEquals(baseEntitlement.getLastActivePlan().getName(), "knife-monthly-notrial"); assertEquals(baseEntitlement.getLastActiveProductCategory(), ProductCategory.STANDALONE); final UUID anotherStandaloneEntitlementId = entitlementApi.addEntitlement(baseEntitlement.getBundleId(), new DefaultEntitlementSpecifier(spec1), initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement anotherStandaloneEntitlement = entitlementApi.getEntitlementForId(anotherStandaloneEntitlementId, callContext); assertEquals(anotherStandaloneEntitlement.getAccountId(), account.getId()); assertEquals(anotherStandaloneEntitlement.getExternalKey(), account.getExternalKey()); assertEquals(anotherStandaloneEntitlement.getBundleId(), baseEntitlement.getBundleId()); assertEquals(anotherStandaloneEntitlement.getLastActivePriceList().getName(), "notrial"); assertEquals(anotherStandaloneEntitlement.getLastActiveProduct().getName(), "Knife"); assertEquals(anotherStandaloneEntitlement.getLastActivePlan().getName(), "knife-monthly-notrial"); assertEquals(anotherStandaloneEntitlement.getLastActiveProductCategory(), ProductCategory.STANDALONE); List<Entitlement> bundleEntitlements = entitlementApi.getAllEntitlementsForBundle(anotherStandaloneEntitlement.getBundleId(), callContext); assertEquals(bundleEntitlements.size(), 2);
@Test(groups = "slow") public void testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange() throws AccountApiException, EntitlementApiException, SubscriptionApiException, InterruptedException { 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); // Immediate change during trial testListener.pushExpectedEvent(NextEvent.CREATE); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); entitlement.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); // Verify the change is immediate final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement2.getLastActivePlan().getProduct().getName(), "Assault-Rifle"); testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK); final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithPolicy(EntitlementActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertEquals(cancelledEntitlement.getState(), EntitlementState.CANCELLED); assertEquals(cancelledEntitlement.getEffectiveEndDate(), initialDate); // Entitlement started in trial on 2013-08-07, which is when we want the billing cancellation date to occur final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(entitlement.getBaseEntitlementId(), callContext); assertEquals(subscription.getBillingEndDate(), new LocalDate(2013, 8, 7)); }
@Test(groups = "slow") public void testCancelFutureSubscription() throws AccountApiException, EntitlementApiException, SubscriptionApiException { 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); final LocalDate futureDate = new LocalDate(2013, 9, 1); // No CREATE event as this is set in the future final UUID createdEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), futureDate, futureDate, false, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement createdEntitlement = entitlementApi.getEntitlementForId(createdEntitlementId, callContext); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(createdEntitlement.getId(), callContext); assertEquals(baseEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(baseEntitlement.getEffectiveEndDate(), null); final Entitlement cancelledEntitlement = baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, null, callContext); assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0); final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(cancelledEntitlement.getId(), callContext); assertEquals(subscription.getEffectiveEndDate().compareTo(futureDate), 0); assertListenerStatus(); }
@Test(groups = "slow") public void testCancelWithEntitlementPolicyEOTAndNOCTD() throws AccountApiException, EntitlementApiException, SubscriptionApiException { 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); testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK); final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithPolicy(EntitlementActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertEquals(cancelledEntitlement.getState(), EntitlementState.CANCELLED); assertEquals(cancelledEntitlement.getEffectiveEndDate(), initialDate); // Entitlement started in trial on 2013-08-07, which is when we want the billing cancellation to occur final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(entitlement.getBaseEntitlementId(), callContext); assertEquals(subscription.getBillingEndDate(), new LocalDate(2013, 8, 7)); }
assertEquals(createdEntitlement.getState(), Entitlement.EntitlementState.PENDING); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); assertListenerStatus(); final Invoice dryRunInvoice1 = invoiceUserApi.triggerDryRunInvoiceGeneration(createdEntitlement.getAccountId(), futureDate, DRY_RUN_TARGET_DATE_ARG, callContext); assertEquals(dryRunInvoice1.getInvoiceItems().size(), 1); assertEquals(dryRunInvoice1.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.FIXED); SubscriptionEventType.CHANGE, createdEntitlement.getId(), createdEntitlement.getBundleId(), futureDate, BillingActionPolicy.IMMEDIATE); invoiceUserApi.triggerDryRunInvoiceGeneration(createdEntitlement.getAccountId(), futureDate.minusDays(1), dryRunSubscriptionActionArg, callContext); fail("Should fail to trigger dryRun invoice prior subscription starts"); } catch (final InvoiceApiException e) { final Invoice dryRunInvoice2 = invoiceUserApi.triggerDryRunInvoiceGeneration(createdEntitlement.getAccountId(), futureDate, dryRunSubscriptionActionArg, callContext); assertEquals(dryRunInvoice2.getInvoiceItems().size(), 1); assertEquals(dryRunInvoice2.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.FIXED); final Invoice realInvoice = invoiceUserApi.triggerInvoiceGeneration(createdEntitlement.getAccountId(), futureDate, callContext); assertListenerStatus();
assertEquals(bpEntitlement.getLastActivePhase().getPhaseType(), PhaseType.TRIAL); assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext).size(), 1); assertListenerStatus(); assertEquals(entitlementApi.getEntitlementForId(bpEntitlement.getId(), callContext).getLastActivePhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext).size(), 2); bpEntitlement = bpEntitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), clock.getUTCToday(), ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertEquals(entitlementApi.getEntitlementForId(bpEntitlement.getId(), callContext).getLastActivePhase().getPhaseType(), PhaseType.DISCOUNT); assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext).size(), 3); bpEntitlement = bpEntitlement.cancelEntitlementWithDate(new LocalDate("2016-05-01"), true, ImmutableList.<PluginProperty>of(), callContext); assertEquals(bpEntitlement.getState(), EntitlementState.ACTIVE); assertListenerStatus(); assertEquals(entitlementApi.getEntitlementForId(bpEntitlement.getId(), callContext).getLastActivePhase().getPhaseType(), PhaseType.EVERGREEN); bpEntitlement.uncancelEntitlement(ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
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(); 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"); 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");
assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getAccountId(), account.getId()); assertEquals(entitlement.getExternalKey(), externalKey); assertEquals(entitlement.getEffectiveStartDate(), initialDate); assertNull(entitlement.getEffectiveEndDate()); assertEquals(activeBundle.getId(), entitlement.getBundleId()); entitlement.cancelEntitlementWithDate(new LocalDate(clock.getUTCNow(), account.getTimeZone()), true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertListenerStatus(); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement2Id, callContext); assertEquals(entitlement2.getAccountId(), account.getId()); assertEquals(entitlement2.getExternalKey(), externalKey);
assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.PENDING); entitlement.changePlan(new DefaultEntitlementSpecifier(spec2), ImmutableList.<PluginProperty>of(), callContext); fail("Changing plan immediately prior the subscription is active is not allowed"); } catch (EntitlementApiException e) { entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), startDate.minusDays(1), ImmutableList.<PluginProperty>of(), callContext); fail("Changing plan immediately prior the subscription is active is not allowed"); } catch (EntitlementApiException e) { entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), startDate, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement1 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement1.getState(), EntitlementState.ACTIVE); assertEquals(entitlement1.getLastActiveProduct().getName(), "Pistol");
final PlanPhaseSpecifier spec1 = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID telescopicEntitlementId = entitlementApi.addEntitlement(baseEntitlement.getBundleId(), new DefaultEntitlementSpecifier(spec1), effectiveDateSpec1, effectiveDateSpec1, false, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement telescopicEntitlement = entitlementApi.getEntitlementForId(telescopicEntitlementId, callContext); entitlementApi.pause(baseEntitlement.getBundleId(), blockingStateDate, ImmutableList .<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement baseEntitlement2 = entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext); assertEquals(baseEntitlement2.getState(), EntitlementState.BLOCKED); final Entitlement telescopicEntitlement2 = entitlementApi.getEntitlementForId(telescopicEntitlement.getId(), callContext); assertEquals(telescopicEntitlement2.getState(), EntitlementState.BLOCKED); final List<Entitlement> bundleEntitlements2 = entitlementApi.getAllEntitlementsForBundle(telescopicEntitlement2.getBundleId(), callContext); assertEquals(bundleEntitlements2.size(), 2); for (final Entitlement cur : bundleEntitlements2) { assertEquals(cur.getState(), EntitlementState.BLOCKED); entitlementApi.addEntitlement(baseEntitlement.getBundleId(), new DefaultEntitlementSpecifier(spec3), blockingStateDate, effectiveDateSpec1, false, ImmutableList.<PluginProperty>of(), callContext); fail("Should not be able to create ADD-ON because BP is paused"); } catch (EntitlementApiException e) { entitlementApi.resume(baseEntitlement.getBundleId(), new LocalDate(clock.getUTCNow()), ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); entitlementApi.resume(baseEntitlement.getBundleId(), new LocalDate(clock.getUTCNow()), ImmutableList.<PluginProperty>of(), callContext);
assertEquals(createdEntitlement.getState(), Entitlement.EntitlementState.PENDING); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureStartDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); assertListenerStatus(); final Invoice firstInvoice = invoiceUserApi.triggerInvoiceGeneration(createdEntitlement.getAccountId(), futureStartDate, callContext); assertListenerStatus(); createdEntitlement.cancelEntitlementWithDate(futureStartDate, true, ImmutableList.<PluginProperty>of(), callContext);
Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.PENDING); assertEquals(entitlement.getEffectiveStartDate(), entitlementDate); entitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), entitlementDate, ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Change plan prior billingStartDate should fail"); } catch (EntitlementApiException e) { final Entitlement result = entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec2), null, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertEquals(result.getState(), EntitlementState.ACTIVE); assertEquals(result.getLastActiveProduct().getName(), "Pistol");
assertListenerStatus(); final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(baseEntitlementId, callContext); assertEquals(baseEntitlement.getSourceType(), EntitlementSourceType.MIGRATED); assertEquals(entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext).getSourceType(), EntitlementSourceType.MIGRATED); clock.addDays(32); subscriptionInternalApi.setChargedThroughDate(baseEntitlement.getId(), ctd, internalCallContext); assertListenerStatus(); final UUID newBundleId = entitlementApi.transferEntitlementsOverrideBillingPolicy(accountSrc.getId(), accountDesc.getId(), baseEntitlement.getExternalKey(), effectiveDate, BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertEquals(oldBaseEntitlement.getEffectiveEndDate(), effectiveDate); assertEquals(oldBaseEntitlement.getState(), EntitlementState.CANCELLED); assertEquals(newBaseEntitlement.getState(), EntitlementState.ACTIVE); assertEquals(newBaseEntitlement.getEffectiveStartDate(), effectiveDate); assertEquals(newBaseEntitlement.getEffectiveEndDate(), null); assertEquals(newBaseEntitlement.getSourceType(), EntitlementSourceType.TRANSFERRED);