Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIV-15265 Order Review Obligation Check Scheduler #1165

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_02cs6jr" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.26.0">
<bpmn:process id="ORDER_REVIEW_OBLIGATION_CHECK_SCHEDULER" name="Order Review Obligation check scheduler" isExecutable="true" camunda:historyTimeToLive="P90D">
<bpmn:sequenceFlow id="Flow_03at42s" sourceRef="StartEvent_1" targetRef="Activity_13h4s1i11" />
<bpmn:sequenceFlow id="Flow_1m5i8op" sourceRef="Activity_13h4s1i11" targetRef="Event_1ifnpoe" />
<bpmn:serviceTask id="Activity_13h4s1i11" name="Order Review Obligation Check scheduler" camunda:type="external" camunda:topic="ORDER_REVIEW_OBLIGATION_CHECK">
<bpmn:incoming>Flow_03at42s</bpmn:incoming>
<bpmn:outgoing>Flow_1m5i8op</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_03at42s</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_1oppfcm">
<bpmn:timeCycle xsi:type="bpmn:tFormalExpression">0 0 0 * * ?</bpmn:timeCycle>
kannan-v-hmcts marked this conversation as resolved.
Show resolved Hide resolved
</bpmn:timerEventDefinition>
</bpmn:startEvent>
<bpmn:endEvent id="Event_1ifnpoe">
<bpmn:incoming>Flow_1m5i8op</bpmn:incoming>
</bpmn:endEvent>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="ORDER_REVIEW_OBLIGATION_CHECK_SCHEDULER">
<bpmndi:BPMNShape id="Activity_1qred84_di" bpmnElement="Activity_13h4s1i11">
<dc:Bounds x="270" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0lbh5uj_di" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_034z4bv_di" bpmnElement="Event_1ifnpoe">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_03at42s_di" bpmnElement="Flow_03at42s">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1m5i8op_di" bpmnElement="Flow_1m5i8op">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package uk.gov.hmcts.reform.civil.bpmn;

import org.camunda.bpm.engine.externaltask.ExternalTask;
import org.camunda.bpm.engine.externaltask.LockedExternalTask;
import org.camunda.bpm.engine.impl.calendar.CronExpression;
import org.camunda.bpm.engine.management.JobDefinition;
import org.junit.jupiter.api.Test;

import java.text.ParseException;
import java.time.LocalDateTime;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;

class OrderReviewObligationCheckSchedulerTest extends BpmnBaseTest {

public static final String TOPIC_NAME = "ORDER_REVIEW_OBLIGATION_CHECK";

public OrderReviewObligationCheckSchedulerTest() {
super("order_review_obligation_check_scheduler.bpmn", "ORDER_REVIEW_OBLIGATION_CHECK_SCHEDULER");
}

@Test
void schedulerShouldRaiseOrderReviewObligationExternalTask_whenStarted() throws ParseException {
//assert process has started
assertFalse(processInstance.isEnded());

//assert topic names
assertThat(getTopics()).containsOnly(TOPIC_NAME);

//get jobs
List<JobDefinition> jobDefinitions = getJobs();

//assert that job is as expected
assertThat(jobDefinitions).hasSize(1);
assertThat(jobDefinitions.get(0).getJobType()).isEqualTo("timer-start-event");

String cronString = "0 0 0 * * ?";
assertThat(jobDefinitions.get(0).getJobConfiguration()).isEqualTo("CYCLE: " + cronString);
assertCronTriggerFiresAtExpectedTime(
new CronExpression(cronString),
LocalDateTime.of(2024, 11, 30, 0, 0, 0),
LocalDateTime.of(2024, 12, 1, 0, 0, 0)
);

//get external tasks
List<ExternalTask> externalTasks = getExternalTasks();
assertThat(externalTasks).hasSize(1);

//fetch and complete task
List<LockedExternalTask> lockedExternalTasks = fetchAndLockTask(TOPIC_NAME);

assertThat(lockedExternalTasks).hasSize(1);
completeTask(lockedExternalTasks.get(0).getId());

//assert no external tasks left
List<ExternalTask> externalTasksAfter = getExternalTasks();
assertThat(externalTasksAfter).isEmpty();

//assert process is still active - timer event, so always running
assertFalse(processInstance.isEnded());
}
}
Loading