From 2540dc721081a5e76cc1dda50d9ffe3e36b66f6c Mon Sep 17 00:00:00 2001 From: Reto Weiss Date: Thu, 22 Feb 2024 17:18:05 +0100 Subject: [PATCH] wip - add test for order process --- .../src_test/test/bpm/TestOrder.java | 72 +++++++++++++++++++ .../BusinessNotification/OrderProcess.p.json | 4 +- 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 workflow/workflow-demos-test/src_test/test/bpm/TestOrder.java diff --git a/workflow/workflow-demos-test/src_test/test/bpm/TestOrder.java b/workflow/workflow-demos-test/src_test/test/bpm/TestOrder.java new file mode 100644 index 000000000..e93d26d05 --- /dev/null +++ b/workflow/workflow-demos-test/src_test/test/bpm/TestOrder.java @@ -0,0 +1,72 @@ +package test.bpm; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import ch.ivyteam.ivy.bpm.engine.client.BpmClient; +import ch.ivyteam.ivy.bpm.engine.client.element.BpmElement; +import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; +import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; +import ch.ivyteam.ivy.environment.Ivy; +import ch.ivyteam.ivy.notification.impl.NotificationRepository; +import ch.ivyteam.ivy.notification.query.NotificationQuery; +import ch.ivyteam.ivy.scripting.objects.Tuple; +import ch.ivyteam.ivy.workflow.CaseState; +import workflow.order.Order; +import workflow.order.Person; + +@IvyProcessTest +public class TestOrder +{ + private static final BpmProcess ORDER_PROCESS = BpmProcess.name("OrderProcess"); + + private static final BpmElement START_ORDER = ORDER_PROCESS.elementName("startOrder"); + private static final BpmElement INPUT_ORDER = ORDER_PROCESS.elementName("Input Order"); + private static final BpmElement PROCESS_ORDER = ORDER_PROCESS.elementName("Process Order"); + private static final BpmElement DELIVER_ORDER = ORDER_PROCESS.elementName("Deliver Order"); + private static final BpmElement SEND_INVOICE = ORDER_PROCESS.elementName("Send Invoice"); + private static final BpmElement BOOK_PAYMENT = ORDER_PROCESS.elementName("Book Payment"); + + private static final Person CUSTOMER = new Person(); + private static final Order ORDER = new Order(); + + static { + CUSTOMER.setName("Doe"); + CUSTOMER.setSurname("John"); + ORDER.setProduct("Ferrari Testarossa"); + } + + @Test + void runProcess(BpmClient bpmClient) + { + bpmClient.mock().uiOf(INPUT_ORDER).with(this::inputOrder); + bpmClient.mock().uiOf(PROCESS_ORDER).withNoAction(); + bpmClient.mock().uiOf(DELIVER_ORDER).withNoAction(); + bpmClient.mock().uiOf(DELIVER_ORDER).withNoAction(); + bpmClient.mock().uiOf(SEND_INVOICE).withNoAction(); + bpmClient.mock().uiOf(BOOK_PAYMENT).withNoAction(); + + NotificationQuery nofiticationQuery = NotificationRepository.of(Ivy.wf().getSecurityContext()).query(); + var notifications = nofiticationQuery.executor().count(); + + var result = bpmClient.start().process(START_ORDER) + .as().everybody().execute(); + bpmClient.start().anyActiveTask(result).as().role("Processor").execute(); + bpmClient.start().anyActiveTask(result).as().role("Deliverer").execute(); + bpmClient.start().anyActiveTask(result).as().role("Finance").execute(); + bpmClient.start().anyActiveTask(result).as().role("Finance").execute(); + + assertThat(result.workflow().activeCase().getState()).isEqualTo(CaseState.DONE); + assertThat(nofiticationQuery.executor().count()).isEqualTo(notifications + 9); + } + + private void inputOrder(Tuple parameters, Tuple results) { + try { + results.set("customer", CUSTOMER); + results.set("order", ORDER); + } catch (NoSuchFieldException ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/workflow/workflow-demos/processes/BusinessNotification/OrderProcess.p.json b/workflow/workflow-demos/processes/BusinessNotification/OrderProcess.p.json index a3ebfb4b7..619c8099f 100644 --- a/workflow/workflow-demos/processes/BusinessNotification/OrderProcess.p.json +++ b/workflow/workflow-demos/processes/BusinessNotification/OrderProcess.p.json @@ -7,9 +7,9 @@ "elements" : [ { "id" : "f0", "type" : "RequestStart", - "name" : "start", + "name" : "startOrder", "config" : { - "signature" : "start", + "signature" : "startOrder", "request" : { "name" : "8.1 Business Notification", "category" : "notification",