Search in sources :

Example 26 with Objectable

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));
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) StringUtils(org.apache.commons.lang.StringUtils) AssertJUnit(org.testng.AssertJUnit) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) DatatypeFactory(javax.xml.datatype.DatatypeFactory) Calendar(java.util.Calendar) Duration(javax.xml.datatype.Duration) PrismContext(com.evolveum.midpoint.prism.PrismContext) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) TimeZone(java.util.TimeZone) Objectable(com.evolveum.midpoint.prism.Objectable) PrismObject.cast(com.evolveum.midpoint.prism.PrismObject.cast) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collectors(java.util.stream.Collectors) File(java.io.File) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) List(java.util.List) ContextConfiguration(org.springframework.test.context.ContextConfiguration) 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) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Objectable(com.evolveum.midpoint.prism.Objectable) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Test(org.testng.annotations.Test)

Aggregations

Objectable (com.evolveum.midpoint.prism.Objectable)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 File (java.io.File)9 Test (org.testng.annotations.Test)9 PrismContext (com.evolveum.midpoint.prism.PrismContext)6 Node (org.w3c.dom.Node)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 Task (com.evolveum.midpoint.task.api.Task)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)3 Validator (com.evolveum.midpoint.common.validator.Validator)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 Element (org.w3c.dom.Element)3 PageDescriptor (com.evolveum.midpoint.authentication.api.authorization.PageDescriptor)2 Url (com.evolveum.midpoint.authentication.api.authorization.Url)2 WebModelServiceUtils (com.evolveum.midpoint.gui.api.util.WebModelServiceUtils)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2