@Override public Catalog getCatalog(final String catalogName, final TenantContext context) { // STEPH TODO this is hack until we decides what do do exactly: // Probably we want one catalog for tenant but but TBD return catalogService.getFullCatalog(); } }
public Catalog initCatalog(final CatalogService catalogService) throws Exception { ((DefaultCatalogService) catalogService).loadCatalog(); final Catalog catalog = catalogService.getFullCatalog(); assertNotNull(catalog); return catalog; }
private Catalog initCatalog(final CatalogService catalogService) throws Exception { ((DefaultCatalogService) catalogService).loadCatalog(); final Catalog catalog = catalogService.getFullCatalog(); assertNotNull(catalog); return catalog; }
@Override protected void configure() { final Catalog catalog = Mockito.mock(Catalog.class); final CatalogService catalogService = Mockito.mock(CatalogService.class); Mockito.when(catalogService.getCurrentCatalog()).thenReturn(new MockCatalog()); Mockito.when(catalogService.getFullCatalog()).thenReturn(catalog); bind(CatalogService.class).toInstance(catalogService); } }
private BusinessSubscriptionEvent subscriptionRecreated(final SubscriptionInternalEvent recreated) throws AccountApiException, EntitlementUserApiException { return BusinessSubscriptionEvent.subscriptionRecreated(recreated.getNextPlan(), catalogService.getFullCatalog(), recreated.getEffectiveTransitionTime(), recreated.getSubscriptionStartDate()); }
@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(); }
private BusinessSubscriptionEvent subscriptionMigrated(final SubscriptionInternalEvent created) throws AccountApiException, EntitlementUserApiException { return BusinessSubscriptionEvent.subscriptionMigrated(created.getNextPlan(), catalogService.getFullCatalog(), created.getEffectiveTransitionTime(), created.getSubscriptionStartDate()); }
private BusinessSubscriptionEvent subscriptionCreated(final SubscriptionInternalEvent created) throws AccountApiException, EntitlementUserApiException { return BusinessSubscriptionEvent.subscriptionCreated(created.getNextPlan(), catalogService.getFullCatalog(), created.getEffectiveTransitionTime(), created.getSubscriptionStartDate()); }
private BusinessSubscriptionEvent subscriptionTransfered(final SubscriptionInternalEvent transfered) throws AccountApiException, EntitlementUserApiException { return BusinessSubscriptionEvent.subscriptionTransfered(transfered.getNextPlan(), catalogService.getFullCatalog(), transfered.getEffectiveTransitionTime(), transfered.getSubscriptionStartDate()); }
private BusinessSubscriptionEvent subscriptionChanged(final SubscriptionInternalEvent changed) throws AccountApiException, EntitlementUserApiException { return BusinessSubscriptionEvent.subscriptionChanged(changed.getNextPlan(), catalogService.getFullCatalog(), changed.getEffectiveTransitionTime(), changed.getSubscriptionStartDate()); }
private BusinessSubscriptionEvent subscriptionCancelled(final SubscriptionInternalEvent cancelled) throws AccountApiException, EntitlementUserApiException { // cancelled.getNextPlan() is null here - need to look at the previous one to create the correct event name return BusinessSubscriptionEvent.subscriptionCancelled(cancelled.getPreviousPlan(), catalogService.getFullCatalog(), cancelled.getEffectiveTransitionTime(), cancelled.getSubscriptionStartDate()); }
@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); }
@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); }
private BusinessSubscriptionEvent subscriptionPhaseChanged(final SubscriptionInternalEvent phaseChanged) throws AccountApiException, EntitlementUserApiException { return BusinessSubscriptionEvent.subscriptionPhaseChanged(phaseChanged.getNextPlan(), phaseChanged.getNextState(), catalogService.getFullCatalog(), phaseChanged.getEffectiveTransitionTime(), phaseChanged.getSubscriptionStartDate()); }
private void addBillingEventsForSubscription(final List<SubscriptionBase> subscriptions, final SubscriptionBaseBundle bundle, final Account account, final InternalCallContext context, final DefaultBillingEventSet result) { boolean updatedAccountBCD = false; for (final SubscriptionBase subscription : subscriptions) { for (final EffectiveSubscriptionInternalEvent transition : subscriptionApi.getBillingTransitions(subscription, context)) { try { final int bcdLocal = bcdCalculator.calculateBcd(bundle, subscription, transition, account, context); if (account.getBillCycleDayLocal() == 0 && !updatedAccountBCD) { final MutableAccountData modifiedData = account.toMutableAccountData(); modifiedData.setBillCycleDayLocal(bcdLocal); accountApi.updateAccount(account.getExternalKey(), modifiedData, context); updatedAccountBCD = true; } final BillingEvent event = new DefaultBillingEvent(account, transition, subscription, bcdLocal, account.getCurrency(), catalogService.getFullCatalog()); result.add(event); } catch (CatalogApiException e) { log.error("Failing to identify catalog components while creating BillingEvent from transition: " + transition.getId().toString(), e); } catch (Exception e) { log.warn("Failed while getting BillingEvent", e); } } } }
@BeforeMethod(groups = "slow") public void beforeMethod() throws Exception { super.beforeMethod(); Mockito.when(catalogService.getFullCatalog()).thenReturn(new MockCatalog()); final PaymentMethod paymentMethod = Mockito.mock(PaymentMethod.class); final UUID paymentMethodId = UUID.randomUUID(); Mockito.when(paymentMethod.getId()).thenReturn(paymentMethodId); final Account account = new MockAccountBuilder(UUID.randomUUID()) .externalKey(ACCOUNT_KEY) .currency(ACCOUNT_CURRENCY) .paymentMethodId(paymentMethodId) .build(); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalCallContext>any())).thenReturn(account); try { // Create events for the bus and expected results createSubscriptionTransitionEvent(account); createAccountCreationEvent(account); createInvoiceAndPaymentCreationEvents(account); } catch (Throwable t) { fail("Initializing accounts failed.", t); } }
private SubscriptionBase buildSubscription(final DefaultSubscriptionBase in, final InternalTenantContext context) { final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(new SubscriptionBuilder(in), null, clock); if (events.size() > 0) { subscription.rebuildTransitions(getEventsForSubscription(in.getId(), context), catalogService.getFullCatalog()); } return subscription; }
private BusinessSubscription createNextBusinessSubscription(final EffectiveSubscriptionInternalEvent event, final BusinessSubscriptionEvent businessEvent, final Currency currency) { final BusinessSubscription nextSubscription; if (BusinessSubscriptionEvent.EventType.CANCEL.equals(businessEvent.getEventType()) || BusinessSubscriptionEvent.EventType.SYSTEM_CANCEL.equals(businessEvent.getEventType())) { nextSubscription = null; } else { nextSubscription = new BusinessSubscription(event.getNextPriceList(), event.getNextPlan(), event.getNextPhase(), currency, event.getEffectiveTransitionTime(), event.getNextState(), catalogService.getFullCatalog()); } return nextSubscription; }
private BusinessSubscription createPreviousBusinessSubscription(final EffectiveSubscriptionInternalEvent event, final BusinessSubscriptionEvent businessEvent, final ArrayList<BusinessSubscriptionTransitionModelDao> transitions, final Currency currency) { if (BusinessSubscriptionEvent.EventType.MIGRATE.equals(businessEvent.getEventType()) || BusinessSubscriptionEvent.EventType.ADD.equals(businessEvent.getEventType()) || BusinessSubscriptionEvent.EventType.RE_ADD.equals(businessEvent.getEventType()) || BusinessSubscriptionEvent.EventType.TRANSFER.equals(businessEvent.getEventType())) { return null; } final BusinessSubscriptionTransitionModelDao prevTransition = getPreviousBusinessSubscriptionTransitionForEvent(event, transitions); return new BusinessSubscription(event.getPreviousPriceList(), event.getPreviousPlan(), event.getPreviousPhase(), currency, prevTransition.getNextSubscription().getStartDate(), event.getPreviousState(), catalogService.getFullCatalog()); }
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); }