|
1 | 1 | package com.jongsoft.finance.bpmn;
|
2 | 2 |
|
| 3 | +import com.jongsoft.finance.bpmn.process.ProcessExtension; |
| 4 | +import com.jongsoft.finance.bpmn.process.RuntimeContext; |
3 | 5 | import com.jongsoft.finance.schedule.Periodicity;
|
4 |
| -import jakarta.inject.Inject; |
| 6 | +import org.apache.commons.lang3.mutable.MutableObject; |
5 | 7 | import org.assertj.core.api.Assertions;
|
6 |
| -import org.camunda.bpm.engine.ProcessEngine; |
| 8 | +import org.junit.jupiter.api.DisplayName; |
7 | 9 | import org.junit.jupiter.api.Test;
|
8 | 10 |
|
9 | 11 | import java.time.LocalDate;
|
10 | 12 | import java.time.ZoneId;
|
11 | 13 | import java.util.Date;
|
12 | 14 | import java.util.Map;
|
13 | 15 |
|
14 |
| -class ProcessSchedulerIT extends ProcessTestSetup { |
15 |
| - |
16 |
| - @Inject |
17 |
| - private ProcessEngine processEngine; |
| 16 | +@ProcessExtension |
| 17 | +@DisplayName("Process Scheduler feature") |
| 18 | +class ProcessSchedulerIT { |
18 | 19 |
|
19 | 20 | @Test
|
20 |
| - void runSchedule() { |
21 |
| - var process = processEngine.getRuntimeService().createProcessInstanceByKey("ProcessScheduler") |
22 |
| - .setVariable("subProcess", "EmptyProcess") |
23 |
| - .setVariable("start", "2019-01-02") |
24 |
| - .setVariable("end", LocalDate.now().plusMonths(5).toString()) |
25 |
| - .setVariable("interval", 3) |
26 |
| - .setVariable("periodicity", Periodicity.MONTHS) |
27 |
| - .execute(); |
28 |
| - |
29 |
| - waitForSuspended(processEngine, process.getProcessInstanceId()); |
30 |
| - |
31 |
| - var subProcess = processEngine.getHistoryService() |
32 |
| - .createHistoricProcessInstanceQuery() |
33 |
| - .processDefinitionKey("EmptyProcess") |
34 |
| - .list(); |
35 |
| - |
36 |
| - Assertions.assertThat(subProcess).isEmpty(); |
| 21 | + @DisplayName("Run a schedule, not yet due") |
| 22 | + void runSchedule(RuntimeContext context) { |
| 23 | + var execution = context.execute("ProcessScheduler", Map.of( |
| 24 | + "subProcess", "EmptyProcess", |
| 25 | + "start", "2019-01-02", |
| 26 | + "end", LocalDate.now().plusMonths(5).toString(), |
| 27 | + "interval", 3, |
| 28 | + "periodicity", Periodicity.MONTHS |
| 29 | + )); |
| 30 | + |
| 31 | + execution.verifyPendingActivity("scheduled_wait"); |
37 | 32 | }
|
38 | 33 |
|
39 | 34 |
|
40 | 35 | @Test
|
41 |
| - void runSchedule_forceRun() throws InterruptedException { |
42 |
| - var process = processEngine.getRuntimeService().createProcessInstanceByKey("ProcessScheduler") |
43 |
| - .setVariable("subProcess", "EmptyProcess") |
44 |
| - .setVariable("start", "2019-01-02") |
45 |
| - .setVariable("end", LocalDate.now().plusYears(1).toString()) |
46 |
| - .setVariable("interval", 3) |
47 |
| - .setVariable("periodicity", Periodicity.MONTHS) |
48 |
| - .setVariable("EmptyProcess", Map.of("subProcess-1", 1, "variable-2", "test")) |
49 |
| - .execute(); |
50 |
| - |
51 |
| - waitForSuspended(processEngine, process.getProcessInstanceId()); |
52 |
| - |
53 |
| - var nextRun = processEngine.getHistoryService() |
54 |
| - .createHistoricVariableInstanceQuery() |
55 |
| - .processDefinitionKey("ProcessScheduler") |
56 |
| - .processInstanceId(process.getProcessInstanceId()) |
57 |
| - .variableName("nextRun") |
58 |
| - .singleResult(); |
59 |
| - |
60 |
| - var jobs = processEngine.getManagementService() |
61 |
| - .createJobQuery() |
62 |
| - .processInstanceId(process.getProcessInstanceId()) |
63 |
| - .singleResult(); |
64 |
| - |
65 |
| - processEngine.getManagementService() |
66 |
| - .executeJob(jobs.getId()); |
67 |
| - |
68 |
| - waitForSuspended(processEngine, process.getProcessInstanceId()); |
69 |
| - |
70 |
| - var subProcess = processEngine.getHistoryService() |
71 |
| - .createHistoricProcessInstanceQuery() |
72 |
| - .processDefinitionKey("EmptyProcess") |
73 |
| - .singleResult(); |
74 |
| - |
75 |
| - Assertions.assertThat(subProcess).isNotNull(); |
76 |
| - |
77 |
| - var variableCount = processEngine.getHistoryService() |
78 |
| - .createHistoricVariableInstanceQuery() |
79 |
| - .processDefinitionKey("EmptyProcess") |
80 |
| - .count(); |
81 |
| - |
82 |
| - var scheduled = processEngine.getHistoryService() |
83 |
| - .createHistoricVariableInstanceQuery() |
84 |
| - .processDefinitionKey("EmptyProcess") |
85 |
| - .variableName("scheduled") |
86 |
| - .singleResult(); |
87 |
| - |
88 |
| - var var1 = processEngine.getHistoryService() |
89 |
| - .createHistoricVariableInstanceQuery() |
90 |
| - .processDefinitionKey("EmptyProcess") |
91 |
| - .variableName("subProcess-1") |
92 |
| - .singleResult(); |
93 |
| - |
94 |
| - Assertions.assertThat(variableCount).isEqualTo(4); |
95 |
| - Assertions.assertThat(var1.getValue()).isEqualTo(1); |
96 |
| - Assertions.assertThat(scheduled.getValue()).isEqualTo(LocalDate.ofInstant(((Date)nextRun.getValue()).toInstant(), |
97 |
| - ZoneId.systemDefault()).toString()); |
| 36 | + @DisplayName("Run a schedule, force run to trigger next iteration") |
| 37 | + void runSchedule_forceRun(RuntimeContext context) throws InterruptedException { |
| 38 | + var execution = context.execute("ProcessScheduler", Map.of( |
| 39 | + "subProcess", "EmptyProcess", |
| 40 | + "start", "2019-01-02", |
| 41 | + "end", LocalDate.now().plusYears(1).toString(), |
| 42 | + "interval", 3, |
| 43 | + "periodicity", Periodicity.MONTHS, |
| 44 | + "EmptyProcess", Map.of("subProcess-1", 1, "variable-2", "test") |
| 45 | + )); |
| 46 | + |
| 47 | + MutableObject<Date> nextRun = new MutableObject<>(); |
| 48 | + MutableObject<String> scheduled = new MutableObject<>(); |
| 49 | + MutableObject<Integer> subValue = new MutableObject<>(); |
| 50 | + |
| 51 | + execution |
| 52 | + .verifyPendingActivity("scheduled_wait") |
| 53 | + .yankVariable("nextRun", nextRun::setValue) |
| 54 | + .forceJob("scheduled_wait") |
| 55 | + .verifyPendingActivity("scheduled_wait") |
| 56 | + .obtainChildProcess("EmptyProcess") |
| 57 | + .yankVariable("scheduled", scheduled::setValue) |
| 58 | + .yankVariable("subProcess-1", subValue::setValue) |
| 59 | + .verifyCompleted(); |
| 60 | + |
| 61 | + Assertions.assertThat(subValue.getValue()).isEqualTo(1); |
| 62 | + Assertions.assertThat(scheduled.getValue()) |
| 63 | + .isEqualTo( |
| 64 | + LocalDate.ofInstant( |
| 65 | + nextRun.getValue().toInstant(), |
| 66 | + ZoneId.systemDefault()).toString()); |
98 | 67 | }
|
99 | 68 |
|
100 |
| - |
101 | 69 | }
|
0 commit comments