Skip to content

Commit

Permalink
fix some spring boot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Sep 30, 2024
1 parent 13415b0 commit d6267f7
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
import org.kie.kogito.process.WorkItem;
import org.kie.kogito.testcontainers.quarkus.InfinispanQuarkusTestResource;
import org.kie.kogito.testcontainers.quarkus.KafkaQuarkusTestResource;
import org.kie.kogito.usertask.UserTaskInstance;
import org.kie.kogito.usertask.UserTasks;
import org.kie.kogito.usertask.impl.lifecycle.DefaultUserTaskLifeCycle;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
Expand All @@ -49,6 +52,7 @@
import jakarta.inject.Named;

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -76,6 +80,9 @@ public class TravelIT {

private ProcessInstance<?> processInstance;

@Inject
UserTasks userTasks;

@BeforeEach
public void cleanUp() {
abort(travelsProcess.instances());
Expand Down Expand Up @@ -128,17 +135,26 @@ private void whenNewTravel(Traveller traveller, Trip trip) {

private void whenConfirmTravel() {
WorkItem workItem = thenNextStepIs(STEP_CONFIRM_TRAVEL, SECURITY_POLICY_JDOE);
Map<String, Object> results = new HashMap<>();
results.put("approve", true);
processInstance.completeWorkItem(workItem.getId(), results, SECURITY_POLICY_JDOE);
assertThat(workItem).isNotNull();

List<UserTaskInstance> userTaskInstances = userTasks.instances().findByIdentity(IdentityProviders.of("jdoe"));
userTaskInstances.forEach(ut -> {
ut.setOutput("approve", true);
ut.transition(DefaultUserTaskLifeCycle.COMPLETE, Collections.emptyMap(), IdentityProviders.of("jdoe"));
});

}

private void whenAddVisaApplication() {
Map<String, Object> results = new HashMap<>();
results.put("visaApplication", new VisaApplication("Jan", "Kowalski", "New York", "US", 10, "XXX098765"));
results.put("visaResolution", new VisaResolution(true, "Test reason"));
WorkItem workItem = thenNextStepIs(STEP_VISA_APPLICATION, SECURITY_POLICY_JDOE);
processInstance.completeWorkItem(workItem.getId(), results, SECURITY_POLICY_JDOE);
assertThat(workItem).isNotNull();
List<UserTaskInstance> userTaskInstances = userTasks.instances().findByIdentity(IdentityProviders.of("jdoe"));
userTaskInstances.forEach(ut -> {
ut.setOutput("visaApplication", new VisaApplication("Jan", "Kowalski", "New York", "US", 10, "XXX098765"));
ut.setOutput("visaResolution", new VisaResolution(true, "Test reason"));
ut.transition(DefaultUserTaskLifeCycle.COMPLETE, Collections.emptyMap(), IdentityProviders.of("jdoe"));
});

}

private WorkItem thenNextStepIs(String expected, SecurityPolicy policy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ DMN]]></drools:metaValue>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>_38F4877F-50AD-4500-98E1-9B4FD3972291_TaskNameInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[Rest]]></bpmn2:from>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[Rest1]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[_38F4877F-50AD-4500-98E1-9B4FD3972291_TaskNameInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
Expand Down Expand Up @@ -228,7 +228,7 @@ DRL]]></drools:metaValue>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>_D8D9E6BA-5940-41F5-BF3A-1A08ADA72A4C_TaskNameInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[Rest]]></bpmn2:from>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[Rest2]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[_D8D9E6BA-5940-41F5-BF3A-1A08ADA72A4C_TaskNameInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" id="_T87XQVufEDiGNr1yTNojrQ" exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:itemDefinition id="_personItem" structureRef="org.kie.kogito.examples.demo.Person"/>
<bpmn2:itemDefinition id="_UserTask_1_SkippableInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_PriorityInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_CommentInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_DescriptionInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_CreatedByInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_TaskNameInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_GroupIdInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_ContentInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_NotStartedReassignInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_NotCompletedReassignInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_NotStartedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_NotCompletedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_1_personInputXItem" structureRef="org.kie.kogito.examples.demo.Person"/>
<bpmn2:itemDefinition id="_UserTask_2_SkippableInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_PriorityInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_CommentInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_DescriptionInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_CreatedByInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_TaskNameInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_GroupIdInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_ContentInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_NotStartedReassignInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_NotCompletedReassignInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_NotStartedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_NotCompletedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="_UserTask_2_personInputXItem" structureRef="org.kie.kogito.examples.demo.Person"/>
<bpmn2:itemDefinition id="_BusinessRuleTask_1_namespaceInputXItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_BusinessRuleTask_1_modelInputXItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_BusinessRuleTask_1_personsInputXItem" structureRef="org.kie.kogito.examples.demo.Person"/>
Expand All @@ -21,10 +21,10 @@
<bpmn2:property id="person" itemSubjectRef="_personItem" name="person"/>
<bpmn2:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="BusinessRuleTask_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_2" sourceRef="BusinessRuleTask_1" targetRef="ExclusiveGateway_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="ExclusiveGateway_1" targetRef="UserTask_1">
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="ExclusiveGateway_1" targetRef="UserTask_2">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression" language="http://www.java.com/java"><![CDATA[return person.isAdult() == false;]]></bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="SequenceFlow_4" sourceRef="UserTask_1" targetRef="EndEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_4" sourceRef="UserTask_2" targetRef="EndEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_5" sourceRef="ExclusiveGateway_1" targetRef="EndEvent_2">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression" language="http://www.java.com/java"><![CDATA[return person.isAdult() == true;]]></bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
Expand Down Expand Up @@ -73,7 +73,7 @@
<bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing>
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:userTask id="UserTask_1" name="Special handling for children">
<bpmn2:userTask id="UserTask_2" name="Special handling for children">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Special handling for children]]></drools:metaValue>
Expand All @@ -82,40 +82,40 @@
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
<bpmn2:ioSpecification>
<bpmn2:dataInput id="UserTask_1_TaskNameInputX" drools:dtype="Object" itemSubjectRef="_UserTask_1_TaskNameInputXItem" name="TaskName"/>
<bpmn2:dataInput id="UserTask_1_personInputX" drools:dtype="org.kie.kogito.examples.demo.Person" itemSubjectRef="_UserTask_1_personInputXItem" name="person"/>
<bpmn2:dataInput id="UserTask_1_SkippableInputX" drools:dtype="Object" itemSubjectRef="_UserTask_1_SkippableInputXItem" name="Skippable"/>
<bpmn2:dataInput id="UserTask_1_PriorityInputX" drools:dtype="Object" itemSubjectRef="_UserTask_1_PriorityInputXItem" name="Priority"/>
<bpmn2:dataInput id="UserTask_2_TaskNameInputX" drools:dtype="Object" itemSubjectRef="_UserTask_2_TaskNameInputXItem" name="TaskName"/>
<bpmn2:dataInput id="UserTask_2_personInputX" drools:dtype="org.kie.kogito.examples.demo.Person" itemSubjectRef="_UserTask_2_personInputXItem" name="person"/>
<bpmn2:dataInput id="UserTask_2_SkippableInputX" drools:dtype="Object" itemSubjectRef="_UserTask_2_SkippableInputXItem" name="Skippable"/>
<bpmn2:dataInput id="UserTask_2_PriorityInputX" drools:dtype="Object" itemSubjectRef="_UserTask_2_PriorityInputXItem" name="Priority"/>
<bpmn2:inputSet>
<bpmn2:dataInputRefs>UserTask_1_TaskNameInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_1_personInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_1_SkippableInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_1_PriorityInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_2_TaskNameInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_2_personInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_2_SkippableInputX</bpmn2:dataInputRefs>
<bpmn2:dataInputRefs>UserTask_2_PriorityInputX</bpmn2:dataInputRefs>
</bpmn2:inputSet>
</bpmn2:ioSpecification>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>UserTask_1_TaskNameInputX</bpmn2:targetRef>
<bpmn2:targetRef>UserTask_2_TaskNameInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[ChildrenHandling]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[UserTask_1_TaskNameInputX]]></bpmn2:to>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[UserTask_2_TaskNameInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
<bpmn2:dataInputAssociation>
<bpmn2:sourceRef>person</bpmn2:sourceRef>
<bpmn2:targetRef>UserTask_1_personInputX</bpmn2:targetRef>
<bpmn2:targetRef>UserTask_2_personInputX</bpmn2:targetRef>
</bpmn2:dataInputAssociation>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>UserTask_1_SkippableInputX</bpmn2:targetRef>
<bpmn2:targetRef>UserTask_2_SkippableInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[true]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[UserTask_1_SkippableInputX]]></bpmn2:to>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[UserTask_2_SkippableInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
<bpmn2:dataInputAssociation>
<bpmn2:targetRef>UserTask_1_PriorityInputX</bpmn2:targetRef>
<bpmn2:targetRef>UserTask_2_PriorityInputX</bpmn2:targetRef>
<bpmn2:assignment>
<bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[1]]></bpmn2:from>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[UserTask_1_PriorityInputX]]></bpmn2:to>
<bpmn2:to xsi:type="bpmn2:tFormalExpression"><![CDATA[UserTask_2_PriorityInputX]]></bpmn2:to>
</bpmn2:assignment>
</bpmn2:dataInputAssociation>
<bpmn2:potentialOwner id="_T9Kn0FufEDiGNr1yTNojrQ">
Expand Down Expand Up @@ -149,7 +149,7 @@
<bpmndi:BPMNShape id="shape_EndEvent_1" bpmnElement="EndEvent_1">
<dc:Bounds height="56" width="56" x="810" y="102"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape_UserTask_1" bpmnElement="UserTask_1">
<bpmndi:BPMNShape id="shape_UserTask_2" bpmnElement="UserTask_2">
<dc:Bounds height="83" width="160" x="561" y="88"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape_ExclusiveGateway_1" bpmnElement="ExclusiveGateway_1">
Expand All @@ -166,11 +166,11 @@
<di:waypoint x="480" y="243"/>
<di:waypoint x="810" y="233"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape_UserTask_1_to_shape_EndEvent_1" bpmnElement="SequenceFlow_4">
<bpmndi:BPMNEdge id="edge_shape_UserTask_2_to_shape_EndEvent_1" bpmnElement="SequenceFlow_4">
<di:waypoint x="721" y="129.5"/>
<di:waypoint x="810" y="120"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape_ExclusiveGateway_1_to_shape_UserTask_1" bpmnElement="SequenceFlow_3">
<bpmndi:BPMNEdge id="edge_shape_ExclusiveGateway_1_to_shape_UserTask_2" bpmnElement="SequenceFlow_3">
<di:waypoint x="502" y="127"/>
<di:waypoint x="561" y="129.5"/>
</bpmndi:BPMNEdge>
Expand All @@ -189,7 +189,7 @@
<bpsim:BPSimData>
<bpsim:Scenario id="default" name="Simulationscenario">
<bpsim:ScenarioParameters/>
<bpsim:ElementParameters elementRef="UserTask_1">
<bpsim:ElementParameters elementRef="UserTask_2">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kie.kogito.Model;
import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.auth.IdentityProviders;
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.examples.DemoApplication;
Expand All @@ -36,6 +37,9 @@
import org.kie.kogito.process.WorkItem;
import org.kie.kogito.testcontainers.springboot.InfinispanSpringBootTestResource;
import org.kie.kogito.testcontainers.springboot.KafkaSpringBootTestResource;
import org.kie.kogito.usertask.UserTaskInstance;
import org.kie.kogito.usertask.UserTasks;
import org.kie.kogito.usertask.impl.lifecycle.DefaultUserTaskLifeCycle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -62,6 +66,9 @@ public class OrdersProcessIT {
@Qualifier("demo.orderItems")
Process<? extends Model> orderItemsProcess;

@Autowired
UserTasks userTasks;

private SecurityPolicy policy = SecurityPolicy.of(IdentityProviders.of("john", Collections.singletonList("managers")));

@Test
Expand All @@ -86,9 +93,12 @@ public void testOrderProcess() {

ProcessInstance<?> childProcessInstance = getFirst(orderItemProcesses);

List<WorkItem> workItems = childProcessInstance.workItems(policy);
assertEquals(1, workItems.size());
childProcessInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
IdentityProvider johnUser = IdentityProviders.of("john", Collections.singletonList("managers"));
List<UserTaskInstance> userTaskInstances = userTasks.instances().findByIdentity(johnUser);
userTaskInstances.forEach(ut -> {
ut.transition(DefaultUserTaskLifeCycle.COMPLETE, Collections.emptyMap(), johnUser);
});


assertEquals(ProcessInstance.STATE_COMPLETED, childProcessInstance.status());
Optional<?> pi = orderProcess.instances().findById(processInstance.id());
Expand Down Expand Up @@ -133,7 +143,11 @@ public void testOrderProcessWithError() {
List<WorkItem> workItems = childProcessInstance.workItems(policy);
assertEquals(1, workItems.size());

childProcessInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
IdentityProvider johnUser = IdentityProviders.of("john", Collections.singletonList("managers"));
List<UserTaskInstance> userTaskInstances = userTasks.instances().findByIdentity(johnUser);
userTaskInstances.forEach(ut -> {
ut.transition(DefaultUserTaskLifeCycle.COMPLETE, Collections.emptyMap(), johnUser);
});

assertEquals(ProcessInstance.STATE_COMPLETED, childProcessInstance.status());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.status());
Expand Down
Loading

0 comments on commit d6267f7

Please sign in to comment.