Search in sources :

Example 1 with ClassPathResource

use of org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.

the class PredictionAwareHumanTaskLifeCycleTest method testUserTaskWithPredictionService.

@Test
public void testUserTaskWithPredictionService() {
    predictNow.set(true);
    BpmnProcess process = BpmnProcess.from(config, new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_COMPLETED, processInstance.status());
    Model result = (Model) processInstance.variables();
    assertEquals(2, result.toMap().size());
    assertEquals("predicted value", result.toMap().get("s"));
    assertEquals(0, trainedTasks.size());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) Model(org.kie.kogito.Model) ClassPathResource(org.drools.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 2 with ClassPathResource

use of org.drools.util.io.ClassPathResource 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.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 3 with ClassPathResource

use of org.drools.util.io.ClassPathResource 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.util.io.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)

Example 4 with ClassPathResource

use of org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testExclusiveSplit.

@Test
public void testExclusiveSplit() 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", "First");
    params.put("y", "Second");
    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) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) ClassPathResource(org.drools.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 5 with ClassPathResource

use of org.drools.util.io.ClassPathResource 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.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

ClassPathResource (org.drools.util.io.ClassPathResource)48 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)45 Test (org.junit.jupiter.api.Test)38 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)33 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)16 HashMap (java.util.HashMap)15 WorkItem (org.kie.kogito.process.WorkItem)10 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)9 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)6 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)6 Collections (java.util.Collections)5 List (java.util.List)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 STATE_ACTIVE (org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE)5 ProcessInstance (org.kie.kogito.process.ProcessInstance)5 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)4 Assertions.entry (org.assertj.core.api.Assertions.entry)4 Action (org.jbpm.process.instance.impl.Action)4 DroolsAction (org.jbpm.workflow.core.DroolsAction)4