Search in sources :

Example 1 with AuditLogModelDao

use of org.killbill.billing.util.audit.dao.AuditLogModelDao in project killbill by killbill.

the class TestDefaultAuditLog method testGetters.

@Test(groups = "fast")
public void testGetters() throws Exception {
    final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
    final long recordId = Long.MAX_VALUE;
    final ChangeType changeType = ChangeType.DELETE;
    final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
    final UUID tenantId = UUID.randomUUID();
    final String userName = UUID.randomUUID().toString();
    final CallOrigin callOrigin = CallOrigin.EXTERNAL;
    final UserType userType = UserType.CUSTOMER;
    final UUID userToken = UUID.randomUUID();
    final ClockMock clock = new ClockMock();
    final CallContext callContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock);
    final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID());
    Assert.assertEquals(auditLog.getChangeType(), changeType);
    Assert.assertNull(auditLog.getComment());
    Assert.assertNotNull(auditLog.getCreatedDate());
    Assert.assertNull(auditLog.getReasonCode());
    Assert.assertEquals(auditLog.getUserName(), userName);
    Assert.assertEquals(auditLog.getUserToken(), userToken.toString());
}
Also used : CallOrigin(org.killbill.billing.util.callcontext.CallOrigin) ClockMock(org.killbill.clock.ClockMock) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) EntityAudit(org.killbill.billing.util.dao.EntityAudit) TableName(org.killbill.billing.util.dao.TableName) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) UUID(java.util.UUID) UserType(org.killbill.billing.util.callcontext.UserType) Test(org.testng.annotations.Test)

Example 2 with AuditLogModelDao

use of org.killbill.billing.util.audit.dao.AuditLogModelDao in project killbill by killbill.

the class AuditLogModelDaoMapper method map.

@Override
public AuditLogModelDao map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException {
    final UUID id = getUUID(r, "id");
    final String tableName = r.getString("table_name");
    final long targetRecordId = r.getLong("target_record_id");
    final String changeType = r.getString("change_type");
    final DateTime createdDate = getDateTime(r, "created_date");
    final String createdBy = r.getString("created_by");
    final String reasonCode = r.getString("reason_code");
    final String comments = r.getString("comments");
    final UUID userToken = getUUID(r, "user_token");
    final EntityAudit entityAudit = new EntityAudit(id, TableName.valueOf(tableName), targetRecordId, ChangeType.valueOf(changeType), createdDate);
    // TODO - we have the tenant_record_id but not the tenant id here
    final CallContext callContext = new DefaultCallContext(null, createdBy, createdDate, reasonCode, comments, userToken);
    return new AuditLogModelDao(entityAudit, callContext);
}
Also used : DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) DateTime(org.joda.time.DateTime)

Example 3 with AuditLogModelDao

use of org.killbill.billing.util.audit.dao.AuditLogModelDao in project killbill by killbill.

the class TestAuditLogJson method testConstructor.

@Test(groups = "fast")
public void testConstructor() throws Exception {
    final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
    final long recordId = Long.MAX_VALUE;
    final ChangeType changeType = ChangeType.DELETE;
    final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
    final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID());
    final AuditLogJson auditLogJson = new AuditLogJson(auditLog);
    Assert.assertEquals(auditLogJson.getChangeType(), changeType.toString());
    Assert.assertNotNull(auditLogJson.getChangeDate());
    Assert.assertEquals(auditLogJson.getChangedBy(), callContext.getUserName());
    Assert.assertEquals(auditLogJson.getReasonCode(), callContext.getReasonCode());
    Assert.assertEquals(auditLogJson.getComments(), callContext.getComments());
    Assert.assertEquals(auditLogJson.getUserToken(), callContext.getUserToken().toString());
}
Also used : EntityAudit(org.killbill.billing.util.dao.EntityAudit) TableName(org.killbill.billing.util.dao.TableName) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) ChangeType(org.killbill.billing.util.audit.ChangeType) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) AuditLog(org.killbill.billing.util.audit.AuditLog) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) Test(org.testng.annotations.Test)

Example 4 with AuditLogModelDao

use of org.killbill.billing.util.audit.dao.AuditLogModelDao in project killbill by killbill.

the class TestDefaultAuditLog method testEquals.

@Test(groups = "fast")
public void testEquals() throws Exception {
    final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
    final long recordId = Long.MAX_VALUE;
    final ChangeType changeType = ChangeType.DELETE;
    final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
    final UUID tenantId = UUID.randomUUID();
    final String userName = UUID.randomUUID().toString();
    final CallOrigin callOrigin = CallOrigin.EXTERNAL;
    final UserType userType = UserType.CUSTOMER;
    final UUID userToken = UUID.randomUUID();
    final ClockMock clock = new ClockMock();
    final CallContext callContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock);
    final AuditLogModelDao auditLog = new AuditLogModelDao(entityAudit, callContext);
    Assert.assertEquals(auditLog, auditLog);
    final AuditLogModelDao sameAuditLog = new AuditLogModelDao(entityAudit, callContext);
    Assert.assertEquals(sameAuditLog, auditLog);
    clock.addMonths(1);
    final CallContext otherCallContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock);
    final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext);
    Assert.assertNotEquals(otherAuditLog, auditLog);
}
Also used : EntityAudit(org.killbill.billing.util.dao.EntityAudit) TableName(org.killbill.billing.util.dao.TableName) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) CallOrigin(org.killbill.billing.util.callcontext.CallOrigin) ClockMock(org.killbill.clock.ClockMock) UUID(java.util.UUID) UserType(org.killbill.billing.util.callcontext.UserType) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) Test(org.testng.annotations.Test)

Aggregations

AuditLogModelDao (org.killbill.billing.util.audit.dao.AuditLogModelDao)4 UUID (java.util.UUID)3 DefaultCallContext (org.killbill.billing.callcontext.DefaultCallContext)3 CallContext (org.killbill.billing.util.callcontext.CallContext)3 EntityAudit (org.killbill.billing.util.dao.EntityAudit)3 TableName (org.killbill.billing.util.dao.TableName)3 Test (org.testng.annotations.Test)3 CallOrigin (org.killbill.billing.util.callcontext.CallOrigin)2 UserType (org.killbill.billing.util.callcontext.UserType)2 ClockMock (org.killbill.clock.ClockMock)2 DateTime (org.joda.time.DateTime)1 AuditLog (org.killbill.billing.util.audit.AuditLog)1 ChangeType (org.killbill.billing.util.audit.ChangeType)1 DefaultAuditLog (org.killbill.billing.util.audit.DefaultAuditLog)1