Search in sources :

Example 6 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType 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 7 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType 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)

Example 8 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class CleanupTest method createPolicy.

private CleanupPolicyType createPolicy(int maxRecords) throws Exception {
    CleanupPolicyType policy = new CleanupPolicyType();
    policy.setMaxRecords(Integer.valueOf(maxRecords));
    return policy;
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)

Example 9 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class CleanupTest method createPolicy.

private CleanupPolicyType createPolicy(Calendar when, long now) throws Exception {
    CleanupPolicyType policy = new CleanupPolicyType();
    Duration duration = createDuration(when, now);
    policy.setMaxAge(duration);
    return policy;
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Duration(javax.xml.datatype.Duration)

Example 10 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class CleanupTest method testTasksCleanup.

@Test
public void testTasksCleanup() throws Exception {
    // GIVEN
    final File file = new File(FOLDER_REPO, "tasks-for-cleanup.xml");
    List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(file).parseObjects();
    OperationResult result = new OperationResult("tasks cleanup");
    for (PrismObject<? extends Objectable> object : elements) {
        String oid = repositoryService.addObject((PrismObject) object, null, result);
        AssertJUnit.assertTrue(StringUtils.isNotEmpty(oid));
    }
    // WHEN
    // because now we can't move system time (we're not using DI for it) we create policy
    // which should always point to 2013-05-07T12:00:00.000+02:00
    final long NOW = System.currentTimeMillis();
    Calendar when = create_2013_07_12_12_00_Calendar();
    CleanupPolicyType policy = createPolicy(when, NOW);
    taskManager.cleanupTasks(policy, taskManager.createTaskInstance(), result);
    // THEN
    List<PrismObject<TaskType>> tasks = repositoryService.searchObjects(TaskType.class, null, null, result);
    AssertJUnit.assertNotNull(tasks);
    display("tasks", tasks);
    AssertJUnit.assertEquals(1, tasks.size());
    PrismObject<TaskType> task = tasks.get(0);
    XMLGregorianCalendar timestamp = task.getPropertyRealValue(TaskType.F_COMPLETION_TIMESTAMP, XMLGregorianCalendar.class);
    Date finished = XMLGregorianCalendarType.asDate(timestamp);
    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) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration) Date(java.util.Date) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Objectable(com.evolveum.midpoint.prism.Objectable) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)11 Duration (javax.xml.datatype.Duration)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 Date (java.util.Date)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Calendar (java.util.Calendar)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 Test (org.testng.annotations.Test)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)2 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 com.evolveum.midpoint.repo.sql.data.audit (com.evolveum.midpoint.repo.sql.data.audit)2 RAuditEventRecord (com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord)2 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)2 BaseHelper (com.evolveum.midpoint.repo.sql.helpers.BaseHelper)2 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)2 GetObjectResult (com.evolveum.midpoint.repo.sql.util.GetObjectResult)2