Search in sources :

Example 36 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method testDroolsScriptWithQualifiedClass.

@Test
// TODO!
@Ignore
public void testDroolsScriptWithQualifiedClass() throws Exception {
    Assume.assumeTrue("Skip script/expr tests", loadJavaMvelScriptProcesses);
    String processId = PROC_ID_RULE_SCRIPT_QUALIFIED_CLASS;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // check that process runs
    Person person = new Person();
    person.setName("Max");
    person.setId(1979l);
    person.setTime(3l);
    KieSession ksession = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getKieSession();
    ksession.insert(person);
    ksession.insert(new Thing());
    ksession.insert(new OtherPerson(person));
    ksession.insert(person.getName());
    ksession.insert(person.getId());
    Long procId = startProcess(deploymentId, processId);
    assertNull("Process instance did not complete:", processService.getProcessInstance(procId));
    Collection<String> javaClasses = bpmn2Service.getJavaClasses(deploymentId, processId);
    assertNotNull("Null set of java classes", javaClasses);
    assertFalse("Empty set of java classes", javaClasses.isEmpty());
    assertEquals("Number java classes", 4, javaClasses.size());
    String[] expected = { "java.lang.Object", Person.class.getCanonicalName(), OtherPerson.class.getCanonicalName(), Thing.class.getCanonicalName() };
    Set<String> expectedClasses = new HashSet<String>(Arrays.asList(expected));
    for (String className : javaClasses) {
        assertTrue("Class name is not qualified: " + className, className.contains("."));
        assertTrue("Unexpected class: " + className, expectedClasses.remove(className));
    }
    if (!expectedClasses.isEmpty()) {
        fail("Expected class not found to be referenced: " + expectedClasses.iterator().next());
    }
}
Also used : OtherPerson(org.jbpm.kie.test.objects.OtherPerson) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) KieSession(org.kie.api.runtime.KieSession) Person(org.jbpm.kie.test.objects.Person) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) Thing(org.jbpm.kie.test.objects.Thing) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 37 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method testImport.

@Test
public void testImport() throws IOException {
    Assume.assumeTrue("Skip import/global tests", loadGlobalImportProcesses);
    String processId = PROC_ID_IMPORT;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // check that process runs
    Person person = new Person();
    person.setName("Max Rockatansky");
    person.setId(1979l);
    person.setTime(3l);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", person);
    Long procId = startProcess(deploymentId, processId, params);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    // verify process information
    Collection<String> refClasses = bpmn2Service.getJavaClasses(deploymentId, processId);
    assertNotNull("Null set of referenced classes", refClasses);
    assertFalse("Empty set of referenced classes", refClasses.isEmpty());
    assertEquals("Number referenced classes", 1, refClasses.size());
    assertEquals("Imported class in process", refClasses.iterator().next(), Person.class.getName());
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.kie.test.objects.Person) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 38 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method testGlobal.

@Test
public void testGlobal() throws IOException {
    Assume.assumeTrue("Skip import/global tests", loadGlobalImportProcesses);
    String processId = PROC_ID_GLOBAL;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // check that process runs
    Person person = new Person();
    person.setName("Max Rockatansky");
    person.setId(1979l);
    person.setTime(3l);
    KieSession ksession = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getKieSession();
    ksession.setGlobal("person", person);
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new SystemOutWorkItemHandler());
    Long procId = startProcess(deploymentId, processId);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    String log = person.getLog();
    assertFalse("Empty log", log == null || log.trim().isEmpty());
    assertEquals("Empty log", log.split(":").length, 4);
    // verify process information
    Collection<String> refClasses = bpmn2Service.getJavaClasses(deploymentId, processId);
    assertNotNull("Null set of referenced classes", refClasses);
    assertFalse("Empty set of referenced classes", refClasses.isEmpty());
    assertEquals("Number referenced classes", 1, refClasses.size());
    assertEquals("Imported class in process", refClasses.iterator().next(), Person.class.getName());
}
Also used : SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.kie.test.objects.Person) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 39 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method testSignalsAndGlobals.

@Test
public void testSignalsAndGlobals() throws IOException {
    Assume.assumeTrue("Skip signal/global tests", loadSignalGlobalInfoProcess);
    String processId = PROC_ID_SIGNAL;
    // check that process starts
    KieSession ksession = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getKieSession();
    ksession.setGlobal("person", new Person());
    long procInstId = startProcess(deploymentId, processId);
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // check information about process
    assertNotNull("Null signals list", procDef.getSignals());
    assertFalse("Empty signals list", procDef.getSignals().isEmpty());
    assertEquals("Unexpected signal", "MySignal", procDef.getSignals().iterator().next());
    Collection<String> globalNames = procDef.getGlobals();
    assertNotNull("Null globals list", globalNames);
    assertFalse("Empty globals list", globalNames.isEmpty());
    assertEquals("globals list size", 2, globalNames.size());
    for (String globalName : globalNames) {
        assertTrue("Unexpected global: " + globalName, "person".equals(globalName) || "name".equals(globalName));
    }
    // cleanup
    processService.abortProcessInstance(procInstId);
}
Also used : KieSession(org.kie.api.runtime.KieSession) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) Person(org.jbpm.kie.test.objects.Person) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 40 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method runScriptTest.

private void runScriptTest(String processId) {
    Assume.assumeTrue("Skip script/expr tests", loadJavaMvelScriptProcesses);
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // check that process runs
    Person person = new Person();
    person.setName("Max Rockatansky");
    person.setId(1979l);
    person.setTime(3l);
    Map<String, Object> params = new HashMap<String, Object>(1);
    params.put("person", person);
    Long procId = startProcess(deploymentId, processId, params);
    assertNull("Process instance did not complete", processService.getProcessInstance(procId));
    assertTrue("Script did not modify variable!", person.getLog().startsWith("Hello"));
    Collection<String> javaClasses = bpmn2Service.getJavaClasses(deploymentId, processId);
    assertNotNull("Null set of java classes", javaClasses);
    assertFalse("Empty set of java classes", javaClasses.isEmpty());
    assertEquals("Number java classes", 4, javaClasses.size());
    String[] expected = { "java.lang.Object", Person.class.getCanonicalName(), OtherPerson.class.getCanonicalName(), Thing.class.getCanonicalName() };
    Set<String> expectedClasses = new HashSet<String>(Arrays.asList(expected));
    for (String className : javaClasses) {
        assertTrue("Class name is not qualified: " + className, className.contains("."));
        assertTrue("Unexpected class: " + className, expectedClasses.remove(className));
    }
    if (!expectedClasses.isEmpty()) {
        fail("Expected class not found to be referenced: " + expectedClasses.iterator().next());
    }
}
Also used : HashMap(java.util.HashMap) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) Person(org.jbpm.kie.test.objects.Person) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) Thing(org.jbpm.kie.test.objects.Thing) HashSet(java.util.HashSet)

Aggregations

ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)50 Test (org.junit.Test)44 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)29 QueryContext (org.kie.api.runtime.query.QueryContext)27 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)22 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)19 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)19 HashMap (java.util.HashMap)14 ArrayList (java.util.ArrayList)12 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)9 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)7 DeployedUnitImpl (org.jbpm.kie.services.impl.DeployedUnitImpl)6 OtherPerson (org.jbpm.kie.test.objects.OtherPerson)6 Person (org.jbpm.kie.test.objects.Person)6 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)6 KieSession (org.kie.api.runtime.KieSession)4 AbstractEJBServicesTest (org.jbpm.test.container.AbstractEJBServicesTest)3 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)3 File (java.io.File)2