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);
}
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));
}
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;
}
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;
}
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));
}
Aggregations