Search in sources :

Example 1 with RAuditEventRecord

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();
    }
}
Also used : Query(org.hibernate.Query) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) Session(org.hibernate.Session)

Example 2 with RAuditEventRecord

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();
    }
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) Query(org.hibernate.Query) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) SystemException(com.evolveum.midpoint.util.exception.SystemException) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Session(org.hibernate.Session)

Example 3 with RAuditEventRecord

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);
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) Calendar(java.util.Calendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 4 with RAuditEventRecord

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));
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) Calendar(java.util.Calendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

RAuditEventRecord (com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)2 Calendar (java.util.Calendar)2 Query (org.hibernate.Query)2 Session (org.hibernate.Session)2 Test (org.testng.annotations.Test)2 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 Date (java.util.Date)1 Duration (javax.xml.datatype.Duration)1