/** * Creates and starts a new job asynchronously. <p>Requires EXECUTE permission on namespace</p> * * @param request the information needed to create the job. * * @return the created job information. */ @RequestMapping(value = "/jobs", method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_JOBS_POST) public Job createJob(@RequestBody JobCreateRequest request) throws Exception { // Create and return a new job. return jobService.createAndStartJob(request); }
/** * Creates and starts a new job asynchronously. <p>Requires EXECUTE permission on namespace</p> * * @param request the information needed to create the job. * * @return the created job information. */ @RequestMapping(value = "/jobs", method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_JOBS_POST) public Job createJob(@RequestBody JobCreateRequest request) throws Exception { // Create and return a new job. return jobService.createAndStartJob(request); }
@Test(expected = IllegalArgumentException.class) public void testCreateJobJobNameEmpty() throws Exception { // Try to create a job by passing an empty job name. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, " ")); }
/** * This method tests the scenario where a process definition is not defined. */ @Test(expected = ObjectNotFoundException.class) public void testCreateProcessCommandProcessNotDefined() throws Exception { // Create the job with Activiti. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, "test_process_not_defined")); }
@Test(expected = IllegalArgumentException.class) public void testCreateJobNamespaceEmpty() throws Exception { // Try to create a job by passing an empty namespace code. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(" ", TEST_ACTIVITI_JOB_NAME)); }
@Test(expected = ObjectNotFoundException.class) public void testCreateJobNamespaceNoExists() throws Exception { // Try to create a job using non-existing namespace code. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest("I_DO_NOT_EXIST", TEST_ACTIVITI_JOB_NAME)); }
/** * Creates a job based on the specified Activiti XML classpath resource location. * * @param activitiXmlClasspathResourceName the Activiti XML classpath resource location. * * @return the job. * @throws Exception if any errors were encountered. */ public Job createJob(String activitiXmlClasspathResourceName) throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(activitiXmlClasspathResourceName); // Start the job synchronously. return jobService.createAndStartJob(createJobCreateRequest(AbstractServiceTest.TEST_ACTIVITI_NAMESPACE_CD, AbstractServiceTest.TEST_ACTIVITI_JOB_NAME)); }
/** * Creates a job based on the specified Activiti XML classpath resource location. * * @param activitiXmlClasspathResourceName the Activiti XML classpath resource location. * @param parameters the job parameters. * * @return the job. * @throws Exception if any errors were encountered. */ public Job createJob(String activitiXmlClasspathResourceName, List<Parameter> parameters) throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(activitiXmlClasspathResourceName); // Start the job synchronously. return jobService .createAndStartJob(createJobCreateRequest(AbstractServiceTest.TEST_ACTIVITI_NAMESPACE_CD, AbstractServiceTest.TEST_ACTIVITI_JOB_NAME, parameters)); }
/** * Creates a job based on the specified Activiti XML. * * @param activitiXml the Activiti XML. * @param parameters the job parameters. * * @return the job. * @throws Exception if any errors were encountered. */ public Job createJobFromActivitiXml(String activitiXml, List<Parameter> parameters) throws Exception { jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(activitiXml); // Start the job synchronously. return jobService .createAndStartJob(createJobCreateRequest(AbstractServiceTest.TEST_ACTIVITI_NAMESPACE_CD, AbstractServiceTest.TEST_ACTIVITI_JOB_NAME, parameters)); }
@Test(expected = IllegalArgumentException.class) public void testCreateJobParameterNameEmpty() throws Exception { // Create a job create request using hard coded test values. JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME); // Add a parameter with an empty name. Parameter parameter = new Parameter(" ", ATTRIBUTE_VALUE_1); jobCreateRequest.getParameters().add(parameter); // Try to create a job. jobService.createAndStartJob(jobCreateRequest); }
@Test(expected = ObjectNotFoundException.class) public void testCreateJobJobNameNoExists() throws Exception { // Create the namespace entity. namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD); // Try to create a job using non-existing job definition name. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, "I_DO_NOT_EXIST")); }
/** * This method tests the scenario where a java delegate is not populated again with spring beans. */ @Test public void testDelegateSpringBeansNotPopulatedAgain() throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_WORKFLOW); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1"); serviceTask.setImplementation(MockJavaDelegate.class.getCanonicalName()); serviceTask.getFieldExtensions().clear(); // Define the job definition jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel)); // Executing the job twice so that the same JavaDelegate object is used and spring beans are not wired again. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); }
@Test(expected = IllegalArgumentException.class) public void testCreateJobDuplicateParameterName() throws Exception { // Create a job create request using hard coded test values. JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME); // Add a duplicate parameter. Parameter parameter = new Parameter(); parameter.setName(addWhitespace(jobCreateRequest.getParameters().get(0).getName().toUpperCase())); parameter.setValue(jobCreateRequest.getParameters().get(0).getValue()); jobCreateRequest.getParameters().add(parameter); // Try to create a job. jobService.createAndStartJob(jobCreateRequest); }
@Test public void testGetJobAssertNoErrorGivenJobCompletedAndUserDoesHasPermissions() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(null); Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); String username = "username"; ApplicationUser applicationUser = new ApplicationUser(getClass()); applicationUser.setUserId(username); applicationUser.setNamespaceAuthorizations(new HashSet<>()); applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ))); SecurityContextHolder.getContext().setAuthentication( new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null)); try { jobService.getJob(job.getId(), false); } catch (AccessDeniedException e) { fail(); } }
/** * This method tests the scenario where a process definition is suspended in Activiti. */ @Test(expected = IllegalArgumentException.class) public void testCreateProcessCommandProcessSuspended() throws Exception { // Define the job definition JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_HERD_WORKFLOW); JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobDefinition.getNamespace(), jobDefinition.getJobName()); // Suspend the job definition with activiti api activitiRepositoryService.suspendProcessDefinitionById(jobDefinitionEntity.getActivitiId()); jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); }
/** * Signals job with both S3 properties and request parameters set. If there are name clashes, the request parameter should take precedence. * * @throws Exception */ @Test public void testSignalJobWithS3PropertiesPrecedenceRequestParamsOverridesS3() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); Parameter s3Parameter = new Parameter("testName", "testValue"); Parameter requestParameter = new Parameter("testName", "expectedValue"); S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation("s3BucketName", "s3ObjectKey", s3Parameter); // Start the job. Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", null, null); jobSignalRequest.setS3PropertiesLocation(s3PropertiesLocation); jobSignalRequest.setParameters(Arrays.asList(requestParameter)); Job signalJob = jobService.signalJob(jobSignalRequest); assertParameterEquals(requestParameter, signalJob.getParameters()); }
/** * Signals job with S3 properties set. Parameters should be populated from the properties. * * @throws Exception */ @Test public void testSignalJobWithS3Properties() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); Parameter parameter = new Parameter("testName", "testValue"); S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation("s3BucketName", "s3ObjectKey", parameter); // Start the job. Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", null, null); jobSignalRequest.setS3PropertiesLocation(s3PropertiesLocation); Job signalJob = jobService.signalJob(jobSignalRequest); assertParameterEquals(parameter, signalJob.getParameters()); }
/** * This method tests the timer execution in a workflow. */ @Test public void testTimerJob() throws Exception { // Create and start the workflow. jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_HERD_TIMER_WITH_CLASSPATH); Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); assertNotNull(job); // This workflow would normally automatically start a timer which would eventually complete the workflow, however, since // this test method is running within our own transaction, the timer would never go off since it is run in a different thread which is outside of // our transaction which didn't commit yet. As a result, we need to manually run the timer job to simulate what would happen if the timer // went off by itself. org.activiti.engine.runtime.Job timer = activitiManagementService.createJobQuery().processInstanceId(job.getId()).timers().singleResult(); if (timer != null) { activitiManagementService.executeJob(timer.getId()); } }
/** * This method tests the scenario when an workflow related error is throws while workflow is executing an Async type task like Timer. This error is logged * as WARN. */ @Test(expected = ActivitiException.class) public void testActivitiUnReportableError() throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_TIMER_WITH_CLASSPATH); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1"); serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); serviceTask.setImplementation("${BeanNotAvailable}"); jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel)); Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, null)); org.activiti.engine.runtime.Job timer = activitiManagementService.createJobQuery().processInstanceId(job.getId()).timers().singleResult(); if (timer != null) { executeWithoutLogging(TimerExecuteNestedActivityJobHandler.class, () -> { activitiManagementService.executeJob(timer.getId()); }); } }
@Test public void testSignalJobNoParameters() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); // Start the job. Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); // Job should be waiting at Receive task. Job jobGet = jobService.getJob(job.getId(), false); assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus()); assertEquals("receivetask1", jobGet.getCurrentWorkflowStep().getId()); // Signal job to continue. JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", null, null); Job signalJob = jobService.signalJob(jobSignalRequest); assertEquals(JobStatusEnum.RUNNING, signalJob.getStatus()); assertEquals("receivetask1", signalJob.getCurrentWorkflowStep().getId()); // Job should have been completed. jobGet = jobService.getJob(job.getId(), true); assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus()); }