private long findTaskId(long procInstId, List<TaskSummary> taskSumList) { long taskId = -1; for (TaskSummary task : taskSumList) { if (task.getProcessInstanceId() == procInstId) { taskId = task.getId(); } } assertNotEquals("Could not determine taskId!", -1, taskId); return taskId; }
@Test public void testLocalTaskService() throws Exception { // Create the task service EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.services.task"); DefaultUserGroupCallbackImpl userGroupCallback = new DefaultUserGroupCallbackImpl(); // create mock groups userGroupCallback.addUser("john", "users"); userGroupCallback.addUser("Administrator", "users"); // start taskService TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .userGroupCallback(userGroupCallback) .getTaskService(); // Create the KIE session KieServices ks = KieServices.Factory.get(); KieContainer kc = ks.getKieClasspathContainer(); KieSession ksession = kc.newKieSession(); // create the work item handler for human task WorkItemHandler humanTaskHandler = new NonManagedLocalHTWorkItemHandler(ksession, taskService); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler); WorkflowProcessInstance instance = (WorkflowProcessInstance) ksession.startProcess("htHomeworkProcess", null); Assert.assertEquals(ProcessInstance.STATE_ACTIVE, instance.getState()); List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK"); Assert.assertNotNull(tasks); Assert.assertEquals(1, tasks.size()); TaskSummary firstTask = tasks.iterator().next(); Assert.assertNotNull(instance.getVariable("requestId")); String requestId = instance.getVariable("requestId").toString(); InternalTask actualFirstTask = (InternalTask) taskService.getTaskById(firstTask.getId()); System.out.println("requestId = " + requestId); System.out.println("formName = " + actualFirstTask.getFormName()); Assert.assertNotNull(actualFirstTask.getFormName()); Assert.assertTrue(actualFirstTask.getFormName().contains(requestId)); taskService.claim(firstTask.getId(), "john"); taskService.start(firstTask.getId(), "john"); taskService.complete(firstTask.getId(), "john", null); // now that the second task is completed, the process is completed as well Assert.assertEquals(ProcessInstance.STATE_COMPLETED, instance.getState()); }
@Test public void testSubjectProperty() { ProcessInstance processInstance = kieSession.startProcess(HUMAN_TASK2_ID); List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK"); TaskSummary task = list.get(0); Task t = taskService.getTaskById(task.getId()); Assertions.assertThat(task.getDescription()).isEqualTo(EXPECTED_SUBJECT); Assertions.assertThat(task.getSubject()).isNullOrEmpty(); Assertions.assertThat(t.getSubject()).isEqualTo(EXPECTED_SUBJECT); taskService.start(task.getId(), "john"); taskService.complete(task.getId(), "john", null); ProcessInstanceLog plog = getLogService().findProcessInstance(processInstance.getId()); Assertions.assertThat(plog.getStatus()).isEqualTo(ProcessInstance.STATE_COMPLETED); }
@Test public void testSupportProcess() { DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION); deploymentService.deploy(deploymentUnitSupport); units.add(deploymentUnitSupport); Map<String, Object> params = new HashMap<String, Object>(); params.put("customer", "polymita"); RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier()); assertNotNull(managerSupport); RuntimeEngine engine = managerSupport.getRuntimeEngine(EmptyContext.get()); assertNotNull(engine); ProcessInstance pI = engine.getKieSession().startProcess("support.process", params); assertNotNull(pI); TaskService taskService = engine.getTaskService(); // Configure Release List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK"); assertEquals(1, tasksAssignedToSalaboy.size()); assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName()); TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0); taskService.start(createSupportTask.getId(), "salaboy"); Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId()); assertEquals("polymita", taskContent.get("input_customer")); Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings( deploymentUnitSupport.getIdentifier(), "support.process", createSupportTask.getName()); assertEquals(1, taskOutputMappings.size()); assertEquals("output_customer", taskOutputMappings.values().iterator().next()); Map<String, Object> output = new HashMap<String, Object>(); output.put("output_customer", "polymita/redhat"); taskService.complete(createSupportTask.getId(), "salaboy", output); tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK"); assertEquals(1, tasksAssignedToSalaboy.size()); assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName()); TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0); taskService.start(resolveSupportTask.getId(), "salaboy"); taskService.complete(resolveSupportTask.getId(), "salaboy", null); tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK"); assertEquals(1, tasksAssignedToSalaboy.size()); assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName()); TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0); taskService.start(notifySupportTask.getId(), "salaboy"); output = new HashMap<String, Object>(); output.put("output_solution", "solved today"); taskService.complete(notifySupportTask.getId(), "salaboy", output); }
@Test public void issueTest() throws Exception { printTestName(); String username = MARY_USER; String password = MARY_PASSWORD; // deploy RepositoryDeploymentUtil deployUtil = new RepositoryDeploymentUtil(deploymentUrl, username, password, 5); String repoUrl = "https://github.com/droolsjbpm/jbpm-playground.git"; String repositoryName = "tests"; String project = "integration-tests"; String deploymentId = KJAR_DEPLOYMENT_ID; String orgUnit = UUID.randomUUID().toString(); deployUtil.createRepositoryAndDeployProject( repoUrl, repositoryName, project, deploymentId, orgUnit); int sleep = 2; logger.info("Waiting {} more seconds to make sure deploy is done..", sleep); Thread.sleep(sleep * 1000); KieWbRestIntegrationTestMethods restTests = KieWbRestIntegrationTestMethods.newBuilderInstance() .setDeploymentId(KJAR_DEPLOYMENT_ID) .setMediaType(MediaType.APPLICATION_XML) .setStrategy(RuntimeStrategy.SINGLETON) .setTimeoutInSecs(5) .build(); restTests.urlsHumanTaskTest(deploymentUrl, MARY_USER, MARY_PASSWORD); // Start process String startProcessUrl = "rest/runtime/" + deploymentId + "/process/" + HUMAN_TASK_VAR_PROCESS_ID + "/start"; Map<String, String> formParams = new HashMap<String, String>(1); formParams.put("map_userName", "John"); JaxbProcessInstanceResponse processInstance = RestUtil.postForm( deploymentUrl, startProcessUrl, MediaType.APPLICATION_XML, 200, username, password, formParams, JaxbProcessInstanceResponse.class); long procInstId = processInstance.getId(); // query tasks for associated task Id Map<String, String> queryparams = new HashMap<String, String>(); queryparams.put("processInstanceId", String.valueOf(procInstId)); JaxbTaskSummaryListResponse taskSumlistResponse = RestUtil.getQuery( deploymentUrl, "task/query", MediaType.APPLICATION_XML, 200, username, password, queryparams, JaxbTaskSummaryListResponse.class); TaskSummary taskSum = findTaskSummaryByProcessInstanceId(procInstId, taskSumlistResponse.getResult()); long taskId = taskSum.getId(); // get task info org.kie.remote.jaxb.gen.Task task = RestUtil.get( deploymentUrl, "task/" + taskId, MediaType.APPLICATION_XML, 200, username, password, org.kie.remote.jaxb.gen.Task.class); assertEquals("Incorrect task id", taskId, task.getId().longValue()); // query tasks for associated task Id queryparams = new HashMap<String, String>(); queryparams.put("taskid", String.valueOf(taskId)); taskSumlistResponse = RestUtil.getQuery( deploymentUrl, "task/query", MediaType.APPLICATION_XML, 200, username, password, queryparams, JaxbTaskSummaryListResponse.class); assertEquals("Incorrect num tasks", 1, taskSumlistResponse.getResult().size()); taskSum = taskSumlistResponse.getResult().get(0); assertEquals("Incorrect task id", taskId, task.getId().longValue()); }
@Test public void queryTaskRestCallTest() throws Exception { int[] pageInfo = {0, 0}; Map<String, String[]> queryParams = new HashMap<String, String[]>(); // simple (everything) JaxbQueryTaskResult result = queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo); assertNotNull("null result", result); assertFalse("empty result", result.getTaskInfoList().isEmpty()); assertTrue("empty result", result.getTaskInfoList().size() > 2); assertTrue( "pagination should not have happened: " + result.getTaskInfoList().size(), result.getTaskInfoList().size() >= 20); for (JaxbQueryTaskInfo taskInfo : result.getTaskInfoList()) { long procInstId = taskInfo.getProcessInstanceId(); assertEquals( procInstId, taskInfo.getTaskSummaries().get(0).getProcessInstanceId().longValue()); } roundTripJson(result); roundTripXml(result); // pagination pageInfo[1] = 3; // page size result = queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo); assertTrue( "Expected a page of size " + pageInfo[1] + ", not " + result.getTaskInfoList().size(), result.getTaskInfoList().size() == pageInfo[1]); pageInfo[0] = 2; // page number 2 JaxbQueryTaskResult otherResult = queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo); Set<Long> origResultSet = new HashSet<Long>(); long lastProcInstId = -1; for (JaxbQueryTaskInfo taskInfo : result.getTaskInfoList()) { assertTrue( "Not in process instance id order:" + lastProcInstId + " !< " + taskInfo.getProcessInstanceId(), lastProcInstId < taskInfo.getProcessInstanceId()); lastProcInstId = taskInfo.getProcessInstanceId(); origResultSet.add(taskInfo.getProcessInstanceId()); } Set<Long> newResultSet = new HashSet<Long>(); for (JaxbQueryTaskInfo taskInfo : otherResult.getTaskInfoList()) { newResultSet.add(taskInfo.getProcessInstanceId()); } for (JaxbQueryTaskInfo taskInfo : otherResult.getTaskInfoList()) { long procInstId = taskInfo.getProcessInstanceId(); assertFalse( "Original results should not be available in new results: " + procInstId, origResultSet.contains(procInstId)); } pageInfo[0] = pageInfo[1] = 0; // reset page info for other tests // complicated long procInstId = result.getTaskInfoList().get(0).getProcessInstanceId(); long taskId = result.getTaskInfoList().get(0).getTaskSummaries().get(0).getId(); addParams(queryParams, "processinstanceid", procInstId + ""); addParams(queryParams, "processid_re", PROCESS_STRING_VAR_ID.substring(0, 10) + "*"); addParams(queryParams, "taskid_min", taskId + ""); addParams(queryParams, "taskid_max", taskId + ""); addParams(queryParams, "taskowner", USER_ID); addParams(queryParams, "tst", "Completed"); Calendar cal = GregorianCalendar.getInstance(); cal.roll(Calendar.DAY_OF_YEAR, +2); String tomorowStr = QUERY_PARAM_DATE_FORMAT.format(cal.getTime()).substring(0, 8); addParams(queryParams, "edt_max", tomorowStr); String yesterdayStr = "00:00:01"; addParams(queryParams, "startdate_min", yesterdayStr); addParams(queryParams, "var_inputStr", "check-1"); addParams(queryParams, "vv_re", "check*"); result = queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo); assertNotNull("null result", result); assertFalse("empty result", result.getTaskInfoList().isEmpty()); assertTrue("more than 1 result", result.getTaskInfoList().size() == 1); JaxbQueryTaskInfo taskInfo = result.getTaskInfoList().get(0); assertEquals("more than 1 task sum", 1, taskInfo.getTaskSummaries().size()); assertEquals("more than 1 variable", 1, taskInfo.getVariables().size()); TaskSummary taskSum = taskInfo.getTaskSummaries().get(0); assertNotNull(taskSum); assertEquals(taskId, taskSum.getId().longValue()); JaxbVariableInfo varInfo = taskInfo.getVariables().get(0); assertEquals("inputStr", varInfo.getName()); roundTripJson(result); roundTripXml(result); }
@Test @Ignore("JMS isn't working.. :/") public void testJmsStartProcess() throws Exception { // send cmd Command<?> cmd = new StartProcessCommand("org.jbpm.humantask"); JaxbCommandsRequest req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); JaxbCommandsResponse response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); // check response assertNotNull("response was null.", response); assertTrue( "response did not contain any command responses", response.getResponses() != null && response.getResponses().size() > 0); JaxbCommandResponse<?> cmdResponse = response.getResponses().get(0); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbProcessInstanceResponse); ProcessInstance procInst = (ProcessInstance) cmdResponse; long procInstId = procInst.getId(); // send cmd cmd = new GetTasksByProcessInstanceIdCommand(procInstId); req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); // check response assertNotNull("response was null.", response); assertTrue( "response did not contain any command responses", response.getResponses() != null && response.getResponses().size() > 0); cmdResponse = response.getResponses().get(0); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbLongListResponse); long taskId = ((JaxbLongListResponse) cmdResponse).getResult().get(0); // send cmd cmd = new StartTaskCommand(taskId, USER_ID); req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); req.getCommands().add(new CompleteTaskCommand(taskId, USER_ID, null)); response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); // check response assertNotNull("response was null.", response); assertTrue("response list was not empty", response.getResponses().size() == 0); // send cmd cmd = new GetTasksOwnedCommand(USER_ID, "en-UK"); req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); req.getCommands().add(new GetTasksOwnedCommand("bob", "fr-CA")); req.getCommands().add(new GetProcessInstanceCommand(procInstId)); response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); assertNotNull("response was null.", response); assertTrue( "response did not contain any command responses", response.getResponses() != null && response.getResponses().size() > 0); cmdResponse = response.getResponses().get(0); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbTaskSummaryListResponse); List<TaskSummary> taskSummaries = ((JaxbTaskSummaryListResponse) cmdResponse).getResult(); assertTrue("task summary list is empty", taskSummaries.size() > 0); for (TaskSummary taskSum : taskSummaries) { if (taskSum.getId() == taskId) { assertTrue( "Task " + taskId + " should have completed.", taskSum.getStatus().equals(Status.Completed)); } } cmdResponse = response.getResponses().get(1); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbTaskSummaryListResponse); taskSummaries = ((JaxbTaskSummaryListResponse) cmdResponse).getResult(); assertTrue( "task summary list should be empty, but has " + taskSummaries.size() + " elements", taskSummaries.size() == 0); cmdResponse = response.getResponses().get(2); assertNotNull(cmdResponse); }
@Test public void testEvaluationProcess() { KieSession ksession = createKnowledgeSession("Step1.bpmn"); KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000); TaskService taskService = getTaskService(); // start a new process instance Map<String, Object> params = new HashMap<String, Object>(); params.put("employee", "krisv"); params.put("reason", "Yearly performance evaluation"); ProcessInstance processInstance = ksession.startProcess("com.sample.evaluation", params); System.out.println("Process started ..."); // complete Self Evaluation List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK"); assertEquals(1, tasks.size()); TaskSummary task = tasks.get(0); System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription()); taskService.start(task.getId(), "krisv"); Map<String, Object> results = new HashMap<String, Object>(); results.put("performance", "exceeding"); taskService.complete(task.getId(), "krisv", results); // john from HR tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK"); assertEquals(1, tasks.size()); task = tasks.get(0); System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription()); taskService.claim(task.getId(), "john"); taskService.start(task.getId(), "john"); results = new HashMap<String, Object>(); results.put("performance", "acceptable"); taskService.complete(task.getId(), "john", results); // mary from PM tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK"); assertEquals(1, tasks.size()); task = tasks.get(0); System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription()); taskService.claim(task.getId(), "mary"); taskService.start(task.getId(), "mary"); results = new HashMap<String, Object>(); results.put("performance", "outstanding"); taskService.complete(task.getId(), "mary", results); assertProcessInstanceCompleted(processInstance.getId(), ksession); System.out.println("Process instance completed"); log.close(); }