private static BusinessSubscriptionEvent eventFromType(final EventType eventType, final String plan, final Catalog catalog, final DateTime eventTime, final DateTime subscriptionCreationDate) { Plan thePlan = null; try { thePlan = catalog.findPlan(plan, eventTime, subscriptionCreationDate); } catch (CatalogApiException e) { log.error(String.format("Failed to retrieve PLan from catalog for %s", plan)); } final ProductCategory category = getTypeFromSubscription(thePlan); return new BusinessSubscriptionEvent(eventType, category); }
@BeforeClass(groups = "slow") public void beforeClass() throws Exception { super.beforeClass(); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), 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); setupBusinessSubscriptionTransition(); setupBusinessAccount(); }
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); product = new MockProduct("platinium", "subscription", ProductCategory.BASE); plan = new MockPlan("platinum-monthly", product); phase = new MockPhase(PhaseType.EVERGREEN, plan, MockDuration.UNLIMITED(), 25.95); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), 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); subscription = new MockSubscription(SubscriptionState.ACTIVE, plan, phase); }
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); product = new MockProduct("platinium", "subscription", ProductCategory.BASE); plan = new MockPlan("platinum-monthly", product); phase = new MockPhase(PhaseType.EVERGREEN, plan, MockDuration.UNLIMITED(), 25.95); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), 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); isubscription = new MockSubscription(SubscriptionState.ACTIVE, plan, phase); subscription = new BusinessSubscription(isubscription, USD, catalog); }
@Test(groups = "fast") public void testCalculateBCDForAOWithBPCancelledBundleAligned() throws Exception { final DateTimeZone accountTimeZone = DateTimeZone.UTC; final DateTime bpStartDateUTC = new DateTime(2012, 7, 16, 21, 0, 0, DateTimeZone.UTC); final int expectedBCDUTC = 16; // Create a Bundle associated with a subscription final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class); final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getStartDate()).thenReturn(bpStartDateUTC); // subscription.getCurrentPlan() will return null as expected (cancelled BP) Mockito.when(subscriptionInternalApi.getBaseSubscription(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscription); // Create a the base plan associated with that subscription final Plan plan = Mockito.mock(Plan.class); Mockito.when(plan.dateOfFirstRecurringNonZeroCharge(bpStartDateUTC, null)).thenReturn(bpStartDateUTC); final Catalog catalog = Mockito.mock(Catalog.class); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(subscription.getLastActivePlan()).thenReturn(plan); final Account account = Mockito.mock(Account.class); Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone); final Integer billCycleDayLocal = billCycleDayCalculator.calculateBcdForAlignment(BillingAlignment.BUNDLE, bundle, subscription, account, catalog, null, internalCallContext); Assert.assertEquals(billCycleDayLocal, (Integer) expectedBCDUTC); }
private TimedPhase getNextTimedPhaseOnChange(final DefaultSubscriptionBase defaultSubscriptionBase, final String newProductName, final DateTime effectiveChangeDate) throws CatalogApiException, SubscriptionBaseApiException { // The date is used for different catalog versions - we don't care here final Plan newPlan = catalogService.getFullCatalog().findPlan(newProductName, clock.getUTCNow()); return planAligner.getNextTimedPhaseOnChange(defaultSubscriptionBase, newPlan, priceList, effectiveChangeDate, effectiveChangeDate); }
private TimedPhase[] getTimedPhasesOnCreate(final String productName, final PhaseType initialPhase, final DefaultSubscriptionBase defaultSubscriptionBase, final DateTime effectiveDate) throws CatalogApiException, SubscriptionBaseApiException { // The date is used for different catalog versions - we don't care here final Plan plan = catalogService.getFullCatalog().findPlan(productName, clock.getUTCNow()); // Same here for the requested date final TimedPhase[] phases = planAligner.getCurrentAndNextTimedPhaseOnCreate(defaultSubscriptionBase, plan, initialPhase, priceList, clock.getUTCNow(), effectiveDate); Assert.assertEquals(phases.length, 2); return phases; } }
@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); }
final PlanPhase phase = new MockPhase(PhaseType.TRIAL, plan, MockDuration.UNLIMITED(), 25.95); final Catalog catalog = Mockito.mock(Catalog.class); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(catalog.findPhase(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(phase); final BusinessSubscriptionTransitionModelDao transition = new BusinessSubscriptionTransitionModelDao(
plan = catalogService.getFullCatalog().findPlan(invoiceItem.getPlanName(), invoiceItem.getStartDate().toDateTimeAtStartOfDay()); } catch (CatalogApiException e) { log.warn("Unable to retrieve plan for invoice item {}", invoiceItem.getId());
PlanPhase thePhase = null; try { thePlan = (currentPlan != null) ? catalog.findPlan(currentPlan, new DateTime(), startDate) : null; thePhase = (currentPhase != null) ? catalog.findPhase(currentPhase, new DateTime(), startDate) : null; } catch (CatalogApiException e) {
protected int calculateBcd(final SubscriptionBaseBundle bundle, final SubscriptionBase subscription, final EffectiveSubscriptionInternalEvent transition, final Account account, final InternalCallContext context) throws CatalogApiException, AccountApiException, SubscriptionBaseApiException { final Catalog catalog = catalogService.getFullCatalog(); final Plan prevPlan = (transition.getPreviousPlan() != null) ? catalog.findPlan(transition.getPreviousPlan(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final Plan nextPlan = (transition.getNextPlan() != null) ? catalog.findPlan(transition.getNextPlan(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final Plan plan = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? nextPlan : prevPlan; final Product product = plan.getProduct(); final PlanPhase prevPhase = (transition.getPreviousPhase() != null) ? catalog.findPhase(transition.getPreviousPhase(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final PlanPhase nextPhase = (transition.getNextPhase() != null) ? catalog.findPhase(transition.getNextPhase(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final PlanPhase phase = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? nextPhase : prevPhase; final BillingAlignment alignment = catalog.billingAlignment( new PlanPhaseSpecifier(product.getName(), product.getCategory(), phase.getBillingPeriod(), transition.getNextPriceList(), phase.getPhaseType()), transition.getRequestedTransitionTime()); return calculateBcdForAlignment(alignment, bundle, subscription, account, catalog, plan, context); }
public DefaultBillingEvent(final Account account, final EffectiveSubscriptionInternalEvent transition, final SubscriptionBase subscription, final int billCycleDayLocal, final Currency currency, final Catalog catalog) throws CatalogApiException { this.account = account; this.billCycleDayLocal = billCycleDayLocal; this.subscription = subscription; effectiveDate = transition.getEffectiveTransitionTime(); final String planPhaseName = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? transition.getNextPhase() : transition.getPreviousPhase(); planPhase = (planPhaseName != null) ? catalog.findPhase(planPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final String planName = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? transition.getNextPlan() : transition.getPreviousPlan(); plan = (planName != null) ? catalog.findPlan(planName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final String nextPhaseName = transition.getNextPhase(); final PlanPhase nextPhase = (nextPhaseName != null) ? catalog.findPhase(nextPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final String prevPhaseName = transition.getPreviousPhase(); final PlanPhase prevPhase = (prevPhaseName != null) ? catalog.findPhase(prevPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; fixedPrice = (nextPhase != null && nextPhase.getFixedPrice() != null) ? nextPhase.getFixedPrice().getPrice(currency) : null; recurringPrice = (nextPhase != null && nextPhase.getRecurringPrice() != null) ? nextPhase.getRecurringPrice().getPrice(currency) : null; this.currency = currency; description = transition.getTransitionType().toString(); billingModeType = BillingModeType.IN_ADVANCE; billingPeriod = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? nextPhase.getBillingPeriod() : prevPhase.getBillingPeriod(); type = transition.getTransitionType(); totalOrdering = transition.getTotalOrdering(); timeZone = account.getTimeZone(); }