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

RHPAM-4296: Test case #2144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jbpm-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
<artifactId>jbpm-workitems-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-workitems-rest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-db-scripts</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2017 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jbpm.test.functional.workitem;

import java.util.HashMap;

import org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler;
import org.kie.api.runtime.process.WorkItem;
import org.kie.api.runtime.process.WorkItemManager;
import org.kie.api.runtime.process.ProcessWorkItemHandlerException;

public class MockRestWorkItemHandler extends AbstractLogOrThrowWorkItemHandler {

public MockRestWorkItemHandler() {
this.handlingProcessId = null;
this.handlingStrategy = null;
}

public MockRestWorkItemHandler(String handlingProcessId,
String handlingStrategy) {
this.handlingProcessId = handlingProcessId;
this.handlingStrategy = handlingStrategy;
}

@Override
public void executeWorkItem( WorkItem workItem, WorkItemManager manager ) {
String urlStr = (String) workItem.getParameter("Url");
if ("https://www.google.com/".equals(urlStr)) {
manager.completeWorkItem(workItem.getId(), new HashMap<String, Object>());
} else {
handleException(new RuntimeException("Mock REST exception"));
}
}

@Override
public void abortWorkItem( WorkItem workItem, WorkItemManager manager ) {
// TODO Auto-generated method stub

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jbpm.test.functional.workitem;

import java.util.HashMap;
import java.util.Map;
import org.assertj.core.api.Assertions;
import org.jbpm.process.workitem.rest.RESTWorkItemHandler;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.workflow.instance.WorkflowRuntimeException;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.api.runtime.process.ProcessWorkItemHandlerException.HandlingStrategy;
import org.kie.internal.runtime.manager.context.ProcessInstanceIdContext;

public class WorkItemExceptionHandlingMultipleWIHRetryTest extends JbpmTestCase {

private static final String FAILING_PROCESS_ID = "ParentProcessMultipleRestWIH";
private static final String EXCEPTION_HANDLING_PROCESS_ID = "ExceptionHandlingProcess";

public WorkItemExceptionHandlingMultipleWIHRetryTest() {
super( true, true );
}

@Test
public void exceptionHandlingAbortProcessWithOneWIH() {
KieSession kieSession = createSession();

kieSession.getWorkItemManager().registerWorkItemHandler( "Rest", new RESTWorkItemHandler(getClass().getClassLoader(), EXCEPTION_HANDLING_PROCESS_ID, HandlingStrategy.RETRY.name()) );
Map<String, Object> params = new HashMap<String, Object>();
params.put("path", "one");

ProcessInstance pi = kieSession.startProcess( FAILING_PROCESS_ID, params );
assertProcessInstanceActive( pi.getId(), kieSession );

try {
kieSession.signalEvent("moveon", null);
} catch(Exception ex) {
}

kieSession.abortProcessInstance(pi.getId());
assertProcessInstanceAborted( pi.getId() );
}

@Test
public void exceptionHandlingAbortProcessWithTwoWIH() {
KieSession kieSession = createSession();

kieSession.getWorkItemManager().registerWorkItemHandler( "Rest", new RESTWorkItemHandler(getClass().getClassLoader(), EXCEPTION_HANDLING_PROCESS_ID, HandlingStrategy.RETRY.name()) );
Map<String, Object> params = new HashMap<String, Object>();
params.put("path", "two");

ProcessInstance pi = kieSession.startProcess( FAILING_PROCESS_ID, params );
assertProcessInstanceActive( pi.getId(), kieSession );

try {
kieSession.signalEvent("moveon", null);
} catch(Exception ex) {
}

kieSession.abortProcessInstance(pi.getId());
assertProcessInstanceAborted( pi.getId() );
}


@Test
public void exceptionHandlingAbortProcessWithTwoMockRestWIH() {
KieSession kieSession = createSession();

kieSession.getWorkItemManager().registerWorkItemHandler( "Rest", new MockRestWorkItemHandler(EXCEPTION_HANDLING_PROCESS_ID, HandlingStrategy.RETRY.name()) );
Map<String, Object> params = new HashMap<String, Object>();
params.put("path", "two");

ProcessInstance pi = kieSession.startProcess( FAILING_PROCESS_ID, params );
assertProcessInstanceActive( pi.getId(), kieSession );

try {
kieSession.signalEvent("moveon", null);
} catch(Exception ex) {
}

kieSession.abortProcessInstance(pi.getId());
assertProcessInstanceAborted( pi.getId() );
}

private KieSession createSession() {
manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, (String) null,
"org/jbpm/test/functional/workitem/ParentProcessMultipleRestWIH.bpmn",
"org/jbpm/test/functional/workitem/ExceptionHandlingProcess.bpmn"
);
RuntimeEngine runtimeEngine = getRuntimeEngine( ProcessInstanceIdContext.get() );
KieSession kieSession = runtimeEngine.getKieSession();
return kieSession;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions 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" xmlns:xsi="xsi" id="_BBLdMK7KEDqmbu_5GyFVGg" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:process id="ExceptionHandlingProcess" drools:packageName="com" drools:version="1.0" drools:adHoc="false" name="ExceptionHandlingProcess" isExecutable="true" processType="Public">
<bpmn2:sequenceFlow id="_5C8A83E2-9171-480D-BCAB-6C9ABF89F7A4" sourceRef="_A05B52C4-58FF-4771-B31B-A921C6217018" targetRef="_0B9CCB8E-F8F2-4349-B9E7-30AB978A9DDA">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.target">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="_6DB5E2A8-6AC8-4774-A642-619C0FD53213" sourceRef="_DA57E66C-2AAB-4B59-8FAF-947DA53901B2" targetRef="_A05B52C4-58FF-4771-B31B-A921C6217018">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.source">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
<drools:metaData name="isAutoConnection.target">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
<bpmn2:startEvent id="_DA57E66C-2AAB-4B59-8FAF-947DA53901B2">
<bpmn2:outgoing>_6DB5E2A8-6AC8-4774-A642-619C0FD53213</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:endEvent id="_0B9CCB8E-F8F2-4349-B9E7-30AB978A9DDA">
<bpmn2:incoming>_5C8A83E2-9171-480D-BCAB-6C9ABF89F7A4</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:scriptTask id="_A05B52C4-58FF-4771-B31B-A921C6217018" name="Task" scriptFormat="http://www.java.com/java">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Task]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_6DB5E2A8-6AC8-4774-A642-619C0FD53213</bpmn2:incoming>
<bpmn2:outgoing>_5C8A83E2-9171-480D-BCAB-6C9ABF89F7A4</bpmn2:outgoing>
<bpmn2:script>System.out.println("Exception handling process called "+kcontext.getProcessInstance().getId());</bpmn2:script>
</bpmn2:scriptTask>
</bpmn2:process>
<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="ExceptionHandlingProcess">
<bpmndi:BPMNShape id="shape__A05B52C4-58FF-4771-B31B-A921C6217018" bpmnElement="_A05B52C4-58FF-4771-B31B-A921C6217018">
<dc:Bounds height="102" width="154" x="355" y="110"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__0B9CCB8E-F8F2-4349-B9E7-30AB978A9DDA" bpmnElement="_0B9CCB8E-F8F2-4349-B9E7-30AB978A9DDA">
<dc:Bounds height="56" width="56" x="601" y="133"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__DA57E66C-2AAB-4B59-8FAF-947DA53901B2" bpmnElement="_DA57E66C-2AAB-4B59-8FAF-947DA53901B2">
<dc:Bounds height="56" width="56" x="219" y="133"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge_shape__DA57E66C-2AAB-4B59-8FAF-947DA53901B2_to_shape__A05B52C4-58FF-4771-B31B-A921C6217018" bpmnElement="_6DB5E2A8-6AC8-4774-A642-619C0FD53213">
<di:waypoint x="275" y="161"/>
<di:waypoint x="355" y="161"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape__A05B52C4-58FF-4771-B31B-A921C6217018_to_shape__0B9CCB8E-F8F2-4349-B9E7-30AB978A9DDA" bpmnElement="_5C8A83E2-9171-480D-BCAB-6C9ABF89F7A4">
<di:waypoint x="432" y="161"/>
<di:waypoint x="601" y="161"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmn2:relationship type="BPSimData">
<bpmn2:extensionElements>
<bpsim:BPSimData>
<bpsim:Scenario id="default" name="Simulationscenario">
<bpsim:ScenarioParameters/>
<bpsim:ElementParameters elementRef="_A05B52C4-58FF-4771-B31B-A921C6217018">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
<bpsim:ResourceParameters>
<bpsim:Availability>
<bpsim:FloatingParameter value="0"/>
</bpsim:Availability>
<bpsim:Quantity>
<bpsim:FloatingParameter value="0"/>
</bpsim:Quantity>
</bpsim:ResourceParameters>
<bpsim:CostParameters>
<bpsim:UnitCost>
<bpsim:FloatingParameter value="0"/>
</bpsim:UnitCost>
</bpsim:CostParameters>
</bpsim:ElementParameters>
<bpsim:ElementParameters elementRef="_DA57E66C-2AAB-4B59-8FAF-947DA53901B2">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
</bpsim:ElementParameters>
</bpsim:Scenario>
</bpsim:BPSimData>
</bpmn2:extensionElements>
<bpmn2:source>_BBLdMK7KEDqmbu_5GyFVGg</bpmn2:source>
<bpmn2:target>_BBLdMK7KEDqmbu_5GyFVGg</bpmn2:target>
</bpmn2:relationship>
</bpmn2:definitions>
Loading