private String getApplicationPath(String processDefinitionId) { ProcessDefinition processDefinition = processEngine.getRepositoryService().getProcessDefinition(processDefinitionId); // get the name of the process application that made the deployment String processApplicationName = processEngine .getManagementService() .getProcessApplicationForDeployment(processDefinition.getDeploymentId()); if (processApplicationName == null) { // no a process application deployment return null; } else { ProcessApplicationService processApplicationService = BpmPlatform.getProcessApplicationService(); ProcessApplicationInfo processApplicationInfo = processApplicationService.getProcessApplicationInfo(processApplicationName); String contextPath = processApplicationInfo .getProperties() .get(ProcessApplicationInfo.PROP_SERVLET_CONTEXT_PATH); return contextPath; } }
@Override public List<ProcessDefinition> executeList(CommandContext commandContext, Page page) { checkQueryOk(); List<ProcessDefinition> list = commandContext .getProcessDefinitionManager() .findProcessDefinitionsByQueryCriteria(this, page); for (ProcessDefinition processDefinition : list) { BpmnModelInstance bpmnModelInstance = Context.getProcessEngineConfiguration() .getDeploymentCache() .findBpmnModelInstanceForProcessDefinition( (ProcessDefinitionEntity) processDefinition); ModelElementInstance processElement = bpmnModelInstance.getModelElementById(processDefinition.getKey()); if (processElement != null) { Collection<Documentation> documentations = processElement.getChildElementsByType(Documentation.class); List<String> docStrings = new ArrayList<String>(); for (Documentation documentation : documentations) { docStrings.add(documentation.getTextContent()); } ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) processDefinition; processDefinitionEntity.setProperty( BpmnParse.PROPERTYNAME_DOCUMENTATION, BpmnParse.parseDocumentation(docStrings)); } } return list; }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"}) public void testActivationByProcessDefinitionKey_shouldActivateJob() { // given // a deployed process definition ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); // a running process instance with a failed job Map<String, Object> params = new HashMap<String, Object>(); params.put("fail", Boolean.TRUE); runtimeService.startProcessInstanceByKey("suspensionProcess", params); // suspended job definitions and corresponding jobs managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true); // the failed job JobQuery jobQuery = managementService.createJobQuery(); Job job = jobQuery.singleResult(); assertTrue(job.isSuspended()); // when // the job will be activated managementService.activateJobByProcessDefinitionKey(processDefinition.getKey()); // then // the job should be suspended assertEquals(0, jobQuery.suspended().count()); assertEquals(1, jobQuery.active().count()); Job activeJob = jobQuery.active().singleResult(); assertEquals(job.getId(), activeJob.getId()); assertFalse(activeJob.isSuspended()); }
@Before public void deployProcessesAndCreateMigrationPlan() { ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); migrationPlan = engineRule .getRuntimeService() .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapEqualActivities() .build(); ProcessInstance pi = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId()); batch1 = engineRule .getRuntimeService() .newMigration(migrationPlan) .processInstanceIds(Arrays.asList(pi.getId())) .executeAsync(); batch2 = engineRule .getRuntimeService() .newMigration(migrationPlan) .processInstanceIds(Arrays.asList(pi.getId())) .executeAsync(); }
@Deployment( resources = { "org/camunda/bpm/engine/test/jobexecutor/JobDefinitionFunctionalTest.testRunningInstance.bpmn" }) public void testNewSuspendedJobDuringRunningInstance() { // given // a process definition ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); // a running instance ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); // suspend the process definition (and the job definitions) repositoryService.suspendProcessDefinitionById(processDefinition.getId()); // assert that there still exists a running and active process instance assertEquals(1, runtimeService.createProcessInstanceQuery().active().count()); // when runtimeService.signal(processInstance.getId()); // then // there should be one suspended job assertEquals(1, managementService.createJobQuery().suspended().count()); assertEquals(0, managementService.createJobQuery().active().count()); assertEquals(1, runtimeService.createProcessInstanceQuery().active().count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/db/processOne.bpmn20.xml"}) public void testProcessDefinitionActiveByDefault() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testStartProcessInstanceById() { List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list(); assertEquals(1, processDefinitions.size()); ProcessDefinition processDefinition = processDefinitions.get(0); assertEquals("oneTaskProcess", processDefinition.getKey()); assertNotNull(processDefinition.getId()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testDeleteDeploymentCascadeWithRunningInstances() { List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list(); assertEquals(1, processDefinitions.size()); ProcessDefinition processDefinition = processDefinitions.get(0); runtimeService.startProcessInstanceById(processDefinition.getId()); // Try to delete the deployment, no exception should be thrown repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true); }
protected void assertProcessDeployed(String processKey, String expectedDeploymentName) { ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery() .latestVersion() .processDefinitionKey(processKey) .singleResult(); DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()); Assert.assertEquals(expectedDeploymentName, deploymentQuery.singleResult().getName()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testSuspendProcessInstancesDuringProcessDefinitionSuspend() { int nrOfProcessInstances = 9; // Fire up a few processes for the deployed process definition ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); for (int i = 0; i < nrOfProcessInstances; i++) { runtimeService.startProcessInstanceByKey(processDefinition.getKey()); } assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count()); assertEquals( nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count()); // Suspend process definitions and include process instances repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, null); // Verify all process instances are also suspended for (ProcessInstance processInstance : runtimeService.createProcessInstanceQuery().list()) { assertTrue(processInstance.isSuspended()); } // Verify all process instances can't be continued for (Task task : taskService.createTaskQuery().list()) { try { taskService.complete(task.getId()); fail("A suspended task shouldn't be able to be continued"); } catch (SuspendedEntityInteractionException e) { // This is good } } assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count()); assertEquals( nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().active().count()); // Activate the process definition again repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null); // Verify that all process instances can be completed for (Task task : taskService.createTaskQuery().list()) { taskService.complete(task.getId()); } assertEquals(0, runtimeService.createProcessInstanceQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().active().count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/db/processOne.bpmn20.xml"}) public void testActivateAlreadyActiveProcessDefinition() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); try { repositoryService.activateProcessDefinitionById(processDefinition.getId()); processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); } catch (Exception e) { fail("Should be successful"); } }
public long countTargetProcessInstances() { return engineRule .getRuntimeService() .createProcessInstanceQuery() .processDefinitionId(targetProcessDefinition.getId()) .count(); }
@Test @ScenarioUnderTest("init.1") public void testCompleteProcessWithUserTask() { // given deployed process with process instance String processDefinitionId = rule.processInstance().getProcessDefinitionId(); ProcessDefinition procDef = rule.getRepositoryService() .createProcessDefinitionQuery() .processDefinitionId(processDefinitionId) .singleResult(); // when deployment is deleted rule.getRepositoryService().deleteDeployment(procDef.getDeploymentId(), true); // then process instance is ended rule.assertScenarioEnded(); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testDeleteDeploymentWithRunningInstances() { List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list(); assertEquals(1, processDefinitions.size()); ProcessDefinition processDefinition = processDefinitions.get(0); runtimeService.startProcessInstanceById(processDefinition.getId()); // Try to delete the deployment try { repositoryService.deleteDeployment(processDefinition.getDeploymentId()); fail("Exception expected"); } catch (RuntimeException ae) { // Exception expected when deleting deployment with running process } }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testFindProcessDefinitionById() { List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery().list(); assertEquals(1, definitions.size()); ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery() .processDefinitionId(definitions.get(0).getId()) .singleResult(); runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertNotNull(processDefinition); assertEquals("oneTaskProcess", processDefinition.getKey()); assertEquals("The One Task Process", processDefinition.getName()); processDefinition = repositoryService.getProcessDefinition(definitions.get(0).getId()); assertEquals("This is a process for testing purposes", processDefinition.getDescription()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testContinueProcessAfterProcessDefinitionSuspend() { // Start Process Instance ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); runtimeService.startProcessInstanceByKey(processDefinition.getKey()); // Verify one task is created Task task = taskService.createTaskQuery().singleResult(); assertNotNull(task); assertEquals(1, runtimeService.createProcessInstanceQuery().count()); // Suspend process definition repositoryService.suspendProcessDefinitionById(processDefinition.getId()); // Process should be able to continue taskService.complete(task.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
@Deployment public void testJobIsExecutedOnProcessDefinitionSuspend() { Date now = new Date(); ClockUtil.setCurrentTime(now); // Suspending the process definition should not stop the execution of jobs // Added this test because in previous implementations, this was the case. ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); runtimeService.startProcessInstanceById(processDefinition.getId()); repositoryService.suspendProcessDefinitionById(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); // The jobs should simply be executed ClockUtil.setCurrentTime( new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes waitForJobExecutorToProcessAllJobs(2000L); assertEquals(0, managementService.createJobQuery().count()); }
public void removeDeployment(String deploymentId) { // remove all process definitions for a specific deployment List<ProcessDefinition> allDefinitionsForDeployment = new ProcessDefinitionQueryImpl(Context.getCommandContext()) .deploymentId(deploymentId) .list(); for (ProcessDefinition processDefinition : allDefinitionsForDeployment) { try { removeProcessDefinition(processDefinition.getId()); } catch (Exception e) { LOGGER.log( Level.WARNING, "Could not remove process definition with id '" + processDefinition.getId() + "' from the cache.", e); } } }
@Deployment( resources = { "org/camunda/bpm/engine/test/db/processOne.bpmn20.xml", "org/camunda/bpm/engine/test/db/processTwo.bpmn20.xml" }) public void testQueryForSuspendedDefinitions() { // default = all definitions List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().list(); assertEquals(2, processDefinitionList.size()); assertEquals(2, repositoryService.createProcessDefinitionQuery().active().count()); ProcessDefinition processDefinition = processDefinitionList.get(0); repositoryService.suspendProcessDefinitionById(processDefinition.getId()); assertEquals(2, repositoryService.createProcessDefinitionQuery().count()); assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testSubmitStartFormAfterProcessDefinitionSuspend() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); repositoryService.suspendProcessDefinitionById(processDefinition.getId()); try { formService.submitStartFormData(processDefinition.getId(), new HashMap<String, String>()); fail(); } catch (ProcessEngineException e) { // This is expected } try { formService.submitStartFormData( processDefinition.getId(), "someKey", new HashMap<String, String>()); fail(); } catch (ProcessEngineException e) { e.printStackTrace(); // This is expected } }
@Deployment(resources = {"org/camunda/bpm/engine/test/db/processOne.bpmn20.xml"}) public void testStartProcessInstanceForSuspendedProcessDefinition() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); repositoryService.suspendProcessDefinitionById(processDefinition.getId()); // By id try { runtimeService.startProcessInstanceById(processDefinition.getId()); fail("Exception is expected but not thrown"); } catch (SuspendedEntityInteractionException e) { assertTextPresentIgnoreCase("is suspended", e.getMessage()); } // By Key try { runtimeService.startProcessInstanceByKey(processDefinition.getKey()); fail("Exception is expected but not thrown"); } catch (SuspendedEntityInteractionException e) { assertTextPresentIgnoreCase("is suspended", e.getMessage()); } }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testDelayedActivateProcessDefinition() { Date startTime = new Date(); ClockUtil.setCurrentTime(startTime); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); repositoryService.suspendProcessDefinitionById(processDefinition.getId()); // Try to start process instance. It should fail now. try { runtimeService.startProcessInstanceById(processDefinition.getId()); fail(); } catch (SuspendedEntityInteractionException e) { assertTextPresentIgnoreCase("suspended", e.getMessage()); } assertEquals(0, runtimeService.createProcessInstanceQuery().count()); assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count()); assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count()); // Activate in a day from now long oneDayFromStart = startTime.getTime() + (24 * 60 * 60 * 1000); repositoryService.activateProcessDefinitionById( processDefinition.getId(), false, new Date(oneDayFromStart)); // Move clock two days and let job executor run long twoDaysFromStart = startTime.getTime() + (2 * 24 * 60 * 60 * 1000); ClockUtil.setCurrentTime(new Date(twoDaysFromStart)); waitForJobExecutorToProcessAllJobs(5000L); // Starting a process instance should now succeed runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(1, runtimeService.createProcessInstanceQuery().count()); assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count()); assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count()); }
public Batch migrateProcessInstancesAsync( int numberOfProcessInstances, ProcessDefinition sourceProcessDefinition, ProcessDefinition targetProcessDefinition) { RuntimeService runtimeService = engineRule.getRuntimeService(); List<String> processInstanceIds = new ArrayList<String>(numberOfProcessInstances); for (int i = 0; i < numberOfProcessInstances; i++) { processInstanceIds.add( runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()).getId()); } MigrationPlan migrationPlan = engineRule .getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapEqualActivities() .build(); return runtimeService .newMigration(migrationPlan) .processInstanceIds(processInstanceIds) .executeAsync(); }
@Deployment(resources = {"org/camunda/bpm/engine/test/db/processOne.bpmn20.xml"}) public void testSuspendActivateProcessDefinitionByKey() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); // suspend repositoryService.suspendProcessDefinitionByKey(processDefinition.getKey()); processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertTrue(processDefinition.isSuspended()); // activate repositoryService.activateProcessDefinitionByKey(processDefinition.getKey()); processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testDelayedSuspendProcessDefinition() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); Date startTime = new Date(); ClockUtil.setCurrentTime(startTime); // Suspend process definition in one week from now long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000); repositoryService.suspendProcessDefinitionById( processDefinition.getId(), false, new Date(oneWeekFromStartTime)); // Verify we can just start process instances runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(1, runtimeService.createProcessInstanceQuery().count()); assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count()); assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count()); // Move clock 8 days further and let job executor run long eightDaysSinceStartTime = oneWeekFromStartTime + (24 * 60 * 60 * 1000); ClockUtil.setCurrentTime(new Date(eightDaysSinceStartTime)); waitForJobExecutorToProcessAllJobs(5000L); // Try to start process instance. It should fail now. try { runtimeService.startProcessInstanceById(processDefinition.getId()); fail(); } catch (SuspendedEntityInteractionException e) { assertTextPresentIgnoreCase("suspended", e.getMessage()); } assertEquals(1, runtimeService.createProcessInstanceQuery().count()); assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count()); assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count()); // Activate again repositoryService.activateProcessDefinitionById(processDefinition.getId()); runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(2, runtimeService.createProcessInstanceQuery().count()); assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count()); assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count()); }
/** Test re-deployment of only those resources that have actually changed */ public void testPartialChangesDeployChangedOnly() { BpmnModelInstance model1 = Bpmn.createExecutableProcess("process1").done(); BpmnModelInstance model2 = Bpmn.createExecutableProcess("process2").done(); // create initial deployment ProcessApplicationDeployment deployment1 = repositoryService .createDeployment(processApplication.getReference()) .name("deployment") .addModelInstance("process1.bpmn20.xml", model1) .addModelInstance("process2.bpmn20.xml", model2) .deploy(); BpmnModelInstance changedModel2 = Bpmn.createExecutableProcess("process2").startEvent().done(); // second deployment with partial changes: ProcessApplicationDeployment deployment2 = repositoryService .createDeployment(processApplication.getReference()) .name("deployment") .enableDuplicateFiltering(true) .resumePreviousVersions() .addModelInstance("process1.bpmn20.xml", model1) .addModelInstance("process2.bpmn20.xml", changedModel2) .deploy(); assertEquals(3, repositoryService.createProcessDefinitionQuery().count()); // there is one version of process1 deployed ProcessDefinition processDefinitionModel1 = repositoryService .createProcessDefinitionQuery() .processDefinitionKey("process1") .singleResult(); assertNotNull(processDefinitionModel1); assertEquals(1, processDefinitionModel1.getVersion()); assertEquals(deployment1.getId(), processDefinitionModel1.getDeploymentId()); // there are two versions of process2 deployed List<ProcessDefinition> processDefinitionsModel2 = repositoryService .createProcessDefinitionQuery() .processDefinitionKey("process2") .orderByProcessDefinitionVersion() .asc() .list(); assertEquals(2, processDefinitionsModel2.size()); assertEquals(1, processDefinitionsModel2.get(0).getVersion()); assertEquals(2, processDefinitionsModel2.get(1).getVersion()); // old deployment was resumed ProcessApplicationRegistration registration = deployment2.getProcessApplicationRegistration(); Set<String> deploymentIds = registration.getDeploymentIds(); assertEquals(2, deploymentIds.size()); BpmnModelInstance anotherChangedModel2 = Bpmn.createExecutableProcess("process2").startEvent().endEvent().done(); // testing with a third deployment to ensure the change check is not only performed against // the last version of the deployment ProcessApplicationDeployment deployment3 = repositoryService .createDeployment(processApplication.getReference()) .enableDuplicateFiltering(true) .resumePreviousVersions() .addModelInstance("process1.bpmn20.xml", model1) .addModelInstance("process2.bpmn20.xml", anotherChangedModel2) .name("deployment") .deploy(); // there should still be one version of process 1 assertEquals( 1, repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").count()); // there should be three versions of process 2 assertEquals( 3, repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").count()); // old deployments are resumed registration = deployment3.getProcessApplicationRegistration(); deploymentIds = registration.getDeploymentIds(); assertEquals(3, deploymentIds.size()); deleteDeployments(deployment1, deployment2, deployment3); }
/** * Creates a process definition query and checks that only one process with version 1 is present. */ private void assertThatOneProcessIsDeployed() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertThat(processDefinition, is(notNullValue())); assertEquals(1, processDefinition.getVersion()); }
private void instantiateProcess( CommandContext commandContext, ProcessDefinition matchingDefinition) { new StartProcessInstanceCmd(null, matchingDefinition.getId(), null, processVariables) .execute(commandContext); }
public void setProcessDefinition(ProcessDefinition processDefinition) { this.processDefinitionId = processDefinition.getId(); this.processDefinitionKey = processDefinition.getKey(); this.processDefinitionName = processDefinition.getName(); }