@Override public String getName() { if (plan == null) { return null; } else { return plan.getName() + "-" + cohort; } }
@Override public String getName() { return phaseName(plan.getName(), this.getPhaseType()); }
@Override public List<Listing> getAvailableBasePlanListings() { final List<Listing> availBasePlans = new ArrayList<Listing>(); for (Plan plan : getCurrentPlans()) { if (plan.getProduct().getCategory().equals(ProductCategory.BASE)) { for (PriceList priceList : getPriceLists().getAllPriceLists()) { for (Plan priceListPlan : priceList.getPlans()) { if (priceListPlan.getName().equals(plan.getName()) && priceListPlan.getProduct().getName().equals(plan.getProduct().getName())) { availBasePlans.add(new DefaultListing(priceListPlan, priceList)); } } } } } return availBasePlans; } }
@Test(groups = "fast") public void testEquals() throws Exception { final DateTime now = new DateTime(); final BusinessSubscriptionEvent event = BusinessSubscriptionEvent.subscriptionChanged(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertSame(event, event); Assert.assertEquals(event, event); Assert.assertTrue(event.equals(event)); } }
@Test(groups = "fast") public void testFromListing() throws Exception { final Product product = Mockito.mock(Product.class); Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString()); final InternationalPrice price = Mockito.mock(InternationalPrice.class); final PlanPhase planPhase = Mockito.mock(PlanPhase.class); Mockito.when(planPhase.getRecurringPrice()).thenReturn(price); final Plan plan = Mockito.mock(Plan.class); Mockito.when(plan.getProduct()).thenReturn(product); Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(plan.getBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY); Mockito.when(plan.getFinalPhase()).thenReturn(planPhase); final PriceList priceList = Mockito.mock(PriceList.class); Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString()); final Listing listing = Mockito.mock(Listing.class); Mockito.when(listing.getPlan()).thenReturn(plan); Mockito.when(listing.getPriceList()).thenReturn(priceList); final PlanDetailJson planDetailJason = new PlanDetailJson(listing); Assert.assertEquals(planDetailJason.getProductName(), plan.getProduct().getName()); Assert.assertEquals(planDetailJason.getPlanName(), plan.getName()); Assert.assertEquals(planDetailJason.getBillingPeriod(), plan.getBillingPeriod()); Assert.assertEquals(planDetailJason.getPriceListName(), priceList.getName()); Assert.assertEquals(planDetailJason.getFinalPhasePrice().size(), 0); } }
private void setupBusinessSubscriptionTransition() { final DateTime requestedTimestamp = clock.getUTCNow(); final BusinessSubscription prevSubscription = new BusinessSubscription(null, plan.getName(), phase.getName(), Currency.USD, clock.getUTCNow(), SubscriptionState.ACTIVE, catalog); final BusinessSubscription nextSubscription = new BusinessSubscription(null, plan.getName(), phase.getName(), Currency.USD, clock.getUTCNow(), SubscriptionState.CANCELLED, catalog); final BusinessSubscriptionEvent event = BusinessSubscriptionEvent.subscriptionCancelled(plan.getName(), catalog, requestedTimestamp, requestedTimestamp); transition = new BusinessSubscriptionTransitionModelDao(TOTAL_ORDERING, BUNDLE_ID, EXTERNAL_KEY, ACCOUNT_ID, ACCOUNT_KEY, UUID.randomUUID(), requestedTimestamp, event, prevSubscription, nextSubscription); }
final PlanJson planJson = new PlanJson(plan.getName(), phases); productJson.getPlans().add(planJson);
private DateTime createSubscriptionCreationEvent(final Plan nextPlan, final PlanPhase nextPhase) throws CatalogApiException { final DateTime now = clock.getUTCNow(); final DateTime then = now.minusDays(1); final PriceList nextPriceList = catalog.findPriceList(PriceListSet.DEFAULT_PRICELIST_NAME, now); final EffectiveSubscriptionInternalEvent t = new MockEffectiveSubscriptionEvent( eventId, subId, bunId, then, now, null, null, null, null, EntitlementState.ACTIVE, nextPlan.getName(), nextPhase.getName(), nextPriceList.getName(), 1L, SubscriptionBaseTransitionType.CREATE, 1, null, 1L, 2L, null); effectiveSubscriptionTransitions.add(t); return now; } }
/** * For unit tests only. * <p/> * You can't really use this constructor in real life because the start date is likely not the one you want (you likely * want the phase start date). * * @param subscription Subscription to use as a model * @param currency ACCOUNT currency * @param catalog Catalog to use */ BusinessSubscription(final Subscription subscription, final Currency currency, final Catalog catalog) { this(subscription.getCurrentPriceList() == null ? null : subscription.getCurrentPriceList().getName(), subscription.getCurrentPlan().getName(), subscription.getCurrentPhase().getName(), currency, subscription.getStartDate(), subscription.getState(), catalog); }
UUID.randomUUID(), clock.getUTCNow(), BusinessSubscriptionEvent.subscriptionCreated(plan.getName(), catalog, clock.getUTCNow(), clock.getUTCNow()), null, new BusinessSubscription("DEFAULT", plan.getName(), phase.getName(), Currency.USD, clock.getUTCNow(), SubscriptionState.ACTIVE, catalog)
public PlanDetailJson(final Listing listing) { final Plan plan = listing.getPlan(); if (plan == null) { this.productName = null; this.planName = null; this.billingPeriod = null; this.finalPhasePrice = ImmutableList.<PriceJson>of(); } else { this.productName = plan.getProduct() == null ? null : plan.getProduct().getName(); this.planName = plan.getName(); this.billingPeriod = plan.getBillingPeriod(); if (plan.getFinalPhase() == null || plan.getFinalPhase().getRecurringPrice() == null || plan.getFinalPhase().getRecurringPrice().getPrices() == null) { this.finalPhasePrice = ImmutableList.<PriceJson>of(); } else { this.finalPhasePrice = Lists.transform(ImmutableList.<Price>copyOf(plan.getFinalPhase().getRecurringPrice().getPrices()), new Function<Price, PriceJson>() { @Override public PriceJson apply(final Price price) { try { return new PriceJson(price); } catch (CurrencyValueNull e) { return new PriceJson(price.getCurrency().toString(), BigDecimal.ZERO); } } }); } } this.priceListName = listing.getPriceList() == null ? null : listing.getPriceList().getName(); }
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); final Product product = new MockProduct("platinium", "subscription", ProductCategory.BASE); final Plan plan = new MockPlan("platinum-monthly", product); final PlanPhase phase = new MockPhase(PhaseType.EVERGREEN, plan, MockDuration.UNLIMITED(), 25.95); final Subscription prevISubscription = new MockSubscription(SubscriptionState.ACTIVE, plan, phase); final Subscription nextISubscription = new MockSubscription(SubscriptionState.CANCELLED, plan, phase); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(catalog.findPhase(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(phase); Mockito.when(catalogService.getFullCatalog()).thenReturn(catalog); final DateTime now = new DateTime(); prevSubscription = new BusinessSubscription(prevISubscription, USD, catalog); nextSubscription = new BusinessSubscription(nextISubscription, USD, catalog); event = BusinessSubscriptionEvent.subscriptionCancelled(prevISubscription.getCurrentPlan().getName(), catalog, now, now); requestedTimestamp = new DateTime(DateTimeZone.UTC); totalOrdering = 12L; bundleId = UUID.randomUUID(); externalKey = "1234"; accountId = UUID.randomUUID(); accountKey = "pierre-1234"; subscriptionId = UUID.randomUUID(); transition = new BusinessSubscriptionTransitionModelDao(totalOrdering, bundleId, externalKey, accountId, accountKey, subscriptionId, requestedTimestamp, event, prevSubscription, nextSubscription); }
InvoiceItem generateFixedPriceItem(final UUID invoiceId, final UUID accountId, final BillingEvent thisEvent, final LocalDate targetDate, final Currency currency) { final LocalDate roundedStartDate = new LocalDate(thisEvent.getEffectiveDate(), thisEvent.getTimeZone()); if (roundedStartDate.isAfter(targetDate)) { return null; } else { final BigDecimal fixedPrice = thisEvent.getFixedPrice(); if (fixedPrice != null) { return new FixedPriceInvoiceItem(invoiceId, accountId, thisEvent.getSubscription().getBundleId(), thisEvent.getSubscription().getId(), thisEvent.getPlan().getName(), thisEvent.getPlanPhase().getName(), roundedStartDate, fixedPrice, currency); } else { return null; } } } }
@Test(groups = "fast") public void testFromSubscription() throws Exception { BusinessSubscriptionEvent event; final DateTime now = new DateTime(); event = BusinessSubscriptionEvent.subscriptionCreated(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.ADD); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "ADD_BASE"); event = BusinessSubscriptionEvent.subscriptionCancelled(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CANCEL); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "CANCEL_BASE"); event = BusinessSubscriptionEvent.subscriptionChanged(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CHANGE); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "CHANGE_BASE"); event = BusinessSubscriptionEvent.subscriptionPhaseChanged(subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now); // The subscription is still active, it's a system change Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CHANGE); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "SYSTEM_CHANGE_BASE"); subscription = new MockSubscription(SubscriptionState.CANCELLED, plan, phase); event = BusinessSubscriptionEvent.subscriptionPhaseChanged(subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now); // The subscription is cancelled, it's a system cancellation Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CANCEL); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "SYSTEM_CANCEL_BASE"); }
Mockito.when(plan.getName()).thenReturn("plan");
@Test(groups = "slow") public void testTransitionsWithNullPhase() throws Exception { final BusinessSubscription subscriptionWithNullPhase = new BusinessSubscription(null, plan.getName(), null, Currency.USD, null, null, catalog); final BusinessSubscriptionTransitionModelDao transitionWithNullPhase = new BusinessSubscriptionTransitionModelDao( transition.getTotalOrdering(), transition.getBundleId(), transition.getExternalKey(), transition.getAccountId(), transition.getAccountKey(), transition.getSubscriptionId(), transition.getRequestedTimestamp(), transition.getEvent(), subscriptionWithNullPhase, subscriptionWithNullPhase ); subscriptionTransitionSqlDao.createTransition(transitionWithNullPhase, internalCallContext); final List<BusinessSubscriptionTransitionModelDao> transitions = subscriptionTransitionSqlDao.getTransitionsByKey(EXTERNAL_KEY, internalCallContext); Assert.assertEquals(transitions.size(), 1); Assert.assertEquals(transitions.get(0).getExternalKey(), transition.getExternalKey()); Assert.assertEquals(transitions.get(0).getRequestedTimestamp(), transition.getRequestedTimestamp()); Assert.assertEquals(transitions.get(0).getEvent(), transition.getEvent()); // Null Phase but Plan - we don't turn the subscription into a null, however price and mrr are both set to 0 (not null) final BusinessSubscription blankSubscription = new BusinessSubscription(null, plan.getName(), new MockPhase(null, null, null, 0.0).getName(), Currency.USD, null, null, catalog); Assert.assertEquals(transitions.get(0).getPreviousSubscription(), blankSubscription); Assert.assertEquals(transitions.get(0).getNextSubscription(), blankSubscription); }
@Test(groups = "slow") public void testSingleBasePlan() throws SubscriptionBaseMigrationApiException { final DateTime startDate = clock.getUTCNow().minusMonths(2); final DateTime beforeMigration = clock.getUTCNow(); final AccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate); final DateTime afterMigration = clock.getUTCNow(); testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT); migrationApi.migrate(toBeMigrated, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundles = subscriptionInternalApi.getBundlesForAccount(toBeMigrated.getAccountKey(), internalCallContext); assertEquals(bundles.size(), 1); final SubscriptionBaseBundle bundle = bundles.get(0); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(bundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1); final SubscriptionBase subscription = subscriptions.get(0); assertTrue(subscription.getStartDate().compareTo(startDate) == 0); assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1)); assertListenerStatus(); }
assertEquals(baseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE); assertEquals(baseSubscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(baseSubscription.getChargedThroughDate(), initalBPStart.plusYears(1)); assertEquals(aoSubscription.getCurrentPhase().getPhaseType(), PhaseType.DISCOUNT); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertEquals(aoSubscription.getCurrentPlan().getName(), "telescopic-scope-monthly"); assertEquals(aoSubscription.getChargedThroughDate(), initalAddonStart.plusMonths(1));
@Test(groups = "slow") public void testTransitionsWithNullFieldsInSubscription() { final BusinessSubscription subscriptionWithNullFields = new BusinessSubscription(null, plan.getName(), phase.getName(), Currency.USD, null, null, catalog); final BusinessSubscriptionTransitionModelDao transitionWithNullFields = new BusinessSubscriptionTransitionModelDao( transition.getTotalOrdering(), transition.getBundleId(), transition.getExternalKey(), transition.getAccountId(), transition.getAccountKey(), transition.getSubscriptionId(), transition.getRequestedTimestamp(), transition.getEvent(), subscriptionWithNullFields, subscriptionWithNullFields ); subscriptionTransitionSqlDao.createTransition(transitionWithNullFields, internalCallContext); final List<BusinessSubscriptionTransitionModelDao> transitions = subscriptionTransitionSqlDao.getTransitionsByKey(EXTERNAL_KEY, internalCallContext); Assert.assertEquals(transitions.size(), 1); Assert.assertEquals(transitions.get(0), transitionWithNullFields); }
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1));