Java Code Examples for org.kie.api.runtime.KieSession#abortProcessInstance()
The following examples show how to use
org.kie.api.runtime.KieSession#abortProcessInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariableTagsTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testProcessWithReadonlyVariable() throws Exception { KieBase kbase = createKnowledgeBase("variable-tags/approval-with-readonly-variable-tags.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); Map<String, Object> parameters = new HashMap<>(); parameters.put("approver", "john"); ProcessInstance processInstance = ksession.startProcess("approvals", parameters); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertThrows(VariableViolationException.class, () -> ksession.getWorkItemManager().completeWorkItem(workItem.getId(), Collections.singletonMap("ActorId", "john"))); ksession.abortProcessInstance(processInstance.getId()); assertProcessInstanceFinished(processInstance, ksession); ksession.dispose(); }
Example 2
Source File: AbortProcessInstanceCommand.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); if (processInstanceId == null) { return null; } ksession.abortProcessInstance(processInstanceId); return null; }
Example 3
Source File: WorkItemTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testCancelNonRegisteredWorkItemHandler() { String processId = "org.drools.actions"; String workName = "Unnexistent Task"; RuleFlowProcess process = getWorkItemProcess( processId, workName ); KieSession ksession = createKieSession(process); ksession.getWorkItemManager().registerWorkItemHandler( workName, new DoNothingWorkItemHandler() ); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put( "UserName", "John Doe" ); parameters.put( "Person", new Person( "John Doe" ) ); ProcessInstance processInstance = ksession.startProcess( "org.drools.actions", parameters ); String processInstanceId = processInstance.getId(); assertEquals( ProcessInstance.STATE_ACTIVE, processInstance.getState() ); ksession.getWorkItemManager().registerWorkItemHandler( workName, null ); try { ksession.abortProcessInstance( processInstanceId ); fail( "should fail if WorkItemHandler for" + workName + "is not registered" ); } catch ( WorkItemHandlerNotFoundException wihnfe ) { } assertEquals( ProcessInstance.STATE_ABORTED, processInstance.getState() ); }