@Test(groups = "fast") public void testDefaultBigDecimalValues() throws Exception { final Account account = Mockito.mock(Account.class); final BusinessAccountModelDao bac = new BusinessAccountModelDao(account); Assert.assertEquals(bac.getBalance(), BigDecimal.ZERO); Assert.assertEquals(bac.getTotalInvoiceBalance(), BigDecimal.ZERO); bac.setBalance(BigDecimal.ONE); bac.setTotalInvoiceBalance(BigDecimal.TEN); Assert.assertEquals(bac.getBalance(), BigDecimal.ONE); Assert.assertEquals(bac.getTotalInvoiceBalance(), BigDecimal.TEN); } }
public void bind(final SQLStatement q, final BusinessAccountBinder bind, final BusinessAccountModelDao account) { final DateTime dateTimeNow = new DateTime(DateTimeZone.UTC); if (account.getCreatedDate() != null) { q.bind("created_date", account.getCreatedDate().getMillis()); } else { q.bind("created_date", dateTimeNow.getMillis()); } if (account.getUpdatedDate() != null) { q.bind("updated_date", account.getUpdatedDate().getMillis()); } else { q.bind("updated_date", dateTimeNow.getMillis()); } q.bind("account_id", account.getAccountId().toString()); q.bind("account_key", account.getKey()); q.bind("balance", account.getRoundedBalance()); q.bind("name", account.getName()); if (account.getLastInvoiceDate() != null) { q.bind("last_invoice_date", account.getLastInvoiceDate().toDate()); } else { q.bindNull("last_invoice_date", Types.DATE); } q.bind("total_invoice_balance", account.getRoundedTotalInvoiceBalance()); q.bind("last_payment_status", account.getLastPaymentStatus()); q.bind("payment_method", account.getPaymentMethod()); q.bind("credit_card_type", account.getCreditCardType()); q.bind("billing_address_country", account.getBillingAddressCountry()); q.bind("currency", account.getCurrency()); } };
public DefaultBusinessAccount(final BusinessAccountModelDao businessAccountModelDao) { this.externalKey = businessAccountModelDao.getKey(); this.name = businessAccountModelDao.getName(); this.currency = businessAccountModelDao.getCurrency(); this.balance = businessAccountModelDao.getBalance(); this.lastInvoiceDate = businessAccountModelDao.getLastInvoiceDate(); this.totalInvoiceBalance = businessAccountModelDao.getTotalInvoiceBalance(); this.lastPaymentStatus = businessAccountModelDao.getLastPaymentStatus(); this.defaultPaymentMethodType = businessAccountModelDao.getPaymentMethod(); this.defaultCreditCardType = businessAccountModelDao.getCreditCardType(); this.defaultBillingAddressCountry = businessAccountModelDao.getBillingAddressCountry(); }
public BusinessAccountModelDao createBusinessAccountFromAccount(final Account account, final InternalTenantContext context) { final BusinessAccountModelDao bac = new BusinessAccountModelDao(account); LocalDate lastInvoiceDate = bac.getLastInvoiceDate(); BigDecimal totalInvoiceBalance = bac.getTotalInvoiceBalance(); String lastPaymentStatus = bac.getLastPaymentStatus(); String paymentMethodType = bac.getPaymentMethod(); String creditCardType = bac.getCreditCardType(); String billingAddressCountry = bac.getBillingAddressCountry(); bac.setLastPaymentStatus(lastPaymentStatus); bac.setPaymentMethod(paymentMethodType); bac.setCreditCardType(creditCardType); bac.setBillingAddressCountry(billingAddressCountry); bac.setLastInvoiceDate(lastInvoiceDate); bac.setTotalInvoiceBalance(totalInvoiceBalance); bac.setBalance(invoiceApi.getAccountBalance(account.getId(), context)); } catch (PaymentApiException ex) { log.error(String.format("Failed to handle account update for account %s", account.getId()), ex);
@Test(groups = "slow") public void testCreateSaveAndRetrieveAccounts() { // Create and retrieve an account accountSqlDao.createAccount(account, internalCallContext); final BusinessAccountModelDao foundAccount = accountSqlDao.getAccountByKey(ACCOUNT_KEY, internalCallContext); Assert.assertEquals(foundAccount.getCreatedDate().getMillis(), account.getCreatedDate().getMillis()); Assert.assertEquals(foundAccount.getUpdatedDate().getMillis(), account.getUpdatedDate().getMillis()); Assert.assertTrue(foundAccount.equals(account)); // Try to update the account account.setBalance(BigDecimal.TEN); account.setPaymentMethod("PayPal"); account.setCurrency("CAD"); accountSqlDao.saveAccount(account, internalCallContext); // Verify the save worked as expected account = accountSqlDao.getAccountByKey(ACCOUNT_KEY, internalCallContext); Assert.assertEquals(Rounder.round(BigDecimal.TEN), account.getRoundedBalance()); Assert.assertEquals("PayPal", account.getPaymentMethod()); Assert.assertEquals("CAD", account.getCurrency()); // ACCOUNT not found Assert.assertNull(accountSqlDao.getAccountByKey("Doesn't exist", internalCallContext)); } }
@Override public BusinessAccountModelDao map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException { return new BusinessAccountModelDao( UUID.fromString(r.getString(1)), r.getString(2), r.getString(6), BigDecimal.valueOf(r.getDouble(5)), getDate(r, "last_invoice_date"), BigDecimal.valueOf(r.getDouble(8)), r.getString(9), r.getString(10), r.getString(11), r.getString(12), r.getString(13), new DateTime(r.getLong(3), DateTimeZone.UTC), new DateTime(r.getLong(4), DateTimeZone.UTC) ); } }
@Test(groups = "fast") public void testEquals() throws Exception { Assert.assertSame(account, account); Assert.assertEquals(account, account); Assert.assertTrue(account.equals(account)); final BusinessAccountModelDao otherAccount = new BusinessAccountModelDao(UUID.randomUUID(), "pierre cardin", UUID.randomUUID().toString(), BigDecimal.ONE, clock.getUTCToday(), BigDecimal.TEN, "ERROR_NOT_ENOUGH_FUNDS", "CreditCard", "Visa", "", UUID.randomUUID().toString(), clock.getUTCNow(), clock.getUTCNow()); Assert.assertFalse(account.equals(otherAccount)); }
@Override public Boolean call() throws Exception { // Test invoice integration - the account creation notification has triggered a BAC update return (accountSqlDao.getAccountByKey(ACCOUNT_KEY, internalCallContext).getTotalInvoiceBalance().compareTo(INVOICE_AMOUNT) == 0); } });
@BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); account = new BusinessAccountModelDao(UUID.randomUUID(), "pierre", UUID.randomUUID().toString(), BigDecimal.ONE, clock.getUTCToday(), BigDecimal.TEN, "ERROR_NOT_ENOUGH_FUNDS", "CreditCard", "Visa", "", UUID.randomUUID().toString(), clock.getUTCNow(), clock.getUTCNow()); }
private void setupBusinessAccount() { account = new BusinessAccountModelDao(UUID.randomUUID(), ACCOUNT_KEY, UUID.randomUUID().toString(), BigDecimal.ONE, clock.getUTCToday(), BigDecimal.TEN, "ERROR_NOT_ENOUGH_FUNDS", "CreditCard", "Visa", "FRANCE", CURRENCY, clock.getUTCNow(), clock.getUTCNow()); }
@Test(groups = "mysql") public void testAccountsCreatedOverTime() throws Exception { final BusinessAccountModelDao account = new BusinessAccountModelDao(UUID.randomUUID(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), BigDecimal.ONE, clock.getUTCToday(), BigDecimal.TEN, "ERROR_NOT_ENOUGH_FUNDS", "CreditCard", "Visa", "FRANCE", "USD", clock.getUTCNow(), clock.getUTCNow()); accountSqlDao.createAccount(account, internalCallContext); final TimeSeriesData data = analyticsUserApi.getAccountsCreatedOverTime(callContext); Assert.assertEquals(data.getDates().size(), 1); Assert.assertEquals(data.getDates().get(0), clock.getUTCToday()); Assert.assertEquals(data.getValues().size(), 1); Assert.assertEquals(data.getValues().get(0), (double) 1); }