Search in sources :

Example 1 with Person

use of org.jbpm.kie.test.objects.Person in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method testBusinessRuleTask.

@Test
public void testBusinessRuleTask() throws IOException {
    Assume.assumeTrue("Skip business rule tests", loadBusinesRuleProcesses);
    String processId = PROC_ID_BUSINESS_RULE;
    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();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    Long procId = startProcess(deploymentId, processId);
    String ruleOutput = "Executed";
    assertEquals("Global did not contain output from rule!", 1, list.size());
    assertEquals("Global did not contain correct output of rule!", ruleOutput, list.get(0));
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull("Process instance did not complete!", procInst);
    // check information about process
    Collection<String> refRules = bpmn2Service.getRuleSets(deploymentId, processId);
    assertNotNull("Null set of imported rules", refRules);
    assertFalse("Empty set of imported rules", refRules.isEmpty());
    assertEquals("Number imported rules", 1, refRules.size());
    assertEquals("Name of imported ruleset", RULE_BUSINESS_RULE_PROCESS, refRules.iterator().next());
    refRules = procDef.getReferencedRules();
    assertNotNull("Null set of imported rules", refRules);
    assertFalse("Empty set of imported rules", refRules.isEmpty());
    assertEquals("Number imported rules", 1, refRules.size());
    assertEquals("Name of imported ruleset", RULE_BUSINESS_RULE_PROCESS, refRules.iterator().next());
}
Also used : ArrayList(java.util.ArrayList) 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 2 with Person

use of org.jbpm.kie.test.objects.Person 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 3 with Person

use of org.jbpm.kie.test.objects.Person 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 4 with Person

use of org.jbpm.kie.test.objects.Person 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 5 with Person

use of org.jbpm.kie.test.objects.Person 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)

Aggregations

OtherPerson (org.jbpm.kie.test.objects.OtherPerson)6 Person (org.jbpm.kie.test.objects.Person)6 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)6 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)5 Test (org.junit.Test)5 KieSession (org.kie.api.runtime.KieSession)4 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Thing (org.jbpm.kie.test.objects.Thing)2 ArrayList (java.util.ArrayList)1 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)1 Ignore (org.junit.Ignore)1