protected Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException { final AccountModelDao accountModelDao = accountDao.getAccountByKey(key, context); if (accountModelDao == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, key); } final Account account = new DefaultAccount(accountModelDao); final Long recordId = nonEntityDao.retrieveRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, recordIdCacheController); accountCacheController.putIfAbsent(recordId, new DefaultImmutableAccountData(account)); return account; }
final AccountModelDao account = accountDao.getAccountByKey(externalKey, tenantContext); Assert.assertEquals(account.getExternalKey(), externalKey); Assert.assertEquals(account.getEmail(), email);
@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: 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); }
refreshCallContext(account.getId()); final AccountModelDao createdAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); List<AuditLogWithHistory> auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(account.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(auditLogsWithHistory.size(), 1); accountDao.update(updatedAccount, true, internalCallContext); final AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); checkAccountsEqual(retrievedAccount, updatedAccount); auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount.getId(), AuditLevel.FULL, internalCallContext); accountDao.update(updatedAccount2, true, internalCallContext); final AccountModelDao retrievedAccount2 = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext); checkAccountsEqual(retrievedAccount2, updatedAccount2); auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount2.getId(), AuditLevel.FULL, internalCallContext);
protected Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException { final AccountModelDao accountModelDao = accountDao.getAccountByKey(key, context); if (accountModelDao == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, key); } final Account account = new DefaultAccount(accountModelDao); final Long recordId = nonEntityDao.retrieveRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, recordIdCacheController); accountCacheController.putIfAbsent(recordId, new DefaultImmutableAccountData(account)); return account; }