Search in sources :

Example 21 with ClassPathResource

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

the class KafkaProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    listener.setKafkaStreams(createStreams());
    process.setProcessInstancesFactory(factory);
    process.configure();
    listener.getKafkaStreams().start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isZero();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    await().atMost(TIMEOUT).until(() -> instances.values().size() == 1);
    SecurityPolicy asJohn = SecurityPolicy.of(IdentityProviders.of("john"));
    assertThat(instances.values().iterator().next().workItems(asJohn)).hasSize(1);
    List<WorkItem> workItems = processInstance.workItems(asJohn);
    assertThat(workItems).hasSize(1);
    WorkItem workItem = workItems.get(0);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), null, asJohn);
    assertEquals(STATE_COMPLETED, processInstance.status());
    await().atMost(TIMEOUT).until(() -> instances.size() == 0);
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 22 with ClassPathResource

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

the class ActionNodeTest method testSingleActionNode.

@Test
public void testSingleActionNode() throws Exception {
    builder.add(new ClassPathResource("ActionNodeTest.xml", ActionNodeTest.class), ResourceType.DRF);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
    List<String> list = new ArrayList<String>();
    kruntime.getKieSession().setGlobal("list", list);
    kruntime.startProcess("process name");
    assertEquals(1, list.size());
    assertEquals("action node was here", list.get(0));
}
Also used : KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) ArrayList(java.util.ArrayList) ClassPathResource(org.drools.util.io.ClassPathResource) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 23 with ClassPathResource

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

the class KafkaProcessInstancesIT method testFindByIdReadMode.

@Test
void testFindByIdReadMode() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
    listener.setKafkaStreams(createStreams());
    process.setProcessInstancesFactory(factory);
    process.configure();
    listener.getKafkaStreams().start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isZero();
    ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(singletonMap("var", "value")));
    mutablePi.start();
    assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
    assertThat(mutablePi.error()).hasValueSatisfying(error -> {
        assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
        assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
    });
    assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
    await().atMost(TIMEOUT).until(() -> instances.values().size() == 1);
    ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
    assertThat(readOnlyPi.error()).hasValueSatisfying(error -> {
        assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
        assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
    });
    assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
    instances.findById(mutablePi.id()).get().abort();
    await().atMost(TIMEOUT).until(() -> instances.size() == 0);
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ClassPathResource(org.drools.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 24 with ClassPathResource

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

the class KafkaProcessInstancesIT method testValuesReadMode.

@Test
void testValuesReadMode() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    listener.setKafkaStreams(createStreams());
    process.setProcessInstancesFactory(factory);
    process.configure();
    listener.getKafkaStreams().start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isZero();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(singletonMap("test", "test")));
    processInstance.start();
    await().atMost(TIMEOUT).until(() -> instances.values().size() == 1);
    ProcessInstance<BpmnVariables> pi = instances.values().stream().findFirst().get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    instances.values(ProcessInstanceReadMode.MUTABLE).stream().findFirst().get().abort();
    await().atMost(TIMEOUT).until(() -> instances.size() == 0);
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ClassPathResource(org.drools.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 25 with ClassPathResource

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

the class SmileRandomForestPredictionTest method testUserTaskWithPredictionService.

@Test
public void testUserTaskWithPredictionService() {
    BpmnProcess process = (BpmnProcess) 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"));
}
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)

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