private void checkChangePlan(final DefaultSubscriptionBase subscription, final String expProduct, final ProductCategory expCategory, final BillingPeriod expBillingPeriod, final PhaseType expPhase) { final Plan currentPlan = subscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), expProduct); assertEquals(currentPlan.getProduct().getCategory(), expCategory); assertEquals(currentPlan.getRecurringBillingPeriod(), expBillingPeriod); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), expPhase); }
public boolean isAddonAvailable(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); final Collection<Product> availableAddOns = baseProduct.getAvailable(); for (final Product curAv : availableAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; } } return false; }
public boolean isAddonIncluded(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); final Collection<Product> includedAddOns = baseProduct.getIncluded(); for (final Product curAv : includedAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; } } return false; }
private Product toDefaultProduct(@Nullable final Product input) { if (input == null) { return null; } if (tmpDefaultProducts != null) { final Product existingProduct = tmpDefaultProducts.get(input.getName()); if (existingProduct == null) throw new IllegalStateException("Unknown product " + input.getName()); return existingProduct; } final DefaultProduct result = new DefaultProduct(); result.setCatalogName(catalogName); result.setCatagory(input.getCategory()); result.setName(input.getName()); result.setPrettyName(input.getPrettyName()); return result; }
@Test(groups = "slow") public void testOverrideOneOutOfTwoTieredBlockPrices() throws Exception { final DefaultPlan overriddenPlan = priceOverride.getOrCreateOverriddenPlan(catalog, plan, new DateTime(catalog.getEffectiveDate()), overrides, internalCallContext); assertTrue(m.matches()); assertEquals(m.group(1), plan.getName()); assertEquals(overriddenPlan.getProduct().getName(), plan.getProduct().getName()); assertEquals(overriddenPlan.getRecurringBillingPeriod(), plan.getRecurringBillingPeriod()); if (plan.getEffectiveDateForExistingSubscriptions() != null) {
@Test(groups = "slow") public void testTransferWithAO() throws Exception { final String baseProduct = "Shotgun"; final DateTime ctd = baseSubscription.getStartDate().plusDays(30).plusMonths(1); subscriptionInternalApi.setChargedThroughDate(baseSubscription.getId(), ctd, internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1); final Plan curPlan = cur.getCurrentPlan(); final Product curProduct = curPlan.getProduct(); if (curProduct.getName().equals(baseProduct)) { foundBP = true; assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo(((DefaultSubscriptionBase) baseSubscription).getAlignStartDate()) == 0); assertNull(cur.getPendingTransition()); } else if (curProduct.getName().equals(aoProduct1)) { foundAO1 = true; assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo((aoSubscription1).getAlignStartDate()) == 0); assertNull(cur.getPendingTransition()); } else if (curProduct.getName().equals(aoProduct2)) { foundAO2 = true; assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo((aoSubscription2).getAlignStartDate()) == 0); assertNotNull(cur.getPendingTransition()); } else { Assert.fail("Unexpected product " + curProduct.getName());
@Test(groups = "slow") public void testTransferBPInTrialWithCTD() throws Exception { final String baseProduct = "Shotgun"; final DateTime ctd = baseSubscription.getStartDate().plusDays(30); assertNotNull(oldBaseSubscription.getFutureEndDate()); assertTrue(oldBaseSubscription.getFutureEndDate().compareTo(ctd) == 0); assertEquals(bundlesForAccountAndKey.size(), 1); assertTrue(((DefaultSubscriptionBase) newBaseSubscription).getAlignStartDate().compareTo(((DefaultSubscriptionBase) oldBaseSubscription).getAlignStartDate()) == 0); assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL);
@Test(groups = "slow") public void testSimpleCreateSubscription() throws SubscriptionBaseApiException { final DateTime init = clock.getUTCNow(); assertNotNull(subscription); assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey()); testUtil.assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow()); testUtil.assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow()); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), productName); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.MONTHLY); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertTrue(futureNow.isAfter(nextPhaseChange));
@Test(groups = "slow") public void testEntitlementChangePlanOnPendingEntitlement() throws AccountApiException, EntitlementApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.PENDING); fail("Changing plan immediately prior the subscription is active is not allowed"); } catch (EntitlementApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_NON_ACTIVE.getCode()); assertEquals(entitlement1.getState(), EntitlementState.ACTIVE); assertEquals(entitlement1.getLastActiveProduct().getName(), "Pistol");
@Test(groups = "slow") public void testUncancel() throws SubscriptionBaseApiException { final String prod = "Shotgun"; assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL); assertListenerStatus(); PlanPhase currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN); assertEquals(currentPlan.getProduct().getName(), prod); currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
@Test(groups = "slow") public void testChangePlanOnPendingSubscription() throws SubscriptionBaseApiException { assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); assertEquals(((DefaultSubscriptionBase) result1.get(0)).getCurrentOrPendingPlan().getName(), "pistol-monthly"); assertEquals(((DefaultSubscriptionBase) result1.get(0)).getPendingTransition().getTransitionType(), SubscriptionBaseTransitionType.CREATE); subscription.changePlanWithDate(spec, subscription.getStartDate().minusDays(1), callContext); fail("Change plan should have failed : subscription PENDING"); } catch (final SubscriptionBaseApiException e) { assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.ACTIVE); assertEquals(subscription2.getCurrentPlan().getProduct().getName(), "Pistol"); assertEquals(subscription2.getEvents().size(), subscription.getEvents().size());
@Test(groups = "slow") public void testWithMultipleCancellationEvent() throws SubscriptionBillingApiException, SubscriptionBaseApiException { final String prod = "Shotgun"; assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertEquals(trialPhase.getPhaseType(), PhaseType.EVERGREEN); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription.getLastActiveProduct().getName(), prod); assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14)); clock.addDeltaFromReality(it.toDurationMillis()); assertNotNull(aoCurrentPlan); assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct); assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(aoCurrentPlan.getRecurringBillingPeriod(), aoTerm); assertEquals(aoSubscription.getBundleStartDate().compareTo(baseSubscription.getBundleStartDate()), 0); assertEquals(aoPendingTranstion.getEffectiveTransitionTime(), baseSubscription.getStartDate().plusMonths(1)); } else { assertEquals(aoPendingTranstion.getEffectiveTransitionTime(), aoSubscription.getStartDate().plusMonths(1)); assertNotNull(aoCurrentPlan); assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct); assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(aoCurrentPlan.getRecurringBillingPeriod(), aoTerm);
@Test(groups = "slow") public void testRefundedInvoiceWithInvoiceItemAdjustmentWithRepair() throws InvoiceApiException, EntityPersistenceException { final UUID accountId = account.getId(); final LocalDate recuringStartDate = clock.getUTCNow().plusDays(30).toLocalDate(); final LocalDate recuringEndDate = recuringStartDate.plusMonths(1); final LocalDate targetDate = recuringStartDate.plusDays(1); assertNotNull(savedInvoice); assertEquals(savedInvoice.getInvoiceItems().size(), 2); Mockito.when(product.getName()).thenReturn("product"); assertNotNull(firstInvoice); assertEquals(firstInvoice.getInvoiceItems().size(), 2);
final PlanPhase trialPhase = subscription.getCurrentPhase(); final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration()); assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); currentTime = clock.getUTCNow(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1)); clock.addDeltaFromReality(it.toDurationMillis()); currentTime = clock.getUTCNow(); final String currentProduct = subscription.getCurrentPlan().getProduct().getName(); assertNotNull(currentProduct); assertEquals(currentProduct, toProd); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(11)); clock.addDeltaFromReality(it.toDurationMillis()); currentTime = clock.getUTCNow();
@Test(groups = "slow") public void testInvoiceNumber() throws InvoiceApiException, EntityPersistenceException { final Currency currency = Currency.USD; final DateTime targetDate1 = clock.getUTCNow().plusMonths(1); final DateTime targetDate2 = clock.getUTCNow().plusMonths(2); Mockito.when(product.getName()).thenReturn("product"); invoiceUtil.createInvoice(invoice1, context); invoice1 = new DefaultInvoice(invoiceDao.getById(invoice1.getId(), context)); assertNotNull(invoice1.getInvoiceNumber()); invoiceUtil.createInvoice(invoice2, context); invoice2 = new DefaultInvoice(invoiceDao.getById(invoice2.getId(), context)); assertNotNull(invoice2.getInvoiceNumber());
final AddonUtils addonUtils, final InternalTenantContext context) throws SubscriptionBaseApiException, CatalogApiException { switch (plan.getProduct().getCategory()) { case BASE: if (baseSubscription != null && throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_NO_BP, bundleId); if (effectiveDate.isBefore(baseSubscription.getStartDate())) { throw new SubscriptionBaseApiException(ErrorCode.SUB_INVALID_REQUESTED_DATE, effectiveDate.toString(), baseSubscription.getStartDate().toString()); plan.getProduct().getCategory().toString()));
public StandaloneCatalog toStandaloneCatalog(final StandalonePluginCatalog pluginCatalog) { final StandaloneCatalog result = new StandaloneCatalog(); result.setCatalogName(catalogName); result.setEffectiveDate(pluginCatalog.getEffectiveDate().toDate()); result.setProducts(toDefaultProducts(pluginCatalog.getProducts())); result.setPlans(toDefaultPlans(result, pluginCatalog.getPlans())); result.setPriceLists(toDefaultPriceListSet(pluginCatalog.getDefaultPriceList(), pluginCatalog.getChildrenPriceList())); result.setSupportedCurrencies(toArray(pluginCatalog.getCurrencies())); result.setUnits(toDefaultUnits(pluginCatalog.getUnits())); result.setPlanRules(toDefaultPlanRules(pluginCatalog.getPlanRules())); for (final Product cur : pluginCatalog.getProducts()) { final Product target = result.getCatalogEntityCollectionProduct().findByName(cur.getName()); if (target != null) { ((DefaultProduct) target).setAvailable(toFilteredDefaultProduct(cur.getAvailable())); ((DefaultProduct) target).setIncluded(toFilteredDefaultProduct(cur.getIncluded())); } } result.initialize(result); return result; }
private boolean isBaseSpecifier(final Plan inputPlan) { return inputPlan.getProduct().getCategory() == ProductCategory.BASE; }
@Override public String apply(final Product input) { return input.getName(); } });