1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.inner;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23
24 import java.time.OffsetDateTime;
25 import java.util.List;
26 import org.apache.syncope.common.lib.types.ExecStatus;
27 import org.apache.syncope.common.lib.types.TaskType;
28 import org.apache.syncope.core.persistence.api.dao.TaskDAO;
29 import org.apache.syncope.core.persistence.api.dao.TaskExecDAO;
30 import org.apache.syncope.core.persistence.api.entity.task.PropagationTask;
31 import org.apache.syncope.core.persistence.api.entity.task.TaskExec;
32 import org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory;
33 import org.apache.syncope.core.persistence.jpa.AbstractTest;
34 import org.apache.syncope.core.provisioning.api.utils.FormatUtils;
35 import org.junit.jupiter.api.Test;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.transaction.annotation.Transactional;
38
39 @Transactional("Master")
40 public class TaskExecTest extends AbstractTest {
41
42 @Autowired
43 private TaskExecDAO taskExecDAO;
44
45 @Autowired
46 private TaskDAO taskDAO;
47
48 @Autowired
49 private TaskUtilsFactory taskUtilsFactory;
50
51 @Test
52 public void findAll() {
53 PropagationTask task = taskDAO.find(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c");
54 assertNotNull(task);
55
56 OffsetDateTime startedBefore = OffsetDateTime.of(2015, 12, 18, 0, 0, 0, 0, FormatUtils.DEFAULT_OFFSET);
57
58 List<TaskExec<?>> execs = taskExecDAO.findAll(task, startedBefore, null, -1, -1, List.of());
59 assertNotNull(execs);
60 assertEquals(1, execs.size());
61 }
62
63 @Test
64 public void findLatestStarted() {
65 PropagationTask task = taskDAO.find(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c");
66 assertNotNull(task);
67
68 TaskExec<?> latestStarted = taskExecDAO.findLatestStarted(TaskType.PROPAGATION, task);
69 assertNotNull(latestStarted);
70 assertEquals("e58ca1c7-178a-4012-8a71-8aa14eaf0655", latestStarted.getKey());
71 }
72
73 @Test
74 public void issueSYNCOPE214() {
75 PropagationTask task = taskDAO.find(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c");
76 assertNotNull(task);
77
78 String faultyMessage = "A faulty message";
79 faultyMessage = faultyMessage.replace('a', '\0');
80
81 TaskExec<PropagationTask> exec = taskUtilsFactory.getInstance(TaskType.PROPAGATION).newTaskExec();
82 exec.setStart(OffsetDateTime.now());
83 exec.setEnd(OffsetDateTime.now());
84 exec.setStatus(ExecStatus.SUCCESS.name());
85 exec.setMessage(faultyMessage);
86 exec.setExecutor("admin");
87
88 task.add(exec);
89 exec.setTask(task);
90
91 exec = taskExecDAO.save(exec);
92 assertNotNull(exec);
93
94 assertEquals(faultyMessage.replace('\0', '\n'), exec.getMessage());
95 }
96 }