use of com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord in project midpoint by Evolveum.
the class CleanupTest method assertAndReturnAuditEventRecord.
private RAuditEventRecord assertAndReturnAuditEventRecord(OperationResult result) {
AssertJUnit.assertTrue(result.isSuccess());
Session session = getFactory().openSession();
try {
session.beginTransaction();
Query query = session.createQuery("from " + RAuditEventRecord.class.getSimpleName());
List<RAuditEventRecord> records = query.list();
AssertJUnit.assertEquals(1, records.size());
session.getTransaction().commit();
return records.get(0);
} finally {
session.close();
}
}
use of com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord in project midpoint by Evolveum.
the class AuditTest method getAuditEventRecord.
private AuditEventRecord getAuditEventRecord(int expectedCount, int index) {
Session session = getFactory().openSession();
try {
session.beginTransaction();
Query query = session.createQuery("from " + RAuditEventRecord.class.getSimpleName() + " order by id");
List<RAuditEventRecord> records = query.list();
assertEquals(expectedCount, records.size());
AuditEventRecord eventRecord = RAuditEventRecord.fromRepo(records.get(index), prismContext);
session.getTransaction().commit();
return eventRecord;
} catch (DtoTranslationException e) {
throw new SystemException(e);
} finally {
session.close();
}
}
use of com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord in project midpoint by Evolveum.
the class CleanupTest method testAuditCleanupMaxRecords.
@Test
public void testAuditCleanupMaxRecords() throws Exception {
//GIVEN
prepareAuditEventRecords();
//WHEN
Calendar calendar = create_2013_07_12_12_00_Calendar();
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.add(Calendar.MINUTE, 1);
final long NOW = System.currentTimeMillis();
CleanupPolicyType policy = createPolicy(1);
OperationResult result = new OperationResult("Cleanup audit");
auditService.cleanupAudit(policy, result);
result.recomputeStatus();
//THEN
RAuditEventRecord record = assertAndReturnAuditEventRecord(result);
}
use of com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord in project midpoint by Evolveum.
the class CleanupTest method testAuditCleanupMaxAge.
@Test
public void testAuditCleanupMaxAge() throws Exception {
//GIVEN
prepareAuditEventRecords();
//WHEN
Calendar calendar = create_2013_07_12_12_00_Calendar();
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.add(Calendar.MINUTE, 1);
final long NOW = System.currentTimeMillis();
CleanupPolicyType policy = createPolicy(calendar, NOW);
OperationResult result = new OperationResult("Cleanup audit");
auditService.cleanupAudit(policy, result);
result.recomputeStatus();
//THEN
RAuditEventRecord record = assertAndReturnAuditEventRecord(result);
Date finished = new Date(record.getTimestamp().getTime());
Date mark = new Date(NOW);
Duration duration = policy.getMaxAge();
duration.addTo(mark);
AssertJUnit.assertTrue("finished: " + finished + ", mark: " + mark, finished.after(mark));
}
Aggregations