public AccountModelDao(final UUID id, @Nullable final DateTime createdDate, @Nullable final DateTime updatedDate, final AccountData account, final boolean withDefaults) { this(id, createdDate, updatedDate, account.getExternalKey(), account.getEmail(), account.getName(), account.getFirstNameLength(), account.getCurrency(), account.getParentAccountId(), account.isPaymentDelegatedToParent(), MoreObjects.firstNonNull(account.getBillCycleDayLocal(), DEFAULT_BILLING_CYCLE_DAY_LOCAL), account.getPaymentMethodId(), account.getReferenceTime() != null ? account.getReferenceTime() : createdDate, account.getTimeZone(), account.getLocale(), account.getAddress1(), account.getAddress2(), account.getCompanyName(), account.getCity(), account.getStateOrProvince(), account.getCountry(), account.getPostalCode(), account.getPhone(), account.getNotes(), account.isMigrated(), withDefaults); }
@Test(groups = "slow") public void testCreateWithRequestedDate() throws SubscriptionBaseApiException { final LocalDate init = clock.getUTCToday(); final LocalDate requestedDate = init.minusYears(1); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvent(NextEvent.PHASE); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate); assertNotNull(subscription); // // In addition to Alignment phase we also test SubscriptionBaseTransition eventIds and created dates. // Keep tracks of row events to compare with ids and created dates returned by SubscriptionBaseTransition later. // final List<SubscriptionBaseEvent> events = subscription.getEvents(); Assert.assertEquals(events.size(), 2); final SubscriptionBaseEvent trialEvent = events.get(0); final SubscriptionBaseEvent phaseEvent = events.get(1); assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey()); assertEquals(subscription.getStartDate().compareTo(requestedDate.toDateTime(accountData.getReferenceTime())), 0); assertListenerStatus(); final SubscriptionBaseTransition transition = subscription.getPreviousTransition(); assertEquals(transition.getPreviousEventId(), trialEvent.getId()); assertEquals(transition.getNextEventId(), phaseEvent.getId()); assertEquals(transition.getPreviousEventCreatedDate().compareTo(trialEvent.getCreatedDate()), 0); assertEquals(transition.getNextEventCreatedDate().compareTo(phaseEvent.getCreatedDate()), 0); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription3() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription1() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); // The code will be smart to infer the cancelation date as being the future startDate subscription.cancel(callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription2() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); try { subscription.cancelWithDate(null, callContext); fail("Cancel plan should have failed : subscription PENDING"); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode()); } try { subscription.cancelWithDate(subscription.getStartDate().minusDays(1), callContext); fail("Cancel plan should have failed : subscription PENDING"); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode()); } subscription.cancelWithDate(subscription.getStartDate(), callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
data.getBillCycleDayLocal(), data.getPaymentMethodId(), data.getReferenceTime(), data.getTimeZone(), data.getLocale(),
public DefaultMutableAccountData(final AccountData accountData) { this.externalKey = accountData.getExternalKey(); this.email = accountData.getEmail(); this.name = accountData.getName(); this.firstNameLength = accountData.getFirstNameLength(); this.currency = accountData.getCurrency(); this.parentAccountId = accountData.getParentAccountId(); this.isPaymentDelegatedToParent = accountData.isPaymentDelegatedToParent(); this.billCycleDayLocal = accountData.getBillCycleDayLocal() == null ? DEFAULT_BILLING_CYCLE_DAY_LOCAL : accountData.getBillCycleDayLocal(); this.paymentMethodId = accountData.getPaymentMethodId(); this.referenceTime = accountData.getReferenceTime(); this.timeZone = accountData.getTimeZone(); this.locale = accountData.getLocale(); this.address1 = accountData.getAddress1(); this.address2 = accountData.getAddress2(); this.companyName = accountData.getCompanyName(); this.city = accountData.getCity(); this.stateOrProvince = accountData.getStateOrProvince(); this.country = accountData.getCountry(); this.postalCode = accountData.getPostalCode(); this.phone = accountData.getPhone(); this.notes = accountData.getNotes(); this.isMigrated = accountData.isMigrated(); }
this.postalCode(data.getPostalCode()); this.stateOrProvince(data.getStateOrProvince()); this.referenceTime(data.getReferenceTime()); this.timeZone(data.getTimeZone()); if (data instanceof Account) {
public AccountModelDao(final UUID id, @Nullable final DateTime createdDate, @Nullable final DateTime updatedDate, final AccountData account, final boolean withDefaults) { this(id, createdDate, updatedDate, account.getExternalKey(), account.getEmail(), account.getName(), account.getFirstNameLength(), account.getCurrency(), account.getParentAccountId(), account.isPaymentDelegatedToParent(), MoreObjects.firstNonNull(account.getBillCycleDayLocal(), DEFAULT_BILLING_CYCLE_DAY_LOCAL), account.getPaymentMethodId(), account.getReferenceTime() != null ? account.getReferenceTime() : createdDate, account.getTimeZone(), account.getLocale(), account.getAddress1(), account.getAddress2(), account.getCompanyName(), account.getCity(), account.getStateOrProvince(), account.getCountry(), account.getPostalCode(), account.getPhone(), account.getNotes(), account.isMigrated(), withDefaults); }
@Test(groups = "slow") public void testCreateWithRequestedDate() throws SubscriptionBaseApiException { final LocalDate init = clock.getUTCToday(); final LocalDate requestedDate = init.minusYears(1); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvent(NextEvent.PHASE); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate); assertNotNull(subscription); // // In addition to Alignment phase we also test SubscriptionBaseTransition eventIds and created dates. // Keep tracks of row events to compare with ids and created dates returned by SubscriptionBaseTransition later. // final List<SubscriptionBaseEvent> events = subscription.getEvents(); Assert.assertEquals(events.size(), 2); final SubscriptionBaseEvent trialEvent = events.get(0); final SubscriptionBaseEvent phaseEvent = events.get(1); assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey()); assertEquals(subscription.getStartDate().compareTo(requestedDate.toDateTime(accountData.getReferenceTime())), 0); assertListenerStatus(); final SubscriptionBaseTransition transition = subscription.getPreviousTransition(); assertEquals(transition.getPreviousEventId(), trialEvent.getId()); assertEquals(transition.getNextEventId(), phaseEvent.getId()); assertEquals(transition.getPreviousEventCreatedDate().compareTo(trialEvent.getCreatedDate()), 0); assertEquals(transition.getNextEventCreatedDate().compareTo(phaseEvent.getCreatedDate()), 0); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription1() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); // The code will be smart to infer the cancelation date as being the future startDate subscription.cancel(callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription3() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription2() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); try { subscription.cancelWithDate(null, callContext); fail("Cancel plan should have failed : subscription PENDING"); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode()); } try { subscription.cancelWithDate(subscription.getStartDate().minusDays(1), callContext); fail("Cancel plan should have failed : subscription PENDING"); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode()); } subscription.cancelWithDate(subscription.getStartDate(), callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
public DefaultMutableAccountData(final AccountData accountData) { this.externalKey = accountData.getExternalKey(); this.email = accountData.getEmail(); this.name = accountData.getName(); this.firstNameLength = accountData.getFirstNameLength(); this.currency = accountData.getCurrency(); this.parentAccountId = accountData.getParentAccountId(); this.isPaymentDelegatedToParent = accountData.isPaymentDelegatedToParent(); this.billCycleDayLocal = accountData.getBillCycleDayLocal() == null ? DEFAULT_BILLING_CYCLE_DAY_LOCAL : accountData.getBillCycleDayLocal(); this.paymentMethodId = accountData.getPaymentMethodId(); this.referenceTime = accountData.getReferenceTime(); this.timeZone = accountData.getTimeZone(); this.locale = accountData.getLocale(); this.address1 = accountData.getAddress1(); this.address2 = accountData.getAddress2(); this.companyName = accountData.getCompanyName(); this.city = accountData.getCity(); this.stateOrProvince = accountData.getStateOrProvince(); this.country = accountData.getCountry(); this.postalCode = accountData.getPostalCode(); this.phone = accountData.getPhone(); this.notes = accountData.getNotes(); this.isMigrated = accountData.isMigrated(); }
data.getBillCycleDayLocal(), data.getPaymentMethodId(), data.getReferenceTime(), data.getTimeZone(), data.getLocale(),
this.postalCode(data.getPostalCode()); this.stateOrProvince(data.getStateOrProvince()); this.referenceTime(data.getReferenceTime()); this.timeZone(data.getTimeZone()); if (data instanceof Account) {