Search in sources :

Example 21 with BpmnProcess

use of org.kie.kogito.process.bpmn2.BpmnProcess 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 22 with BpmnProcess

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

the class ActivityGenerationModelTest method testWorkItemProcessWithVariableMapping.

@Test
public void testWorkItemProcessWithVariableMapping() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-ServiceProcess.bpmn2")).get(0);
    ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
    Map<String, String> classData = new HashMap<>();
    classData.put("org.drools.bpmn2.ServiceProcessProcess", content);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("s", "john");
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("org.jbpm.bpmn2.objects.HelloService_hello_2_Handler", workItemHandler));
    ProcessInstance<BpmnVariables> processInstance = processes.get("ServiceProcess").createInstance(BpmnVariables.create(params));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("Parameter"));
    processInstance.completeWorkItem(workItem.getStringId(), Collections.singletonMap("Result", "john doe"));
    assertEquals(STATE_COMPLETED, processInstance.status());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 23 with BpmnProcess

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

the class ActivityGenerationModelTest method testParallelGateway.

@Test
public void testParallelGateway() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-ParallelSplit.bpmn2")).get(0);
    ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
    Map<String, String> classData = new HashMap<>();
    classData.put("org.drools.bpmn2.TestProcess", content);
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.emptyMap());
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance<BpmnVariables> processInstance = processes.get("com.sample.test").createInstance(BpmnVariables.create(params));
    processInstance.start();
    assertEquals(STATE_COMPLETED, processInstance.status());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 24 with BpmnProcess

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

the class ActivityGenerationModelTest method testCallActivityProcess.

@Test
public void testCallActivityProcess() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("PrefixesProcessIdCallActivity.bpmn2")).get(0);
    ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
    assertThat(metaData.getSubProcesses()).hasSize(1).containsKey("SubProcess").containsValue("test.SubProcess");
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 25 with BpmnProcess

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

the class ActivityGenerationModelTest method testScriptMultilineExprProcess.

@Test
public void testScriptMultilineExprProcess() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-CallActivitySubProcess.bpmn2")).get(0);
    ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
    Map<String, String> classData = new HashMap<>();
    classData.put("org.drools.bpmn2.SubProcessProcess", content);
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.emptyMap());
    ProcessInstance<BpmnVariables> processInstance = processes.get("SubProcess").createInstance();
    processInstance.start();
    assertEquals(STATE_COMPLETED, processInstance.status());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)74 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)64 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)47 ClassPathResource (org.drools.core.io.impl.ClassPathResource)46 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)22 HashMap (java.util.HashMap)21 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)18 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)16 WorkItem (org.kie.kogito.process.WorkItem)16 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)10 BpmnProcessInstance (org.kie.kogito.process.bpmn2.BpmnProcessInstance)8 WorkItem (io.automatiko.engine.api.workflow.WorkItem)7 Collections (java.util.Collections)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)7 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)6 STATE_ACTIVE (org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE)6 ProcessInstance (org.kie.kogito.process.ProcessInstance)6 ClassPathResource (io.automatiko.engine.services.io.ClassPathResource)5 List (java.util.List)5