final String postalCode, final String phone) { final Account result = new MockAccountBuilder(id) .externalKey(externalKey) .email(email) .name(name).firstNameLength(firstNameLength) .currency(currency) .billingCycleDayLocal(billCycleDayLocal) .paymentMethodId(paymentMethodId) .timeZone(timeZone) .locale(locale) .address1(address1) .address2(address2) .companyName(companyName) .city(city) .stateOrProvince(stateOrProvince) .country(country) .postalCode(postalCode) .phone(phone) .isNotifiedForInvoices(false) .build(); accounts.add(result); return result;
protected AccountData getAccountData(final int billingDay) { return new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)) .firstNameLength(6) .email(UUID.randomUUID().toString().substring(1, 8)) .phone(UUID.randomUUID().toString().substring(1, 8)) .migrated(false) .isNotifiedForInvoices(false) .externalKey(UUID.randomUUID().toString().substring(1, 8)) .billingCycleDayLocal(billingDay) .currency(Currency.USD) .paymentMethodId(UUID.randomUUID()) .timeZone(DateTimeZone.UTC) .build(); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { final Account result = new MockAccountBuilder(data).build(); accounts.add(result); return result; }
@Test(groups = "slow") public void testAddAndRemoveTagsForAccount() throws Exception { final String name = UUID.randomUUID().toString().substring(0, 20); final String accountKey = UUID.randomUUID().toString(); final Account accountData = new MockAccountBuilder(UUID.randomUUID()) .externalKey(accountKey) .currency(Currency.MXN) .build(); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(accountData.getId()), Mockito.<InternalCallContext>any())).thenReturn(accountData); Mockito.when(accountInternalApi.getAccountByKey(Mockito.eq(accountData.getExternalKey()), Mockito.<InternalCallContext>any())).thenReturn(accountData); final UUID accountId = accountData.getId(); Assert.assertEquals(accountTagSqlDao.getTagsForAccountByKey(accountKey, internalCallContext).size(), 0); tagDao.tagAdded(ObjectType.ACCOUNT, accountId, name, internalCallContext); Assert.assertEquals(accountTagSqlDao.getTagsForAccountByKey(accountKey, internalCallContext).size(), 1); tagDao.tagRemoved(ObjectType.ACCOUNT, accountId, name, internalCallContext); Assert.assertEquals(accountTagSqlDao.getTagsForAccountByKey(accountKey, internalCallContext).size(), 0); }
@Test(groups = "slow") public void testAddAndRemoveTagsForBundle() throws Exception { final String name = UUID.randomUUID().toString().substring(0, 20); final String externalKey = UUID.randomUUID().toString(); final Account accountData = new MockAccountBuilder() .currency(Currency.MXN) .build(); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(accountData.getId()), Mockito.<InternalCallContext>any())).thenReturn(accountData); Mockito.when(accountInternalApi.getAccountByKey(Mockito.eq(accountData.getExternalKey()), Mockito.<InternalCallContext>any())).thenReturn(accountData); final UUID bundleId = UUID.randomUUID(); final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class); Mockito.when(bundle.getId()).thenReturn(bundleId); Mockito.when(bundle.getAccountId()).thenReturn(accountData.getId()); Mockito.when(bundle.getExternalKey()).thenReturn(externalKey); Mockito.when(entitlementInternalApi.getBundleFromId(Mockito.eq(bundleId), Mockito.<InternalCallContext>any())).thenReturn(bundle); Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransitionByKey(externalKey, internalCallContext).size(), 0); tagDao.tagAdded(ObjectType.BUNDLE, bundleId, name, internalCallContext); Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransitionByKey(externalKey, internalCallContext).size(), 1); tagDao.tagRemoved(ObjectType.BUNDLE, bundleId, name, internalCallContext); Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransitionByKey(externalKey, internalCallContext).size(), 0); } }
@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 BillingEvent createEvent(final SubscriptionBase sub, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final long totalOrdering) { final int billCycleDay = 1; final Plan shotgun = new MockPlan(); final PlanPhase shotgunMonthly = createMockMonthlyPlanPhase(null, BigDecimal.ZERO, PhaseType.TRIAL); final Account account = new MockAccountBuilder().build(); return new DefaultBillingEvent(account, sub, effectiveDate, shotgun, shotgunMonthly, BigDecimal.ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay, BillingModeType.IN_ADVANCE, "Test Event 1", totalOrdering, type, DateTimeZone.UTC); }
public MockAccountBuilder(final AccountData data) { this.id = UUID.randomUUID(); 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.email(data.getEmail()); this.externalKey(data.getExternalKey()); this.firstNameLength(data.getFirstNameLength()); this.isNotifiedForInvoices(data.isNotifiedForInvoices()); this.locale(data.getLocale()); this.migrated(data.isMigrated()); this.name(data.getName()); this.paymentMethodId(data.getPaymentMethodId()); this.phone(data.getPhone()); this.postalCode(data.getPostalCode()); this.stateOrProvince(data.getStateOrProvince()); this.timeZone(data.getTimeZone()); }
public AccountData initAccountData() { final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString()) .firstNameLength(6) .email(UUID.randomUUID().toString()) .phone(UUID.randomUUID().toString()) .migrated(false) .isNotifiedForInvoices(false) .externalKey(UUID.randomUUID().toString()) .billingCycleDayLocal(1) .currency(Currency.USD) .paymentMethodId(UUID.randomUUID()) .timeZone(DateTimeZone.forID("Europe/Paris")) .build(); assertNotNull(accountData); return accountData; }
@Test(groups = "fast") public void testFromAccount() throws Exception { final MockAccountBuilder accountBuilder = new MockAccountBuilder(); accountBuilder.address1(UUID.randomUUID().toString()); accountBuilder.address2(UUID.randomUUID().toString()); final int bcd = 4; accountBuilder.billingCycleDayLocal(bcd); accountBuilder.city(UUID.randomUUID().toString()); accountBuilder.companyName(UUID.randomUUID().toString()); accountBuilder.country(UUID.randomUUID().toString()); accountBuilder.currency(Currency.GBP); accountBuilder.email(UUID.randomUUID().toString()); accountBuilder.externalKey(UUID.randomUUID().toString()); accountBuilder.firstNameLength(12); accountBuilder.isNotifiedForInvoices(true); accountBuilder.locale(UUID.randomUUID().toString()); accountBuilder.migrated(true); accountBuilder.name(UUID.randomUUID().toString()); accountBuilder.paymentMethodId(UUID.randomUUID()); accountBuilder.phone(UUID.randomUUID().toString()); accountBuilder.postalCode(UUID.randomUUID().toString()); accountBuilder.stateOrProvince(UUID.randomUUID().toString()); accountBuilder.timeZone(DateTimeZone.UTC); final Account account = accountBuilder.build();
public Account createAccount(final CallContext callContext) throws AccountApiException { final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)) .firstNameLength(6) .email(UUID.randomUUID().toString().substring(1, 8)) .phone(UUID.randomUUID().toString().substring(1, 8)) .migrated(false) .isNotifiedForInvoices(true) .externalKey(UUID.randomUUID().toString().substring(1, 8)) .billingCycleDayLocal(31) .currency(accountCurrency) .paymentMethodId(UUID.randomUUID()) .timeZone(DateTimeZone.UTC) .build(); return accountUserApi.createAccount(accountData, callContext); }