Search in sources :

Example 41 with BpmnVariables

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

the class ActivityGenerationModelTest method testInclusiveSplitAndJoinNested.

@Test
public void testInclusiveSplitAndJoinNested() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-InclusiveSplitAndJoinNested.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);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 15);
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Human Task", workItemHandler));
    ProcessInstance<BpmnVariables> processInstance = processes.get("com.sample.test").createInstance(BpmnVariables.create(params));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    List<KogitoWorkItem> activeWorkItems = workItemHandler.getWorkItems();
    assertEquals(2, activeWorkItems.size());
    for (KogitoWorkItem wi : activeWorkItems) {
        processInstance.completeWorkItem(wi.getStringId(), null);
    }
    activeWorkItems = workItemHandler.getWorkItems();
    assertEquals(2, activeWorkItems.size());
    for (KogitoWorkItem wi : activeWorkItems) {
        processInstance.completeWorkItem(wi.getStringId(), null);
    }
    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 42 with BpmnVariables

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

the class ActivityGenerationModelTest method testInclusiveSplit.

@Test
public void testInclusiveSplit() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-InclusiveSplit.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>();
    params.put("x", 15);
    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 43 with BpmnVariables

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

the class ActivityGenerationModelTest method testInclusiveSplitDefaultConnection.

@Test
public void testInclusiveSplitDefaultConnection() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-InclusiveGatewayWithDefault.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.InclusiveGatewayWithDefaultProcess", content);
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.emptyMap());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("test", "c");
    ProcessInstance<BpmnVariables> processInstance = processes.get("InclusiveGatewayWithDefault").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 44 with BpmnVariables

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

the class ActivityGenerationModelTest method testMinimalProcess.

@Test
public void testMinimalProcess() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-MinimalProcess.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("com.sample.MinimalProcess", content);
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.emptyMap());
    ProcessInstance<BpmnVariables> processInstance = processes.get("Minimal").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 45 with BpmnVariables

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

the class VariableTagsTest method testRequiredVariableFiltering.

@Test
public void testRequiredVariableFiltering() {
    List<BpmnProcess> processes = BpmnProcess.from(new ClassPathResource("variable-tags/approval-with-custom-variable-tags.bpmn2"));
    BpmnProcess process = processes.get(0);
    Map<String, Object> params = new HashMap<>();
    params.put("approver", "john");
    org.kie.kogito.process.ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create(params));
    instance.start();
    assertEquals(STATE_ACTIVE, instance.status());
    assertThat(instance.variables().toMap()).hasSize(1);
    assertThat(instance.variables().toMap(BpmnVariables.OUTPUTS_ONLY)).hasSize(0);
    assertThat(instance.variables().toMap(BpmnVariables.INPUTS_ONLY)).hasSize(0);
    assertThat(instance.variables().toMap(BpmnVariables.INTERNAL_ONLY)).hasSize(0);
    assertThat(instance.variables().toMap(v -> v.hasTag("onlyAdmin"))).hasSize(1).containsEntry("approver", "john");
    instance.abort();
    assertEquals(STATE_ABORTED, instance.status());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) STATE_ABORTED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ABORTED) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) STATE_ACTIVE(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) HashMap(java.util.HashMap) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) Test(org.junit.jupiter.api.Test) List(java.util.List) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) VariableViolationException(org.kie.kogito.process.VariableViolationException) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) 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)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