public static DateTimeZone getFixedOffsetTimeZone(final Account account) { return getFixedOffsetTimeZone(account.getTimeZone(), account.getReferenceTime()); }
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); }
currentAccount.getTimeZone() != null && !currentAccount.getTimeZone().equals(timeZone)) { throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account timeZone yet: new=%s, current=%s", timeZone, currentAccount.getTimeZone()));
public DefaultImmutableAccountData(final Account account) { this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone(), AccountDateTimeUtils.getFixedOffsetTimeZone(account), account.getReferenceTime()); }
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException { final UUID accountId = UUID.randomUUID(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final Invoice invoice = Mockito.mock(Invoice.class); Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice); Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN); Mockito.when(invoice.getStatus()).thenReturn(InvoiceStatus.COMMITTED); Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID()); final InvoiceItem item = Mockito.mock(InvoiceItem.class); final List<InvoiceItem> items = new ArrayList<InvoiceItem>(); items.add(item); Mockito.when(invoice.getInvoiceItems()).thenReturn(items); final List<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(invoice); Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); final Tag tag = Mockito.mock(Tag.class); Mockito.when(tag.getObjectId()).thenReturn(accountId); Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT); Mockito.when(tag.getTagDefinitionId()).thenReturn(ControlTagType.TEST.getId()); final List<Tag> tags = new ArrayList<Tag>(); tags.add(tag); Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())) .thenReturn(tags); return account; }
@Test(groups = "fast", description = "Test if Account constructor can accept null values") public void testConstructorAcceptsNullValues() throws Exception { final AccountData accountData = getNullAccountData(); final Account account = new DefaultAccount(UUID.randomUUID(), accountData); Assert.assertNull(account.getExternalKey()); Assert.assertNull(account.getEmail()); Assert.assertNull(account.getName()); Assert.assertNull(account.getFirstNameLength()); Assert.assertNull(account.getCurrency()); Assert.assertEquals(account.getBillCycleDayLocal(), (Integer) 0); Assert.assertNull(account.getPaymentMethodId()); Assert.assertNull(account.getTimeZone()); Assert.assertNull(account.getLocale()); Assert.assertNull(account.getAddress1()); Assert.assertNull(account.getAddress2()); Assert.assertNull(account.getCompanyName()); Assert.assertNull(account.getCity()); Assert.assertNull(account.getStateOrProvince()); Assert.assertNull(account.getCountry()); Assert.assertNull(account.getPostalCode()); Assert.assertNull(account.getPhone()); Assert.assertNull(account.isMigrated()); }
private void checkAccountEquals(final Account finalAccount, final Account delegateAccount) { Assert.assertEquals(finalAccount.getExternalKey(), delegateAccount.getExternalKey()); Assert.assertEquals(finalAccount.getEmail(), delegateAccount.getEmail()); Assert.assertEquals(finalAccount.getName(), delegateAccount.getName()); Assert.assertEquals(finalAccount.getFirstNameLength(), delegateAccount.getFirstNameLength()); Assert.assertEquals(finalAccount.getCurrency(), delegateAccount.getCurrency()); Assert.assertEquals(finalAccount.getBillCycleDayLocal(), delegateAccount.getBillCycleDayLocal()); Assert.assertEquals(finalAccount.getPaymentMethodId(), delegateAccount.getPaymentMethodId()); Assert.assertEquals(finalAccount.getTimeZone(), delegateAccount.getTimeZone()); Assert.assertEquals(finalAccount.getLocale(), delegateAccount.getLocale()); Assert.assertEquals(finalAccount.getAddress1(), delegateAccount.getAddress1()); Assert.assertEquals(finalAccount.getAddress2(), delegateAccount.getAddress2()); Assert.assertEquals(finalAccount.getCompanyName(), delegateAccount.getCompanyName()); Assert.assertEquals(finalAccount.getCity(), delegateAccount.getCity()); Assert.assertEquals(finalAccount.getStateOrProvince(), delegateAccount.getStateOrProvince()); Assert.assertEquals(finalAccount.getCountry(), delegateAccount.getCountry()); Assert.assertEquals(finalAccount.getPostalCode(), delegateAccount.getPostalCode()); Assert.assertEquals(finalAccount.getPhone(), delegateAccount.getPhone()); Assert.assertEquals(finalAccount.getNotes(), delegateAccount.getNotes()); Assert.assertEquals(finalAccount.isMigrated(), delegateAccount.isMigrated()); }
Assert.assertEquals(updatedAccount2.getBillCycleDayLocal(), updatedAccount1.getBillCycleDayLocal()); Assert.assertEquals(updatedAccount2.getPaymentMethodId(), updatedAccount1.getPaymentMethodId()); Assert.assertEquals(updatedAccount2.getTimeZone(), updatedAccount1.getTimeZone()); Assert.assertEquals(updatedAccount2.getLocale(), updatedAccount1.getLocale()); Assert.assertEquals(updatedAccount2.getAddress1(), updatedAccount1.getAddress1());
Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency()); Assert.assertEquals(retrievedAccount.getPaymentMethodId(), account.getPaymentMethodId()); Assert.assertEquals(retrievedAccount.getTimeZone(), account.getTimeZone()); Assert.assertEquals(retrievedAccount.getLocale(), account.getLocale()); Assert.assertEquals(retrievedAccount.getAddress1(), account.getAddress1());
accountData.setTimeZone(timeZone != null ? timeZone : currentAccount.getTimeZone()); accountData.setLocale(locale != null ? locale : currentAccount.getLocale()); accountData.setAddress1(address1 != null ? address1 : currentAccount.getAddress1());
protected LocalDate toLocalDateDefaultToday(final Account account, @Nullable final String inputDate, final TenantContext context) { // TODO Switch to cached normalized timezone when available return MoreObjects.firstNonNull(toLocalDate(inputDate), clock.getToday(account.getTimeZone())); }
public static DateTimeZone getFixedOffsetTimeZone(final Account account) { return getFixedOffsetTimeZone(account.getTimeZone(), account.getReferenceTime()); }
public DefaultImmutableAccountData(final Account account) { this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone(), AccountDateTimeUtils.getFixedOffsetTimeZone(account), account.getReferenceTime()); }
public static Account buildAccount(final Currency currency, final String address1, final String address2, final String city, final String stateOrProvince, final String postalCode, final String country) { final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getExternalKey()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getFirstNameLength()).thenReturn(4); Mockito.when(account.getEmail()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getBillCycleDayLocal()).thenReturn(2); Mockito.when(account.getCurrency()).thenReturn(currency); Mockito.when(account.getPaymentMethodId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.getDefault()); // Return language tag to be able to use Locale.forLanguageTag Mockito.when(account.getLocale()).thenReturn("en-US"); Mockito.when(account.getAddress1()).thenReturn(address1); Mockito.when(account.getAddress2()).thenReturn(address2); Mockito.when(account.getCompanyName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(account.getCity()).thenReturn(city); Mockito.when(account.getStateOrProvince()).thenReturn(stateOrProvince); Mockito.when(account.getPostalCode()).thenReturn(postalCode); Mockito.when(account.getCountry()).thenReturn(country); Mockito.when(account.getPhone()).thenReturn(UUID.randomUUID().toString().substring(0, 25)); Mockito.when(account.isMigrated()).thenReturn(true); Mockito.when(account.getCreatedDate()).thenReturn(new DateTime(2016, 1, 22, 10, 56, 47, DateTimeZone.UTC)); Mockito.when(account.getUpdatedDate()).thenReturn(new DateTime(2016, 1, 22, 10, 56, 48, DateTimeZone.UTC)); return account; }
@Test(groups = "slow") public void testCreateParentInvoice() throws InvoiceApiException { final UUID parentAccountId = UUID.randomUUID(); final UUID childAccountId = UUID.randomUUID(); final DateTime today = clock.getNow(account.getTimeZone()); InvoiceModelDao parentInvoice = new InvoiceModelDao(parentAccountId, today.toLocalDate(), account.getCurrency(), InvoiceStatus.DRAFT, true); InvoiceItem parentInvoiceItem = new ParentInvoiceItem(UUID.randomUUID(), today, parentInvoice.getId(), parentAccountId, childAccountId, BigDecimal.TEN, account.getCurrency(), ""); parentInvoice.addInvoiceItem(new InvoiceItemModelDao(parentInvoiceItem)); invoiceDao.createInvoices(ImmutableList.<InvoiceModelDao>of(parentInvoice), ImmutableSet.of(), context); final InvoiceModelDao parentDraftInvoice = invoiceDao.getParentDraftInvoice(parentAccountId, context); assertNotNull(parentDraftInvoice); assertEquals(parentDraftInvoice.getStatus(), InvoiceStatus.DRAFT); assertEquals(parentDraftInvoice.getInvoiceItems().size(), 1); }
Mockito.when(accountData.getBillCycleDayLocal()).thenReturn(1); Mockito.when(accountData.isMigrated()).thenReturn(false); Mockito.when(accountData.getTimeZone()).thenReturn(DateTimeZone.UTC); final DateTime utcNow = clock.getUTCNow(); Mockito.when(accountData.getCreatedDate()).thenReturn(utcNow);
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; } }
private void insertInvoiceItemAdjustmentToChildInvoice(final Account childAccount, final Invoice childInvoice, BigDecimal amount) throws InvoiceApiException { busHandler.pushExpectedEvents(NextEvent.INVOICE_ADJUSTMENT, NextEvent.INVOICE_ADJUSTMENT); invoiceUserApi.insertInvoiceItemAdjustment(childAccount.getId(), childInvoice.getId(), childInvoice.getInvoiceItems().get(0).getId(), clock.getToday(childAccount.getTimeZone()), amount, childAccount.getCurrency(), "test adjustment", null, null, callContext); assertListenerStatus(); }
public AccountJson(final Account account, final BigDecimal accountBalance, final BigDecimal accountCBA, @Nullable final AccountAuditLogs accountAuditLogs) { super(toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForAccount())); this.accountCBA = accountCBA; this.accountBalance = accountBalance; this.accountId = account.getId(); this.externalKey = account.getExternalKey(); this.name = account.getName(); this.firstNameLength = account.getFirstNameLength(); this.email = account.getEmail(); this.billCycleDayLocal = account.getBillCycleDayLocal(); this.currency = account.getCurrency(); this.parentAccountId = account.getParentAccountId(); this.isPaymentDelegatedToParent = account.isPaymentDelegatedToParent(); this.paymentMethodId = account.getPaymentMethodId(); this.referenceTime = account.getReferenceTime(); this.timeZone = account.getTimeZone() != null ? account.getTimeZone().toString() : null; this.address1 = account.getAddress1(); this.address2 = account.getAddress2(); this.postalCode = account.getPostalCode(); this.company = account.getCompanyName(); this.city = account.getCity(); this.state = account.getStateOrProvince(); this.country = account.getCountry(); this.locale = account.getLocale(); this.phone = account.getPhone(); this.notes = account.getNotes(); this.isMigrated = account.isMigrated(); }
@Test(groups = "slow") public void testUncancelEffectiveCancelledEntitlement() throws AccountApiException, EntitlementApiException, SubscriptionBaseApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); // Keep the same object for the whole test, to make sure we refresh its state before r/w calls testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDays(30); assertListenerStatus(); subscriptionInternalApi.setChargedThroughDate(entitlement.getId(), clock.getUTCNow().plusMonths(1), internalCallContext); final LocalDate entitlementCancelledDate = clock.getToday(account.getTimeZone()); testListener.pushExpectedEvent(NextEvent.BLOCK); final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithDateOverrideBillingPolicy(clock.getToday(account.getTimeZone()), BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); Assert.assertEquals(cancelledEntitlement.getEffectiveEndDate(), entitlementCancelledDate); testListener.pushExpectedEvent(NextEvent.UNCANCEL); cancelledEntitlement.uncancelEntitlement(ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement reactivatedEntitlement = entitlementApi.getEntitlementForId(cancelledEntitlement.getId(), callContext); Assert.assertNull(reactivatedEntitlement.getEffectiveEndDate()); }