Search in sources :

Example 16 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables 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 17 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables 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 18 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables 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)

Example 19 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testUserTaskProcess.

@Test
public void testUserTaskProcess() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.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.UserTaskProcess", content);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Human Task", workItemHandler));
    ProcessInstance<BpmnVariables> processInstance = processes.get("UserTask").createInstance();
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    processInstance.completeWorkItem(workItem.getStringId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(STATE_COMPLETED, processInstance.status());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) 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 20 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testExclusiveSplitRetriggerAfterError.

@Test
public void testExclusiveSplitRetriggerAfterError() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-ExclusiveSplit.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);
    SystemOutWorkItemHandler workItemHandler = new SystemOutWorkItemHandler();
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Email", workItemHandler));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "First1");
    params.put("y", "Second1");
    ProcessInstance<BpmnVariables> processInstance = processes.get("com.sample.test").createInstance(BpmnVariables.create(params));
    processInstance.start();
    assertEquals(KogitoProcessInstance.STATE_ERROR, processInstance.status());
    Optional<ProcessError> errorOptional = processInstance.error();
    assertThat(errorOptional).isPresent();
    ProcessError error = errorOptional.get();
    assertThat(error.failedNodeId()).isEqualTo("_2");
    assertThat(error.errorMessage()).contains("XOR split could not find at least one valid outgoing connection for split Split");
    params.put("x", "First");
    processInstance.updateVariables(BpmnVariables.create(params));
    error.retrigger();
    assertEquals(STATE_COMPLETED, processInstance.status());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ProcessError(org.kie.kogito.process.ProcessError) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)64 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)48 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)47 ClassPathResource (org.drools.core.io.impl.ClassPathResource)34 HashMap (java.util.HashMap)19 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)18 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)18 WorkItem (org.kie.kogito.process.WorkItem)16 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)13 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 ProcessInstance (org.kie.kogito.process.ProcessInstance)7 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 STATE_ACTIVE (org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE)6 List (java.util.List)5 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)5