use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.
the class ESimultaneousProcessInstancesTest method testSimultaneousProcesses.
@Test()
public void testSimultaneousProcesses() {
ProcessInstance pi1 = ejb.startAndGetProcess(ProcessDefinitions.HUMAN_TASK);
ProcessInstance pi2 = ejb.startAndGetProcess(ProcessDefinitions.HUMAN_TASK);
ProcessInstance pi3 = ejb.startAndGetProcess(ProcessDefinitions.HUMAN_TASK);
// check that all the process instances are running
Assertions.assertThat(pi1.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Assertions.assertThat(pi2.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Assertions.assertThat(pi3.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// start and complete the task for p2
long taskId = ejb.getTasksByProcessInstanceId(pi2.getId()).get(0);
Map<String, Object> params = new HashMap<>();
params.put("userId", userId);
ejb.start(taskId, userId);
ejb.complete(taskId, userId, params);
// check that p2 is completed
ProcessInstanceDesc instanceDesc = ejb.getProcessInstanceById(pi2.getId());
Assertions.assertThat(instanceDesc).isNotNull();
Assertions.assertThat(instanceDesc.getState().intValue()).isEqualTo(ProcessInstance.STATE_COMPLETED);
// other processes shouldn't be affected
pi1 = ejb.getProcessInstance(pi1.getId());
Assertions.assertThat(pi1.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
pi3 = ejb.getProcessInstance(pi3.getId());
Assertions.assertThat(pi3.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// abort p1 to test that the tasks will be removed
ejb.abortProcessInstance(pi1.getId());
instanceDesc = ejb.getProcessInstanceById(pi1.getId());
Assertions.assertThat(instanceDesc).isNotNull();
Assertions.assertThat(instanceDesc.getState().intValue()).isEqualTo(ProcessInstance.STATE_ABORTED);
// p1 was aborted so there shouldn't be any tasks to do
List<Long> taskIds = ejb.getTasksByProcessInstanceId(pi1.getId());
Assertions.assertThat(taskIds).hasSize(1);
UserTaskInstanceDesc taskDesc = ejb.getTaskById(taskIds.get(0));
Assertions.assertThat(taskDesc.getStatus()).isEqualTo(Status.Exited.name());
// p3 still shouldn't be affected by any of the previous operations
pi3 = ejb.getProcessInstance(pi3.getId());
Assertions.assertThat(pi3.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// start and complete the task for p3
taskId = ejb.getTasksByProcessInstanceId(pi3.getId()).get(0);
params = new HashMap<>();
params.put("userId", userId);
ejb.start(taskId, userId);
ejb.complete(taskId, userId, params);
// check that p3 is completed
instanceDesc = ejb.getProcessInstanceById(pi3.getId());
Assertions.assertThat(instanceDesc).isNotNull();
Assertions.assertThat(instanceDesc.getState().intValue()).isEqualTo(ProcessInstance.STATE_COMPLETED);
taskIds = ejb.getTasksByProcessInstanceId(pi3.getId());
Assertions.assertThat(taskIds).hasSize(1);
taskDesc = ejb.getTaskById(taskIds.get(0));
Assertions.assertThat(taskDesc.getStatus()).isEqualTo(Status.Completed.name());
}
use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.
the class EGetTaskTest method testGetTaskInstanceInfo.
@Test
public void testGetTaskInstanceInfo() {
Long pid = ejb.startProcess(ProcessDefinitions.HUMAN_TASK);
long taskId = ejb.getTasksByProcessInstanceId(pid).get(0);
UserTaskInstanceDesc task = ejb.getTaskById(taskId);
System.out.println(task.getActualOwner() + "," + task.getTaskId() + "," + task.getStatus());
Assertions.assertThat(userId).isEqualTo(task.getActualOwner());
Assertions.assertThat(Status.Reserved.name()).isEqualTo(task.getStatus());
}
use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetTaskInstances.
@Test
public void testGetTaskInstances() {
query = new SqlQueryDefinition("getAllTaskInstances", dataSourceJNDIname);
query.setExpression("select ti.* from AuditTaskImpl ti ");
queryService.registerQuery(query);
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetFilteredTaskInstancesAsPotOwners.
@Test
public void testGetFilteredTaskInstancesAsPotOwners() {
// let's grant managers role so process can be started
List<String> roles = new ArrayList<String>();
roles.add("managers");
identityProvider.setRoles(roles);
query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.FILTERED_PO_TASK);
query.setExpression(PO_TASK_QUERY);
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
identityProvider.setName("salaboy");
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
List<TaskSummary> taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(1, taskSummaries.size());
// let's now change the roles so user should not see instances
roles.clear();
roles.add("employees");
identityProvider.setRoles(roles);
identityProvider.setName("anotherUser");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(0, taskSummaries.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetTaskInstancesAsExcludedOwner.
@Test
public void testGetTaskInstancesAsExcludedOwner() {
final String potentialOwner = "maciej";
final String excludedOwner = "kris";
final List<String> roles = Arrays.asList("admins");
query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.PO_TASK);
query.setExpression(PO_TASK_QUERY);
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queries.get(0);
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.ExcludedOwner", new HashMap<String, Object>());
assertNotNull(processInstanceId);
identityProvider.setName(potentialOwner);
identityProvider.setRoles(roles);
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
identityProvider.setName(excludedOwner);
identityProvider.setRoles(roles);
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
Aggregations