use of org.jbpm.test.domain.Person in project jbpm by kiegroup.
the class VariableInstanceLogCleanTest method deleteDataObjectLogsByDateRange.
/**
* TBD - test is failing on the last line - probably a test error
*/
@Ignore
@Test
public void deleteDataObjectLogsByDateRange() throws InterruptedException {
kieSession = createKSession(DATA_OBJECT);
Person person = new Person("Marge");
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("person", person);
Date start = new Date();
processInstanceList.addAll(startProcess(kieSession, DATA_OBJECT_ID, paramMap, 1));
Date mid = new Date();
processInstanceList.addAll(startProcess(kieSession, DATA_OBJECT_ID, paramMap, 2));
Date end = new Date();
processInstanceList.addAll(startProcess(kieSession, DATA_OBJECT_ID, paramMap, 1));
// Delete by date range but only from a part of the instance created in the date range.
int resultCount = auditService.variableInstanceLogDelete().dateRangeStart(start).dateRangeEnd(mid).build().execute();
Assertions.assertThat(resultCount).isEqualTo(1);
// Assert remaining logs - We expect 2 logs to be present - One from instance 3 and one from instance 4
List<VariableInstanceLog> variableList = auditService.variableInstanceLogQuery().dateRangeStart(mid).dateRangeEnd(end).variableId("person").build().getResultList();
Assertions.assertThat(variableList.size()).isEqualTo(2);
Assertions.assertThat(variableList.get(0).getDate()).isBefore(mid);
Assertions.assertThat(variableList.get(1).getDate()).isAfter(end);
}
use of org.jbpm.test.domain.Person in project jbpm by kiegroup.
the class DataObjectTest method testDataObject.
/**
* DataObject is linked via association with Human Task. Work item should
* obtain this DataObject in parameters.
*/
@Test(timeout = 30000)
public void testDataObject() {
KieSession ksession = createKSession(PROCESS);
IterableProcessEventListener listener = new IterableProcessEventListener();
ksession.addEventListener(listener);
Map<String, Object> params = new HashMap<String, Object>();
Person mojmir = new Person("Mojmir");
params.put("person", mojmir);
JbpmJUnitBaseTestCase.TestWorkItemHandler wih = getTestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", wih);
StartProcessCommand spc = new StartProcessCommand();
spc.setProcessId(PROCESS_ID);
spc.setParameters(params);
ksession.execute(spc);
assertChangedVariable(listener, "person", null, mojmir);
assertProcessStarted(listener, PROCESS_ID);
assertNextNode(listener, "start");
assertTriggered(listener, "userTask");
WorkItem wi = wih.getWorkItem();
assertTrue(wi.getParameters().containsKey("PersonInput"));
Object param = wi.getParameter("PersonInput");
assertTrue(param instanceof Person);
Person userTaskInput = (Person) param;
assertEquals("Mojmir", userTaskInput.getName());
listener.clear();
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
assertLeft(listener, "userTask");
assertNextNode(listener, "end");
assertProcessCompleted(listener, PROCESS_ID);
}
use of org.jbpm.test.domain.Person in project jbpm by kiegroup.
the class FireUntilHaltTest method testFireUntilHaltWithProcess.
@Test(timeout = 30000)
public void testFireUntilHaltWithProcess() throws Exception {
Map<String, ResourceType> res = new HashMap<String, ResourceType>();
res.put(PROCESS, ResourceType.BPMN2);
res.put(PROCESS_DRL, ResourceType.DRL);
final KieSession ksession = createKSession(res);
ksession.getEnvironment().set("org.jbpm.rule.task.waitstate", true);
TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
// thread for firing until halt
ExecutorService thread = Executors.newSingleThreadExecutor();
thread.submit(new Runnable() {
@Override
public void run() {
ksession.fireUntilHalt();
}
});
int wantedPersonsNum = 3;
int unwantedPersonsNum = 2;
Person p;
// insert 3 wanted persons
for (int i = 0; i < wantedPersonsNum; i++) {
p = new Person("wanted person");
p.setId(i);
ksession.insert(p);
}
// insert 2 unwanted persons
for (int i = 0; i < unwantedPersonsNum; i++) {
p = new Person("unwanted person");
p.setId(i);
ksession.insert(p);
}
// wait for rule to fire
Thread.sleep(100);
// 8 persons should be acknowledged - person detector rule fired
Assertions.assertThat(listener.ruleFiredCount("person detector")).isEqualTo(wantedPersonsNum + unwantedPersonsNum);
// we start defined process
ksession.startProcess(PROCESS_ID);
Thread.sleep(100);
Assertions.assertThat(listener.ruleFiredCount("initial actions")).isEqualTo(1);
Assertions.assertThat(listener.ruleFiredCount("wanted person detector")).isEqualTo(wantedPersonsNum);
Assertions.assertThat(listener.ruleFiredCount("change unwanted person to wanted")).isEqualTo(unwantedPersonsNum);
// 5 + 2 changed + 1 added
Assertions.assertThat(listener.ruleFiredCount("person detector")).isEqualTo(wantedPersonsNum * unwantedPersonsNum);
Assertions.assertThat(listener.ruleFiredCount("closing actions")).isEqualTo(1);
ksession.halt();
}
use of org.jbpm.test.domain.Person in project jbpm by kiegroup.
the class ScriptTaskTest method testScriptTask.
/**
* Object and collection access
*/
@Test(timeout = 30000)
public void testScriptTask() {
KieSession kieSession = createKSession(SCRIPT_TASK);
IterableProcessEventListener ipel = new IterableProcessEventListener();
kieSession.addEventListener(ipel);
Map<String, Object> params = new HashMap<String, Object>();
Person p = new Person("Vandrovec");
params.put("person", p);
List<Person> personList = new ArrayList<Person>();
personList.add(new Person("Birsky"));
personList.add(new Person("Korcasko"));
params.put("personList", personList);
kieSession.execute((Command<?>) getCommands().newStartProcess(SCRIPT_TASK_ID, params));
assertMultipleVariablesChanged(ipel, "person", "personList");
assertProcessStarted(ipel, SCRIPT_TASK_ID);
assertNextNode(ipel, "start");
assertTriggered(ipel, "scriptJava");
assertChangedVariable(ipel, "output", null, "BirskyKorcaskoVandrovec");
assertLeft(ipel, "scriptJava");
assertTriggered(ipel, "scriptMvel");
assertChangedVariable(ipel, "output", "BirskyKorcaskoVandrovec", "VandrovecBirskyKorcasko");
assertLeft(ipel, "scriptMvel");
assertTriggered(ipel, "scriptJavaScript");
assertChangedVariable(ipel, "output", "VandrovecBirskyKorcasko", "JavaScript Node: Vandrovec");
assertLeft(ipel, "scriptJavaScript");
assertNextNode(ipel, "end");
assertProcessCompleted(ipel, SCRIPT_TASK_ID);
}
use of org.jbpm.test.domain.Person in project jbpm by kiegroup.
the class VariableInstanceLogCleanTest method deleteDataObjectLogsByDate.
/**
* BZ-TBD - what is the difference between 'queryVariableInstanceLogs' and
* 'variableInstanceLogQuery'
* BZ-TBD - Assertion will fail on line 71 where 3 results will be found instead
* of 2!
*/
@Ignore
@Test
public void deleteDataObjectLogsByDate() {
kieSession = createKSession(DATA_OBJECT);
Person person = new Person("Homer");
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("person", person);
processInstanceList = startProcess(kieSession, DATA_OBJECT_ID, paramMap, 3);
Assertions.assertThat(processInstanceList).hasSize(3);
// retrieve person variable of process instance 2 and 3
List<VariableInstanceLog> variableList = auditService.variableInstanceLogQuery().processInstanceId(processInstanceList.get(1).getId(), processInstanceList.get(2).getId()).variableId("person").build().getResultList();
Assertions.assertThat(variableList).hasSize(2);
// delete the variable log which belongs to instance 2 and 3
int resultCount = auditService.variableInstanceLogDelete().date(variableList.get(0).getDate(), variableList.get(1).getDate()).build().execute();
Assertions.assertThat(resultCount).isEqualTo(2);
// check what has remained in the database - we expect to find only the person variable
// belonging to instance 1 as the others where deleted in the previous ste
variableList = auditService.variableInstanceLogQuery().variableId("person").build().getResultList();
Assertions.assertThat(variableList).hasSize(1);
Assertions.assertThat(variableList.get(0).getValue()).contains("name='Homer'");
}
Aggregations