use of com.evolveum.midpoint.repo.sqale.audit.qmodel.QAuditEventRecord in project midpoint by Evolveum.
the class AuditCleanupTest method test102CleanupByZeroCount.
@Test
public void test102CleanupByZeroCount() throws SchemaException {
given("audit has 100 records");
OperationResult operationResult = createOperationResult();
prepareAuditRecords(System.currentTimeMillis(), 100, operationResult);
QAuditEventRecord qae = QAuditEventRecordMapping.get().defaultAlias();
when("audit cleanup is called to leave 0 records");
int recordsToLeave = 0;
auditService.cleanupAudit(new CleanupPolicyType().maxRecords(recordsToLeave), operationResult);
then("operation is success and everything is deleted");
assertThatOperationResult(operationResult).isSuccess();
assertCount(qae, 0);
}
use of com.evolveum.midpoint.repo.sqale.audit.qmodel.QAuditEventRecord in project midpoint by Evolveum.
the class AuditCleanupTest method test100CleanupByCount.
// These tests rely on uninterrupted ID series, but cleanup works even with holes
@Test
public void test100CleanupByCount() throws SchemaException {
given("audit has 100 records");
OperationResult operationResult = createOperationResult();
prepareAuditRecords(System.currentTimeMillis(), 100, operationResult);
QAuditEventRecord qae = QAuditEventRecordMapping.get().defaultAlias();
long maxId = selectMinMaxId(qae, qae.id.max());
when("audit cleanup is called to leave 50 records");
int recordsToLeave = 50;
auditService.cleanupAudit(new CleanupPolicyType().maxRecords(recordsToLeave), operationResult);
then("operation is success and only 50 records are left");
assertThatOperationResult(operationResult).isSuccess();
assertCount(qae, recordsToLeave);
long minId = selectMinMaxId(qae, qae.id.min());
// top IDs are left, that is the newest records
assertThat(maxId - minId).isEqualTo(recordsToLeave - 1);
}
use of com.evolveum.midpoint.repo.sqale.audit.qmodel.QAuditEventRecord in project midpoint by Evolveum.
the class AuditCleanupTest method test200CleanupByAge.
@Test
public void test200CleanupByAge() throws SchemaException {
given("audit has 100 records across the last 100s");
OperationResult operationResult = createOperationResult();
long startTimestamp = System.currentTimeMillis() - 100_000;
prepareAuditRecords(startTimestamp, 100, operationResult);
QAuditEventRecord qae = QAuditEventRecordMapping.get().defaultAlias();
when("audit cleanup is called to leave just last 1 minute");
auditService.cleanupAudit(new CleanupPolicyType().maxAge(XmlTypeConverter.createDuration("PT1M")), operationResult);
then("operation is success and only the last minute of records are left");
assertThatOperationResult(operationResult).isSuccess();
// it's probably 59, some time passed between last audit and the cleanup call
assertThat(count(qae)).isLessThanOrEqualTo(60).isGreaterThan(// but something should be there, this is extreme 5s leeway
55);
assertThat(count(qae, qae.timestamp.lt(Instant.ofEpochMilli(startTimestamp + 40_000)))).isZero();
}
use of com.evolveum.midpoint.repo.sqale.audit.qmodel.QAuditEventRecord in project midpoint by Evolveum.
the class AuditCleanupTest method test101CleanupByHighCount.
@Test
public void test101CleanupByHighCount() throws SchemaException {
given("audit has 100 records");
OperationResult operationResult = createOperationResult();
prepareAuditRecords(System.currentTimeMillis(), 100, operationResult);
QAuditEventRecord qae = QAuditEventRecordMapping.get().defaultAlias();
when("audit cleanup is called to leave 150 records");
int recordsToLeave = 150;
auditService.cleanupAudit(new CleanupPolicyType().maxRecords(recordsToLeave), operationResult);
then("operation is success and nothing is deleted");
assertThatOperationResult(operationResult).isSuccess();
// original count
assertCount(qae, 100);
}
Aggregations