Search in sources :

Example 36 with ClassPathResource

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

Example 37 with ClassPathResource

use of org.drools.core.io.impl.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.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)

Example 38 with ClassPathResource

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

the class ActivityGenerationModelTest method testInclusiveSplitAndJoinNestedWithBusinessKey.

@Test
public void testInclusiveSplitAndJoinNestedWithBusinessKey() 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);
    String businessKey = "custom";
    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(businessKey, BpmnVariables.create(params));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    ProcessInstance<BpmnVariables> loadedProcessInstance = processes.get("com.sample.test").instances().findById(processInstance.id()).orElse(null);
    assertThat(loadedProcessInstance).isNotNull();
    assertThat(loadedProcessInstance.businessKey()).isEqualTo(businessKey);
    loadedProcessInstance.abort();
    assertEquals(STATE_ABORTED, processInstance.status());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) 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 39 with ClassPathResource

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

the class ActivityGenerationModelTest method testAsyncExecution.

@Test
public void testAsyncExecution() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("async/AsyncProcess.bpmn")).get(0);
    ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
    Map<String, String> classData = Collections.singletonMap("com.example.AsyncProcessProcess", content);
    CountDownLatch latch = new CountDownLatch(1);
    String mainThread = Thread.currentThread().getName();
    AtomicReference<String> workItemThread = new AtomicReference<>();
    KogitoWorkItemHandler workItemHandler = new KogitoWorkItemHandler() {

        @Override
        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
            workItemThread.set(Thread.currentThread().getName());
            manager.completeWorkItem(workItem.getStringId(), Collections.singletonMap("response", "hello " + workItem.getParameter("name")));
            latch.countDown();
        }

        @Override
        public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
            latch.countDown();
        }
    };
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("org.jbpm.bpmn2.objects.HelloService_hello_3_Handler", workItemHandler));
    ProcessInstance i = UnitOfWorkExecutor.executeInUnitOfWork(process.getApplication().unitOfWorkManager(), () -> {
        ProcessInstance<BpmnVariables> processInstance = processes.get("AsyncProcess").createInstance(BpmnVariables.create(Collections.singletonMap("name", "Tiago")));
        processInstance.start();
        assertEquals(STATE_ACTIVE, processInstance.status());
        return processInstance;
    });
    // since the tasks as async, possibly executed in different threads.
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(STATE_COMPLETED, i.status());
    BpmnVariables variables = (BpmnVariables) i.variables();
    assertEquals(variables.get("greeting"), "hello Tiago");
    assertNotEquals(mainThread, workItemThread.get());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 40 with ClassPathResource

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

the class ActivityGenerationModelTest method testUserTaskWithParamProcess.

@Test
public void testUserTaskWithParamProcess() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTaskWithParametrizedInput.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("Executing task of process instance " + processInstance.id() + " as work item with Hello", workItem.getParameter("Description").toString().trim());
    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)

Aggregations

ClassPathResource (org.drools.core.io.impl.ClassPathResource)88 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)45 Test (org.junit.jupiter.api.Test)38 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)33 Test (org.junit.Test)24 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)21 HashMap (java.util.HashMap)16 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)14 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 VerifierReport (org.drools.verifier.data.VerifierReport)10 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)10 WorkItem (org.kie.kogito.process.WorkItem)10 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)9 ArrayList (java.util.ArrayList)6 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 KieSession (org.kie.api.runtime.KieSession)6 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)6