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(); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { // Not transactional, but there is a db constraint on that column if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) { throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey()); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); if (data.getParentAccountId() != null) { // verify that parent account exists if parentAccountId is not null final ImmutableAccountData immutableAccountData = immutableAccountInternalApi.getImmutableAccountDataById(data.getParentAccountId(), internalContext); if (immutableAccountData == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, data.getParentAccountId()); } } final AccountModelDao account = new AccountModelDao(data); if (null != account.getExternalKey() && account.getExternalKey().length() > 255) { throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultAccount(account); }
public Account checkAccount(final UUID accountId, final AccountData accountData, final CallContext context) throws Exception { final Account account = accountApi.getAccountById(accountId, context); // Not all test pass it, since this is always the same test if (accountData != null) { Assert.assertEquals(account.getName(), accountData.getName()); Assert.assertEquals(account.getFirstNameLength(), accountData.getFirstNameLength()); Assert.assertEquals(account.getEmail(), accountData.getEmail()); Assert.assertEquals(account.getPhone(), accountData.getPhone()); Assert.assertEquals(account.getExternalKey(), accountData.getExternalKey()); Assert.assertEquals(account.getBillCycleDayLocal(), accountData.getBillCycleDayLocal()); Assert.assertEquals(account.getCurrency(), accountData.getCurrency()); Assert.assertEquals(account.getTimeZone(), accountData.getTimeZone()); // createWithPaymentMethod will update the paymentMethod //Assert.assertEquals(account.getPaymentMethodId(), accountData.getPaymentMethodId()); } auditChecker.checkAccountCreated(account, context); return account; } }
Mockito.when(accountDataUpdates2.getEmail()).thenReturn(UUID.randomUUID().toString()); Mockito.when(accountDataUpdates2.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(accountDataUpdates2.getFirstNameLength()).thenReturn(12); final Account accountUpdates2 = new DefaultAccount(UUID.randomUUID(), accountDataUpdates2);
@Test(groups = "slow") public void testCancelSubscription_START_OF_TERM() throws SubscriptionBaseApiException { // Set date in such a way that Phase align with the first of the month (and so matches our hardcoded accountData account BCD) final DateTime testStartDate = new DateTime(2016, 11, 1, 0, 3, 42, 0); clock.setDeltaFromReality(testStartDate.getMillis() - clock.getUTCNow().getMillis()); final String prod = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet); PlanPhase currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL); // Move out of TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDays(30); assertListenerStatus(); // Artificially set the CTD final Duration ctd = testUtil.getDurationMonth(1); final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(clock.getUTCNow(), ctd); subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); // Move ahead a bit abd cancel START_OF_TERM clock.addDays(5); testListener.pushExpectedEvent(NextEvent.CANCEL); subscription.cancelWithPolicy(BillingActionPolicy.START_OF_TERM, callContext); assertListenerStatus(); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); Assert.assertEquals(subscription.getAllTransitions().get(subscription.getAllTransitions().size() - 1).getTransitionType(), SubscriptionBaseTransitionType.CANCEL); Assert.assertEquals(new LocalDate(subscription.getAllTransitions().get(subscription.getAllTransitions().size() - 1).getEffectiveTransitionTime(), accountData.getTimeZone()), new LocalDate(2016, 12, 1)); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { // Not transactional, but there is a db constraint on that column if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) { throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey()); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); if (data.getParentAccountId() != null) { // verify that parent account exists if parentAccountId is not null final ImmutableAccountData immutableAccountData = immutableAccountInternalApi.getImmutableAccountDataById(data.getParentAccountId(), internalContext); if (immutableAccountData == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, data.getParentAccountId()); } } final AccountModelDao account = new AccountModelDao(data); if (null != account.getExternalKey() && account.getExternalKey().length() > 255) { throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultAccount(account); }
@Test(groups = "slow") public void testCancelSubscription_START_OF_TERM() throws SubscriptionBaseApiException { // Set date in such a way that Phase align with the first of the month (and so matches our hardcoded accountData account BCD) final DateTime testStartDate = new DateTime(2016, 11, 1, 0, 3, 42, 0); clock.setDeltaFromReality(testStartDate.getMillis() - clock.getUTCNow().getMillis()); final String prod = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet); PlanPhase currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL); // Move out of TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDays(30); assertListenerStatus(); // Artificially set the CTD final Duration ctd = testUtil.getDurationMonth(1); final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(clock.getUTCNow(), ctd); subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); // Move ahead a bit abd cancel START_OF_TERM clock.addDays(5); testListener.pushExpectedEvent(NextEvent.CANCEL); subscription.cancelWithPolicy(BillingActionPolicy.START_OF_TERM, callContext); assertListenerStatus(); subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); Assert.assertEquals(subscription.getAllTransitions().get(subscription.getAllTransitions().size() - 1).getTransitionType(), SubscriptionBaseTransitionType.CANCEL); Assert.assertEquals(new LocalDate(subscription.getAllTransitions().get(subscription.getAllTransitions().size() - 1).getEffectiveTransitionTime(), accountData.getTimeZone()), new LocalDate(2016, 12, 1)); }
data.getExternalKey(), data.getEmail(), data.getName(), data.getFirstNameLength(), data.getCurrency(), data.getParentAccountId(), data.isPaymentDelegatedToParent(), data.getBillCycleDayLocal(), data.getPaymentMethodId(), data.getReferenceTime(), data.getTimeZone(), data.getLocale(), data.getAddress1(), data.getAddress2(), data.getCompanyName(), data.getCity(), data.getStateOrProvince(), data.getCountry(), data.getPostalCode(), data.getPhone(), data.getNotes(), data.isMigrated());
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); }
private AccountData getAccountData(final Integer bcd, final Currency currency, final String externalKey) { final AccountData secondAccountData = Mockito.mock(AccountData.class); Mockito.when(secondAccountData.getExternalKey()).thenReturn(externalKey); Mockito.when(secondAccountData.getEmail()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getFirstNameLength()).thenReturn(Integer.MAX_VALUE); Mockito.when(secondAccountData.getCurrency()).thenReturn(currency); Mockito.when(secondAccountData.getBillCycleDayLocal()).thenReturn(bcd); Mockito.when(secondAccountData.getPaymentMethodId()).thenReturn(UUID.randomUUID()); Mockito.when(secondAccountData.getTimeZone()).thenReturn(DateTimeZone.forID("EST")); Mockito.when(secondAccountData.getLocale()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getAddress1()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getAddress2()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getCompanyName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getCity()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getStateOrProvince()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getCountry()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getPostalCode()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.getPhone()).thenReturn(UUID.randomUUID().toString()); Mockito.when(secondAccountData.isMigrated()).thenReturn(false); return secondAccountData; }
public MockAccountBuilder(final AccountData data) { this.address1(data.getAddress1()); this.address2(data.getAddress2()); this.billingCycleDayLocal(data.getBillCycleDayLocal()); this.city(data.getCity()); this.companyName(data.getCompanyName()); this.country(data.getCountry()); this.currency(data.getCurrency()); this.parentAccountId(data.getParentAccountId()); this.isPaymentDelegatedToParent(data.isPaymentDelegatedToParent()); this.email(data.getEmail()); this.externalKey(data.getExternalKey()); this.firstNameLength(data.getFirstNameLength()); this.locale(data.getLocale()); this.migrated(data.isMigrated()); this.name(data.getName()); this.paymentMethodId(data.getPaymentMethodId()); this.phone(data.getPhone()); this.notes(data.getNotes()); this.postalCode(data.getPostalCode()); this.stateOrProvince(data.getStateOrProvince()); this.referenceTime(data.getReferenceTime()); this.timeZone(data.getTimeZone()); if (data instanceof Account) { this.id = ((Account) data).getId();
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(); }
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); }
data.getExternalKey(), data.getEmail(), data.getName(), data.getFirstNameLength(), data.getCurrency(), data.getParentAccountId(), data.isPaymentDelegatedToParent(), data.getBillCycleDayLocal(), data.getPaymentMethodId(), data.getReferenceTime(), data.getTimeZone(), data.getLocale(), data.getAddress1(), data.getAddress2(), data.getCompanyName(), data.getCity(), data.getStateOrProvince(), data.getCountry(), data.getPostalCode(), data.getPhone(), data.getNotes(), data.isMigrated());
public MockAccountBuilder(final AccountData data) { this.address1(data.getAddress1()); this.address2(data.getAddress2()); this.billingCycleDayLocal(data.getBillCycleDayLocal()); this.city(data.getCity()); this.companyName(data.getCompanyName()); this.country(data.getCountry()); this.currency(data.getCurrency()); this.parentAccountId(data.getParentAccountId()); this.isPaymentDelegatedToParent(data.isPaymentDelegatedToParent()); this.email(data.getEmail()); this.externalKey(data.getExternalKey()); this.firstNameLength(data.getFirstNameLength()); this.locale(data.getLocale()); this.migrated(data.isMigrated()); this.name(data.getName()); this.paymentMethodId(data.getPaymentMethodId()); this.phone(data.getPhone()); this.notes(data.getNotes()); this.postalCode(data.getPostalCode()); this.stateOrProvince(data.getStateOrProvince()); this.referenceTime(data.getReferenceTime()); this.timeZone(data.getTimeZone()); if (data instanceof Account) { this.id = ((Account) data).getId();