@Test(groups = "slow", description = "Test Account DAO: retrieve by externalKey") public void testGetIdFromKey() throws AccountApiException { final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); final UUID accountId = accountDao.getIdFromKey(account.getExternalKey(), internalCallContext); Assert.assertEquals(accountId, account.getId()); }
@Test(groups = "slow", description = "Test Account DAO: long numbers") public void testLongPhoneNumber() throws AccountApiException { final AccountModelDao account = createTestAccount("123456789012345678901234"); accountDao.create(account, internalCallContext); refreshCallContext(account.getId()); final AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); checkAccountsEqual(retrievedAccount, account); }
@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: verify audits") public void testAudits() throws AccountApiException { // Special test to verify audits - they are handled a bit differently due to the account record id (see EntitySqlDaoWrapperInvocationHandler#insertAudits) final AccountModelDao account1 = createTestAccount(); accountDao.create(account1, internalCallContext); refreshCallContext(account1.getId()); // Verify audits via account record id final DefaultAccountAuditLogs auditLogsForAccount1ViaAccountRecordId1 = auditDao.getAuditLogsForAccountRecordId(AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsForAccount1ViaAccountRecordId1.getAuditLogsForAccount().size(), 1); Assert.assertEquals(auditLogsForAccount1ViaAccountRecordId1.getAuditLogsForAccount().get(0).getChangeType(), ChangeType.INSERT); // Add an entry in the account_history table to make sure we pick up the right // record id / target record id / account record id in the audit_log table accountDao.updatePaymentMethod(account1.getId(), UUID.randomUUID(), internalCallContext); final AccountModelDao account2 = createTestAccount(); accountDao.create(account2, internalCallContext); refreshCallContext(account2.getId()); // Verify audits via account record id final DefaultAccountAuditLogs auditLogsForAccount2ViaAccountRecordId = auditDao.getAuditLogsForAccountRecordId(AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsForAccount2ViaAccountRecordId.getAuditLogsForAccount().size(), 1); Assert.assertEquals(auditLogsForAccount2ViaAccountRecordId.getAuditLogsForAccount().get(0).getChangeType(), ChangeType.INSERT); refreshCallContext(account1.getId()); final DefaultAccountAuditLogs auditLogsForAccount1ViaAccountRecordId2 = auditDao.getAuditLogsForAccountRecordId(AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsForAccount1ViaAccountRecordId2.getAuditLogsForAccount().size(), 2); Assert.assertEquals(auditLogsForAccount1ViaAccountRecordId2.getAuditLogsForAccount().get(0).getChangeType(), ChangeType.INSERT); Assert.assertEquals(auditLogsForAccount1ViaAccountRecordId2.getAuditLogsForAccount().get(1).getChangeType(), ChangeType.UPDATE); }
@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); }
@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 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()); }
final AccountModelDao account = createTestAccount(); accountDao.create(account, internalCallContext); refreshCallContext(account.getId());