Search in sources :

Example 1 with BpmnProcesses

use of org.kie.kogito.process.bpmn2.BpmnProcesses in project kogito-runtimes by kiegroup.

the class ProcessFactoryTest method testBoundaryErrorEvent.

@Test
public void testBoundaryErrorEvent() throws Exception {
    final String boundaryErrorEvent = "BoundaryErrorEvent";
    final String errorCode = "java.lang.RuntimeException";
    final String processId = "myProcess";
    final RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess(processId);
    final String startNode = "Start";
    final String task = "Task";
    final String endOnError = "EndOnError";
    factory.name("My process").packageName("org.kie.kogito").startNode(1).name(startNode).metaData(UNIQUE_ID, startNode).done().workItemNode(2).name(task).workName(task).done().endNode(3).name("EndOnSuccess").done().boundaryEventNode(4).name(boundaryErrorEvent).attachedTo(2).metaData(ERROR_EVENT, errorCode).metaData(HAS_ERROR_EVENT, true).metaData(ERROR_STRUCTURE_REF, null).metaData("EventTpe", "error").metaData(UNIQUE_ID, boundaryErrorEvent).eventType("Error", errorCode).done().endNode(5).name(endOnError).metaData(UNIQUE_ID, endOnError).terminate(true).done().connection(1, 2).connection(2, 3).connection(4, 5);
    final RuleFlowProcess process = factory.validate().getProcess();
    Application application = mock(Application.class);
    when(application.get(Processes.class)).thenReturn(new BpmnProcesses().addProcess(new BpmnProcess(process)));
    final LightProcessRuntime processRuntime = LightProcessRuntime.of(application, Collections.singletonList(process), new LightProcessRuntimeServiceProvider());
    processRuntime.getKogitoWorkItemManager().registerWorkItemHandler(task, new ExceptionOnPurposeHandler());
    final List<String> completedNodes = new ArrayList<>();
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            completedNodes.add(event.getNodeInstance().getNodeName());
            super.afterNodeLeft(event);
        }
    };
    processRuntime.addEventListener(listener);
    ProcessInstance processInstance = processRuntime.startProcess(processId);
    assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED);
    assertThat(completedNodes).contains(startNode, task, boundaryErrorEvent, endOnError);
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) LightProcessRuntime(org.jbpm.process.instance.LightProcessRuntime) ArrayList(java.util.ArrayList) LightProcessRuntimeServiceProvider(org.jbpm.process.instance.LightProcessRuntimeServiceProvider) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) BpmnProcesses(org.kie.kogito.process.bpmn2.BpmnProcesses) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) ExceptionOnPurposeHandler(org.jbpm.bpmn2.objects.ExceptionOnPurposeHandler) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with BpmnProcesses

use of org.kie.kogito.process.bpmn2.BpmnProcesses in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method createProcesses.

protected Map<String, BpmnProcess> createProcesses(Map<String, String> classData, Map<String, KogitoWorkItemHandler> handlers) throws Exception {
    MemoryFileSystem srcMfs = new MemoryFileSystem();
    MemoryFileSystem trgMfs = new MemoryFileSystem();
    String[] sources = new String[classData.size()];
    int index = 0;
    for (Entry<String, String> entry : classData.entrySet()) {
        String fileName = entry.getKey().replaceAll("\\.", "/") + ".java";
        sources[index++] = fileName;
        srcMfs.write(fileName, entry.getValue().getBytes());
    }
    CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, trgMfs, this.getClass().getClassLoader());
    assertThat(result).isNotNull();
    assertThat(result.getErrors()).hasSize(0);
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    for (Entry<String, KogitoWorkItemHandler> entry : handlers.entrySet()) {
        wiConfig.register(entry.getKey(), entry.getValue());
    }
    ProcessConfig config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
    TestClassLoader cl = new TestClassLoader(this.getClass().getClassLoader(), trgMfs.getMap());
    Map<String, BpmnProcess> processes = new HashMap<>();
    BpmnProcesses bpmnProcesses = new BpmnProcesses();
    StaticApplication application = new StaticApplication(new StaticConfig(null, config), bpmnProcesses);
    for (String className : classData.keySet()) {
        Class<?> processClass = Class.forName(className, true, cl);
        Method processMethod = processClass.getMethod("process");
        Process process = (Process) processMethod.invoke(null);
        assertThat(process).isNotNull();
        processes.put(process.getId(), new BpmnProcess(process, config, application));
    }
    return processes;
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ProcessConfig(org.kie.kogito.process.ProcessConfig) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) HashMap(java.util.HashMap) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) StaticConfig(org.kie.kogito.StaticConfig) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) Process(org.kie.api.definition.process.Process) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) Method(java.lang.reflect.Method) BpmnProcesses(org.kie.kogito.process.bpmn2.BpmnProcesses) StaticApplication(org.kie.kogito.StaticApplication) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) CompilationResult(org.kie.memorycompiler.CompilationResult) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager)

Aggregations

BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)2 BpmnProcesses (org.kie.kogito.process.bpmn2.BpmnProcesses)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)1 ExceptionOnPurposeHandler (org.jbpm.bpmn2.objects.ExceptionOnPurposeHandler)1 LightProcessRuntime (org.jbpm.process.instance.LightProcessRuntime)1 LightProcessRuntimeServiceProvider (org.jbpm.process.instance.LightProcessRuntimeServiceProvider)1 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)1 RuleFlowProcessFactory (org.jbpm.ruleflow.core.RuleFlowProcessFactory)1 Test (org.junit.jupiter.api.Test)1 Process (org.kie.api.definition.process.Process)1 WorkflowProcess (org.kie.api.definition.process.WorkflowProcess)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 Application (org.kie.kogito.Application)1 StaticApplication (org.kie.kogito.StaticApplication)1 StaticConfig (org.kie.kogito.StaticConfig)1 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)1