use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class CleanupTest method testTasksCleanup.
@Test
public void testTasksCleanup() throws Exception {
given();
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(TASKS_FOR_CLEANUP).parseObjects();
OperationResult result = new OperationResult("tasks cleanup");
for (PrismObject<? extends Objectable> object : elements) {
String oid = repositoryService.addObject(cast(object, ObjectType.class), 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 threshold = create_2013_05_07_12_00_00_Calendar();
CleanupPolicyType policy = createPolicy(threshold, NOW);
taskManager.cleanupTasks(policy, t -> true, taskManager.createFakeRunningTask(taskManager.createTaskInstance()), result);
then();
List<PrismObject<TaskType>> tasks = repositoryService.searchObjects(TaskType.class, null, null, result);
AssertJUnit.assertNotNull(tasks);
displayValue("tasks", tasks);
AssertJUnit.assertEquals(2, tasks.size());
var indestructible = tasks.stream().filter(t -> Boolean.TRUE.equals(t.asObjectable().isIndestructible())).collect(Collectors.toList());
assertThat(indestructible).as("indestructible tasks left").hasSize(1);
var nonIndestructible = tasks.stream().filter(t -> !Boolean.TRUE.equals(t.asObjectable().isIndestructible())).collect(Collectors.toList());
assertThat(nonIndestructible).as("non-indestructible tasks left").hasSize(1);
PrismObject<TaskType> task = nonIndestructible.get(0);
XMLGregorianCalendar timestamp = task.getPropertyRealValue(TaskType.F_COMPLETION_TIMESTAMP, XMLGregorianCalendar.class);
Date finished = timestamp.toGregorianCalendar().getTime();
Date mark = new Date(NOW);
Duration duration = policy.getMaxAge();
duration.addTo(mark);
AssertJUnit.assertTrue("finished: " + finished + ", mark: " + mark, finished.after(mark));
}
Aggregations