Search in sources :

Example 11 with ProcessMetaData

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

Example 12 with ProcessMetaData

use of org.jbpm.compiler.canonical.ProcessMetaData in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testBusinessRuleTaskProcess.

@Test
public void testBusinessRuleTaskProcess() throws Exception {
    // This is a workaround to make it compile. A process that includes rules will never execute without a full Kogito context
    MockClassLoader classLoader = new MockClassLoader("org.kie.kogito.legacy.rules.KieRuntimeBuilder");
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-BusinessRuleTask.bpmn2")).get(0);
    ProcessMetaData metaData = new ProcessToExecModelGenerator(classLoader).generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ProcessToExecModelGenerator(org.jbpm.compiler.canonical.ProcessToExecModelGenerator) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 13 with ProcessMetaData

use of org.jbpm.compiler.canonical.ProcessMetaData in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testServiceTaskProcess.

@Test
public void testServiceTaskProcess() 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);
    assertThat(metaData.getWorkItems()).hasSize(1).contains("org.jbpm.bpmn2.objects.HelloService_hello_2_Handler");
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 14 with ProcessMetaData

use of org.jbpm.compiler.canonical.ProcessMetaData 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 15 with ProcessMetaData

use of org.jbpm.compiler.canonical.ProcessMetaData 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)

Aggregations

ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)18 ClassPathResource (org.drools.core.io.impl.ClassPathResource)16 Test (org.junit.jupiter.api.Test)16 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)16 HashMap (java.util.HashMap)13 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)13 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)5 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ProcessToExecModelGenerator (org.jbpm.compiler.canonical.ProcessToExecModelGenerator)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)2 StaticJavaParser.parseClassOrInterfaceType (com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 Modifier (com.github.javaparser.ast.Modifier)1 Keyword (com.github.javaparser.ast.Modifier.Keyword)1 NodeList (com.github.javaparser.ast.NodeList)1