Search in sources :

Example 1 with DefaultAccountAuditLogs

use of org.killbill.billing.util.audit.DefaultAccountAuditLogs in project killbill by killbill.

the class TestAccountDao method testAudits.

@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);
}
Also used : DefaultAccountAuditLogs(org.killbill.billing.util.audit.DefaultAccountAuditLogs) Test(org.testng.annotations.Test)

Example 2 with DefaultAccountAuditLogs

use of org.killbill.billing.util.audit.DefaultAccountAuditLogs in project killbill by killbill.

the class DefaultAuditDao method getAuditLogsForAccountRecordId.

@Override
public DefaultAccountAuditLogs getAuditLogsForAccountRecordId(final AuditLevel auditLevel, final InternalTenantContext context) {
    final UUID accountId = nonEntitySqlDao.getIdFromObject(context.getAccountRecordId(), TableName.ACCOUNT.getTableName());
    // Lazy evaluate records to minimize the memory footprint (these can yield a lot of results)
    // We usually always want to wrap our queries in an EntitySqlDaoTransactionWrapper... except here.
    // Since we want to stream the results out, we don't want to auto-commit when this method returns.
    final EntitySqlDao auditSqlDao = transactionalSqlDao.onDemandForStreamingResults(EntitySqlDao.class);
    final Iterator<AuditLogModelDao> auditLogsForAccountRecordId = auditSqlDao.getAuditLogsForAccountRecordId(context);
    final Iterator<AuditLog> allAuditLogs = buildAuditLogsFromModelDao(auditLogsForAccountRecordId, context);
    return new DefaultAccountAuditLogs(accountId, auditLevel, allAuditLogs);
}
Also used : EntitySqlDao(org.killbill.billing.util.entity.dao.EntitySqlDao) NonEntitySqlDao(org.killbill.billing.util.dao.NonEntitySqlDao) DefaultAccountAuditLogs(org.killbill.billing.util.audit.DefaultAccountAuditLogs) UUID(java.util.UUID) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) AuditLog(org.killbill.billing.util.audit.AuditLog)

Aggregations

DefaultAccountAuditLogs (org.killbill.billing.util.audit.DefaultAccountAuditLogs)2 UUID (java.util.UUID)1 AuditLog (org.killbill.billing.util.audit.AuditLog)1 DefaultAuditLog (org.killbill.billing.util.audit.DefaultAuditLog)1 NonEntitySqlDao (org.killbill.billing.util.dao.NonEntitySqlDao)1 EntitySqlDao (org.killbill.billing.util.entity.dao.EntitySqlDao)1 Test (org.testng.annotations.Test)1