@Test(groups = "slow", description = "Test Account: verify minimal set of required fields") public void testMinimalFields() throws Exception { final String email = UUID.randomUUID().toString(); final String name = UUID.randomUUID().toString(); final AccountData accountData = new DefaultMutableAccountData(null, email, name, 0, null, null, false, 0, null, clock.getUTCNow(), null, null, null, null, null, null, null, null, null, null, null, false); final AccountModelDao account = new AccountModelDao(UUID.randomUUID(), accountData); accountDao.create(account, internalCallContext); final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext); checkAccountsEqual(retrievedAccount, account); // Verify a default external key was set Assert.assertEquals(retrievedAccount.getExternalKey(), retrievedAccount.getId().toString()); // Verify a default time zone was set Assert.assertEquals(retrievedAccount.getTimeZone(), DateTimeZone.UTC); }
@Test(groups = "slow", description = "Test Account DAO: payment method update") public void testUpdatePaymentMethod() throws Exception { final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); final UUID newPaymentMethodId = UUID.randomUUID(); accountDao.updatePaymentMethod(account.getId(), newPaymentMethodId, internalCallContext); final AccountModelDao newAccount = accountDao.getById(account.getId(), internalCallContext); Assert.assertEquals(newAccount.getPaymentMethodId(), newPaymentMethodId); // And then set it to null (delete the default payment method) accountDao.updatePaymentMethod(account.getId(), null, internalCallContext); final AccountModelDao newAccountWithPMNull = accountDao.getById(account.getId(), internalCallContext); Assert.assertNull(newAccountWithPMNull.getPaymentMethodId()); }
@Test(groups = "slow", description = "Test Account DAO: BCD of 0") public void testShouldBeAbleToHandleBCDOfZero() throws Exception { final AccountModelDao account = createTestAccount(0); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); // Same BCD (zero) final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext); checkAccountsEqual(retrievedAccount, account); }
@Test(groups = "slow", description = "Test Account DAO: basic update (2)") public void testShouldBeAbleToUpdateSomeFields() throws Exception { final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); final MutableAccountData otherAccount = new DefaultAccount(account).toMutableAccountData(); otherAccount.setAddress1(UUID.randomUUID().toString()); otherAccount.setEmail(UUID.randomUUID().toString()); final AccountModelDao newAccount = new AccountModelDao(account.getId(), otherAccount); accountDao.update(newAccount, true, internalCallContext); final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext); checkAccountsEqual(retrievedAccount, newAccount); }
@Test(groups = "slow", description = "Test Account: basic DAO calls") public void testBasic() throws AccountApiException { final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); // Retrieve by key AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); checkAccountsEqual(retrievedAccount, account); // Retrieve by id retrievedAccount = accountDao.getById(retrievedAccount.getId(), internalCallContext); checkAccountsEqual(retrievedAccount, account); // Retrieve all final Pagination<AccountModelDao> allAccounts = accountDao.getAll(internalCallContext); final List<AccountModelDao> all = ImmutableList.<AccountModelDao>copyOf(allAccounts); Assert.assertNotNull(all); Assert.assertEquals(all.size(), 1); checkAccountsEqual(all.get(0), account); // Verify audits final List<AuditLog> auditLogsForAccount = auditDao.getAuditLogsForId(TableName.ACCOUNT, account.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsForAccount.size(), 1); Assert.assertEquals(auditLogsForAccount.get(0).getChangeType(), ChangeType.INSERT); }