org.kie.api.runtime.process.ProcessInstance Java Examples

The following examples show how to use org.kie.api.runtime.process.ProcessInstance. 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: FlowTest.java    From kogito-runtimes with Apache License 2.0 7 votes vote down vote up
@Test
public void testMultiInstanceLoopCharacteristicsTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultiInstanceLoopCharacteristicsTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
            new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    List<String> myList = new ArrayList<String>();
    myList.add("First Item");
    myList.add("Second Item");
    params.put("list", myList);
    ProcessInstance processInstance = ksession.startProcess(
            "MultiInstanceLoopCharacteristicsTask", params);
    assertProcessInstanceCompleted(processInstance);

}
 
Example #2
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testBoundarySignalEventOnSubprocessWithVariableResolution() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SubprocessWithSignalEndEventAndSignalBoundaryEvent.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(LOGGING_EVENT_LISTENER);

    Map<String, Object> params = new HashMap<>();
    params.put("document-ref", "signalling");
    params.put("message", "hello");
    ProcessInstance processInstance = ksession.startProcess("SubprocessWithSignalEndEventAndSignalBoundaryEvent", params);

    assertNodeTriggered(processInstance.getId(), "sysout from boundary", "end2");
    assertNotNodeTriggered(processInstance.getId(),"end1");

    assertProcessInstanceFinished(processInstance, ksession);
}
 
Example #3
Source File: JbpmBpmn2TestCase.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public void assertNodeActive(String processInstanceId, KieSession ksession,
        String... name) {
    List<String> names = new ArrayList<String>();
    for (String n : name) {
        names.add(n);
    }
    ProcessInstance processInstance = ksession
            .getProcessInstance(processInstanceId);
    if (processInstance instanceof WorkflowProcessInstance) {            
        assertNodeActive((WorkflowProcessInstance) processInstance, names);            
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) not active: " + s);
    }
}
 
Example #4
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "BPMN2-SignalBoundaryOnSubProcess.bpmn");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);

    ProcessInstance processInstance = ksession.startProcess("jbpm.testing.signal");
    assertProcessInstanceActive(processInstance);

    ksession.signalEvent("continue", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();

    ksession = createKnowledgeSession(kbase);

    processInstance = ksession.startProcess("jbpm.testing.signal");
    assertProcessInstanceActive(processInstance);

    ksession.signalEvent("forward", null);
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();
}
 
Example #5
Source File: ProcessEventSupport.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public void fireBeforeVariableChanged(final String id, final String instanceId, 
        final Object oldValue, final Object newValue,
        final List<String> tags,
        final ProcessInstance processInstance, NodeInstance nodeInstance, KieRuntime kruntime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    
    final ProcessVariableChangedEvent event = new ProcessVariableChangedEventImpl(
                                                                                  id, instanceId, oldValue, newValue, tags, processInstance, nodeInstance, kruntime);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (iter.hasNext()) {            
        
            do {
                iter.next().beforeVariableChanged(e);
            } while (iter.hasNext());            
        }
    }));
}
 
Example #6
Source File: ProcessInstanceResolverStrategy.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
/**
 * Fill the process instance .kruntime and .process fields with the appropriate values.
 * @param processInstance
 * @param streamContext
 */
private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance,
                                                       Object streamContext) {
    ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance;
    InternalKnowledgeRuntime kruntime = processInstanceImpl.getKnowledgeRuntime();

    // Attach the kruntime if not present
    if ( kruntime == null ) {
        kruntime = retrieveKnowledgeRuntime( streamContext );
        processInstanceImpl.setKnowledgeRuntime( kruntime );
    }
    // Attach the process if not present
    if ( processInstance.getProcess() == null ) {
    	String processId = processInstance.getProcessId();
    	if (processId != null) {
    		Process process = kruntime.getKieBase().getProcess( processId );
    		if (process != null) {
    			processInstanceImpl.setProcess( process );
    		}
    	}
    }
}
 
Example #7
Source File: LightProcessRuntime.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessInstance createProcessInstance(String processId,
                                             CorrelationKey correlationKey, Map<String, Object> parameters) {
    try {
        runtimeContext.startOperation();

        final Process process =
                runtimeContext.findProcess(processId)
                        .orElseThrow(() -> new IllegalArgumentException(
                                "Unknown process ID: " + processId));

        return startProcess(process, correlationKey, parameters);
    } finally {
        runtimeContext.endOperation();
    }
}
 
Example #8
Source File: InMemoryJobService.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        LOGGER.debug("Job {} started", id);
        UnitOfWorkExecutor.executeInUnitOfWork(unitOfWorkManager, () -> {
            ProcessInstance pi = processRuntime.createProcessInstance(processId, null);
            if (pi != null) {
                processRuntime.startProcessInstance(pi.getId(), TRIGGER);
            }

            return null;
        });
        limit--;
        if (limit == 0) {
            scheduledJobs.remove(id).cancel(false);
        }
        LOGGER.debug("Job {} completed", id);
    } finally {
        if (removeAtExecution) {
            scheduledJobs.remove(id);
        }
    }
}
 
Example #9
Source File: ActivityTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testCallActivity2() throws Exception {
	KieBase kbase = createKnowledgeBase("BPMN2-CallActivity2.bpmn2",
			"BPMN2-CallActivitySubProcess.bpmn2");
	ksession = createKnowledgeSession(kbase);
	TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
	ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
               workItemHandler);
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("x", "oldValue");
	ProcessInstance processInstance = ksession.startProcess(
			"ParentProcess", params);
	assertProcessInstanceActive(processInstance);
	assertEquals("new value",
			((WorkflowProcessInstance) processInstance).getVariable("y"));

	ksession = restoreSession(ksession, true);
	WorkItem workItem = workItemHandler.getWorkItem();
	assertNotNull(workItem);
	assertEquals("krisv", workItem.getParameter("ActorId"));
	ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);

	assertProcessInstanceFinished(processInstance, ksession);
}
 
Example #10
Source File: FlowTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testExclusiveSplitXPathAdvancedWithVars() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-with-vars.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email",
            new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    Document doc = DocumentBuilderFactory.newInstance()
            .newDocumentBuilder().newDocument();
    Element hi = doc.createElement("hi");
    Element ho = doc.createElement("ho");
    hi.appendChild(ho);
    Attr attr = doc.createAttribute("value");
    ho.setAttributeNode(attr);
    attr.setValue("a");
    params.put("x", hi);
    params.put("y", "Second");
    ProcessInstance processInstance = ksession.startProcess(
            "com.sample.test", params);
    assertProcessInstanceCompleted(processInstance);

}
 
Example #11
Source File: ActivityTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorBetweenProcessesProcess() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/ErrorsBetweenProcess-Process.bpmn2",
    		"subprocess/ErrorsBetweenProcess-SubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);

    Map<String, Object> variables = new HashMap<String, Object>();

    variables.put("tipoEvento", "error");
    variables.put("pasoVariable", 3);
    ProcessInstance processInstance = ksession.startProcess("Principal", variables);

    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    assertProcessInstanceAborted(processInstance.getId()+1, ksession);

    assertProcessVarValue(processInstance, "event", "error desde Subproceso");
}
 
Example #12
Source File: ActivityTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserTaskParametrizedInput() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithParametrizedInput.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("Executing task of process instance " + processInstance.getId() + " as work item with Hello",
            workItem.getParameter("Description").toString().trim());
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
}
 
Example #13
Source File: WorkItemHandlerExceptionHandlingTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrornousHandlerWithStrategyAbort() throws Exception {
      
    KieBase kbase = createKnowledgeBaseWithoutDumper("handler/BPMN2-UserTaskWithBooleanOutput.bpmn2", "handler/BPMN2-ScriptTask.bpmn2");

    KieSession ksession = createKnowledgeSession(kbase);
    ErrornousWorkItemHandler workItemHandler = new ErrornousWorkItemHandler("ScriptTask", HandlingStrategy.ABORT);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    
    Map<String, Object> params = new HashMap<>();
    params.put("isChecked", false);
    ProcessInstance processInstance = ksession.startProcess("com.sample.boolean", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertProcessVarValue(processInstance, "isChecked", "false");
    
    WorkItem handledWorkItem = workItemHandler.getWorkItem();
    assertEquals(WorkItem.ABORTED, handledWorkItem.getState());
    
}
 
Example #14
Source File: GetProcessInstanceVariableCommand.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public Object execute(Context context ) {
    KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );
    if (processInstanceId == null) {
        return null;
    }
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if ( processInstance == null ) {
        throw new IllegalArgumentException( "Could not find process instance for id " + processInstanceId );
    }
    if ( processInstance instanceof WorkflowProcessInstance ) { 
    	return ((WorkflowProcessInstance) processInstance).getVariable(variableId);
    } else { 
        throw new IllegalStateException("Could not retrieve variable " + variableId 
                + " because process instance " + processInstanceId + " was inaccessible!");
    }
}
 
Example #15
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEventBasedSplitAfter() throws Exception {
    // signaling the other alternative after one has been selected should
    // have no effect
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1",
            new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2",
            new DoNothingWorkItemHandler());
    // Yes
    ProcessInstance processInstance = ksession
            .startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1",
            new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2",
            new DoNothingWorkItemHandler());
    ksession.signalEvent("Yes", "YesValue", processInstance.getId());
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1",
            new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2",
            new DoNothingWorkItemHandler());
    // No
    ksession.signalEvent("No", "NoValue", processInstance.getId());

}
 
Example #16
Source File: StartCorrelatedProcessCommand.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public ProcessInstance execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );

    if (data != null) {
        for (Object o: data) {
            ksession.insert(o);
        }
    }
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime)ksession).startProcess(processId, correlationKey, parameters);
    if ( this.outIdentifier != null ) {
        ((RegistryContext) context).lookup( ExecutionResultImpl.class ).setResult(this.outIdentifier, processInstance.getId());
    }
    return processInstance;
}
 
Example #17
Source File: DataTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluationProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EvaluationProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
            new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler(
            "RegisterRequest", new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "UserId-12345");
    ProcessInstance processInstance = ksession.startProcess("Evaluation",
            params);
    assertProcessInstanceCompleted(processInstance);
    
}
 
Example #18
Source File: ProcessEventSupport.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void fireAfterSLAViolated(final ProcessInstance instance, KieRuntime kruntime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();

    final SLAViolatedEvent event = new SLAViolatedEventImpl(instance, kruntime);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (iter.hasNext()) {
        
            do {
                iter.next().afterSLAViolated(e);
            } while (iter.hasNext());            
        }
    }));
}
 
Example #19
Source File: ActivityTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
@RequirePersistence(false)
public void testBusinessRuleTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-BusinessRuleTask.bpmn2",
            "BPMN2-BusinessRuleTask.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventListener());
    ProcessInstance processInstance = ksession
            .startProcess("BPMN2-BusinessRuleTask");
    assertProcessInstanceFinished(processInstance, ksession);
}
 
Example #20
Source File: FlowTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testInclusiveSplitAndJoinExtraPath() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoinExtraPath.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
            workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 25);
    ProcessInstance processInstance = ksession.startProcess(
            "com.sample.test", params);

    ksession.signalEvent("signal", null);

    List<WorkItem> activeWorkItems = workItemHandler.getWorkItems();

    assertEquals(4, activeWorkItems.size());
    ksession = restoreSession(ksession, true);

    for (int i = 0; i < 3; i++) {
        ksession.getWorkItemManager().completeWorkItem(
                activeWorkItems.get(i).getId(), null);
    }
    assertProcessInstanceActive(processInstance);

    ksession.getWorkItemManager().completeWorkItem(
            activeWorkItems.get(3).getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);

}
 
Example #21
Source File: CompensationTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void compensationViaEventSubProcess() throws Exception {
    KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-EventSubProcess.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
 
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "0");
    ProcessInstance processInstance = ksession.startProcess("CompensationEventSubProcess", params);

    assertProcessInstanceActive(processInstance.getId(), ksession);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    
    assertProcessVarValue(processInstance, "x", "1");
}
 
Example #22
Source File: EscalationEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEscalationEndEventProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationEndEvent.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("EscalationEndEvent");
    assertProcessInstanceAborted(processInstance.getId(), ksession);
}
 
Example #23
Source File: FlowTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testExclusiveSplit() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplit.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email",
            new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "First");
    params.put("y", "Second");
    ProcessInstance processInstance = ksession.startProcess(
            "com.sample.test", params);
    assertProcessInstanceCompleted(processInstance);

}
 
Example #24
Source File: CreateCorrelatedProcessInstanceCommand.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public ProcessInstance execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );

    if (data != null) {
        for (Object o: data) {
            ksession.insert(o);
        }
    }
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime)ksession).createProcessInstance(processId, correlationKey, parameters);
    if ( this.outIdentifier != null ) {
        ((RegistryContext) context).lookup( ExecutionResultImpl.class ).setResult(this.outIdentifier, processInstance.getId());
    }
    return processInstance;
}
 
Example #25
Source File: SuspendProcessInstanceCommand.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public Object execute(Context context ) {
    KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );
    if (processInstanceId == null) {
        return null;
    }
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if ( processInstance == null ) {
        throw new IllegalArgumentException( "Could not find process instance for id " + processInstanceId );
    }
    if ( processInstance.getState() != ProcessInstance.STATE_ACTIVE ) {
    	throw new IllegalArgumentException( "Process instance with id " + processInstanceId + " in state " + processInstance.getState());
    }
    ((org.jbpm.process.instance.ProcessInstance) processInstance).setState( ProcessInstance.STATE_SUSPENDED );
    return null;
}
 
Example #26
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testErrorBoundaryEventOnMultiInstanceSubprocess() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "subprocess/BPMN2-MultiInstanceSubprocessWithBoundaryError.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

    Map<String, Object> params = new HashMap<String, Object>();
    List<String> approvers = new ArrayList<String>();
    approvers.add("john");
    approvers.add("john");

    params.put("approvers", approvers);

    ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
    assertProcessInstanceActive(processInstance);
    Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
    assertThat(eventDescriptions)
        .hasSize(3)
        .extracting("event").contains("workItemCompleted", "Inside", "Error-_D83CFC28-3322-4ABC-A12D-83476B08C7E8-MyError");
    assertThat(eventDescriptions)
        .extracting("eventType").contains("workItem", "signal");
    assertThat(eventDescriptions)            
        .extracting("processInstanceId").contains(processInstance.getId());
    assertThat(eventDescriptions)
        .filteredOn("eventType", "signal")
        .hasSize(2)
        .extracting("properties", Map.class)
        .anyMatch(m -> m.containsKey("AttachedToID") && m.containsKey("AttachedToName"));

    List<WorkItem> workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(2);

    ksession.signalEvent("Inside", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();
}
 
Example #27
Source File: WorkItemHandlerExceptionHandlingTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testErrornousHandlerWithStrategyRethrow() throws Exception {
      
    KieBase kbase = createKnowledgeBaseWithoutDumper("handler/BPMN2-UserTaskWithBooleanOutput.bpmn2", "handler/BPMN2-ScriptTask.bpmn2");

    KieSession ksession = createKnowledgeSession(kbase);
    ErrornousWorkItemHandler workItemHandler = new ErrornousWorkItemHandler("ScriptTask", HandlingStrategy.RETHROW);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);

    Map<String, Object> params = new HashMap<>();
    params.put("isChecked", false);
    ProcessInstance processInstance = ksession.startProcess("com.sample.boolean", params);
    assertEquals(ProcessInstance.STATE_ERROR, processInstance.getState());  
}
 
Example #28
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignalBoundaryEventOnMultiInstanceSubprocess() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "subprocess/BPMN2-MultiInstanceSubprocessWithBoundarySignal.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

    Map<String, Object> params = new HashMap<String, Object>();
    List<String> approvers = new ArrayList<String>();
    approvers.add("john");
    approvers.add("john");

    params.put("approvers", approvers);

    ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
    assertProcessInstanceActive(processInstance);

    List<WorkItem> workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(2);

    ksession.signalEvent("Outside", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();
}
 
Example #29
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEventSubprocessConditional() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessConditional.bpmn2");
    final List<String> executednodes = new ArrayList<>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName()
                    .equals("Script Task 1")) {
                executednodes.add(event.getNodeInstance().getId());
            }
        }

    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
            workItemHandler);
    ProcessInstance processInstance = ksession
            .startProcess("BPMN2-EventSubprocessConditional");
    assertProcessInstanceActive(processInstance);

    Person person = new Person();
    person.setName("john");
    ksession.insert(person);


    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1",
            "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertThat(executednodes.size()).isEqualTo(1);

}
 
Example #30
Source File: ProcessVariableChangedEventImpl.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public ProcessVariableChangedEventImpl(final String id, final String instanceId,
        final Object oldValue, final Object newValue, List<String> tags,
        final ProcessInstance processInstance, NodeInstance nodeInstance, KieRuntime kruntime ) {
    super( processInstance, kruntime );
    this.nodeInstance = nodeInstance;
    this.id = id;
    this.instanceId = instanceId;
    this.oldValue = oldValue;
    this.newValue = newValue;
    this.tags = tags == null ? Collections.emptyList() : tags;
}