public void testQueryByInvalidDeploymentId() { ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().deploymentId("invalid"); verifyQueryResults(query, 0); try { repositoryService.createProcessDefinitionQuery().deploymentId(null); fail(); } catch (ProcessEngineException e) { // Expected Exception } }
public void testQueryByDeploymentId() { ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentOneId); verifyQueryResults(query, 2); }
public ProcessDefinition deployForTenantAndGetDefinition(String tenant, BpmnModelInstance bpmnModel) { Deployment deployment = deploy(createDeploymentBuilder().tenantId(tenant), Collections.singletonList(bpmnModel), Collections.<String>emptyList()); return processEngineRule.getRepositoryService() .createProcessDefinitionQuery() .deploymentId(deployment.getId()) .singleResult(); }
@Test public void testDeleteProcessDefinitionWithAuthenticatedTenant() { //given deployment with two process definitions Deployment deployment = testRule.deployForTenant(TENANT_ONE, "org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml"); ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()); List<ProcessDefinition> processDefinitions = processDefinitionQuery.list(); //and user with tenant authentication identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); //when delete process definition with authenticated user repositoryService.deleteProcessDefinition(processDefinitions.get(0).getId()); //then process definition should be deleted identityService.clearAuthentication(); assertThat(processDefinitionQuery.count(), is(1L)); assertThat(processDefinitionQuery.tenantIdIn(TENANT_ONE).count(), is(1L)); }
public ProcessInstance startAndDeleteProcessInstance(String tenantId, BpmnModelInstance modelInstance) { String deploymentId = deploymentForTenant(TENANT_ONE, PROCESS); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); return processInstance; }
protected List<String> setupFailedJobs() { List<String> jobIds = new ArrayList<String>(); Deployment deploy = testHelper.deploy(JOB_EXCEPTION_DEFINITION_XML); ProcessDefinition sourceDefinition = engineRule.getRepositoryService() .createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult(); processInstance = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId()); List<Job> jobs = managementService.createJobQuery().processInstanceId(processInstance.getId()).list(); for (Job job : jobs) { jobIds.add(job.getId()); } return jobIds; }
@Test public void testDeleteProcessDefinitionDisabledTenantCheck() { //given deployment with two process definitions Deployment deployment = testRule.deployForTenant(TENANT_ONE, "org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml"); //tenant check disabled processEngineConfiguration.setTenantCheckEnabled(false); ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()); List<ProcessDefinition> processDefinitions = processDefinitionQuery.list(); //user with no authentication identityService.setAuthentication("user", null, null); //when process definition should be deleted without tenant check repositoryService.deleteProcessDefinition(processDefinitions.get(0).getId()); //then process definition is deleted identityService.clearAuthentication(); assertThat(processDefinitionQuery.count(), is(1L)); assertThat(processDefinitionQuery.tenantIdIn(TENANT_ONE).count(), is(1L)); }
public void testQueryByStartableInTasklistNestedProcess() { // given // startable super process // non-startable subprocess BpmnModelInstance[] nestedProcess = setupNestedProcess(false); String dplmntId = deployment(nestedProcess); // when ProcessDefinition actualStartable = repositoryService.createProcessDefinitionQuery() .deploymentId(dplmntId) .startableInTasklist() .singleResult(); ProcessDefinition actualNotStartable = repositoryService.createProcessDefinitionQuery() .deploymentId(dplmntId) .notStartableInTasklist() .singleResult(); // then assertEquals("calling", actualStartable.getKey()); assertEquals("called", actualNotStartable.getKey()); // cleanup repositoryService.deleteDeployment(dplmntId); }
private String deployAndInstantiateWithNewEngineConfiguration(String resource) { // 1. create another process engine try { otherProcessEngine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResource("camunda.cfg.xml") .buildProcessEngine(); } catch (RuntimeException ex) { if (ex.getCause() != null && ex.getCause() instanceof FileNotFoundException) { otherProcessEngine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResource("activiti.cfg.xml") .buildProcessEngine(); } else { throw ex; } } // 2. deploy again RepositoryService otherRepositoryService = otherProcessEngine.getRepositoryService(); String deploymentId = otherRepositoryService.createDeployment() .addClasspathResource(resource) .deploy().getId(); // 3. start instance (i.e. create job) ProcessDefinition newDefinition = otherRepositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); otherProcessEngine.getRuntimeService().startProcessInstanceById(newDefinition.getId()); return deploymentId; }
@Override @Before public void deployProcesses() { Deployment deploy = testHelper.deploy(DEFINITION_XML); sourceDefinition = engineRule.getRepositoryService() .createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult(); processInstance = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId()); processInstance2 = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId()); }
public void testInvalidUsageOfLatest() { try { repositoryService.createProcessDefinitionQuery().processDefinitionId("test").latestVersion().list(); fail(); } catch (ProcessEngineException e) { // Expected Exception } try { repositoryService.createProcessDefinitionQuery().processDefinitionVersion(1).latestVersion().list(); fail(); } catch (ProcessEngineException e) { // Expected Exception } try { repositoryService.createProcessDefinitionQuery().deploymentId("test").latestVersion().list(); fail(); } catch (ProcessEngineException e) { // Expected Exception } }
public void testDeleteProcessDefinitionCascadingShouldKeepCreateUserOperationLog() { // given Deployment deployment = repositoryService .createDeployment() .name(DEPLOYMENT_NAME) .addModelInstance(RESOURCE_NAME, createProcessWithServiceTask(PROCESS_KEY)) .deploy(); ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery() .deploymentId(deployment.getId()) .singleResult(); UserOperationLogQuery query = historyService .createUserOperationLogQuery() .operationType(UserOperationLogEntry.OPERATION_TYPE_CREATE); assertEquals(1, query.count()); // when repositoryService.deleteProcessDefinition(procDef.getId(), true); // then assertEquals(1, query.count()); }
public void testDeleteProcessDefinitiontWithoutCascadingShouldKeepCreateUserOperationLog() { // given Deployment deployment = repositoryService .createDeployment() .name(DEPLOYMENT_NAME) .addModelInstance(RESOURCE_NAME, createProcessWithServiceTask(PROCESS_KEY)) .deploy(); ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery() .deploymentId(deployment.getId()) .singleResult(); UserOperationLogQuery query = historyService .createUserOperationLogQuery() .operationType(UserOperationLogEntry.OPERATION_TYPE_CREATE); assertEquals(1, query.count()); // when repositoryService.deleteProcessDefinition(procDef.getId()); // then assertEquals(1, query.count()); }
@Deployment(resources = TEST_PROCESS_ATTACHED_TIMER) public void testSetProcessDefinitionVersionAttachedTimer() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("attachedTimer"); // and a second deployment of the process org.camunda.bpm.engine.repository.Deployment deployment = repositoryService .createDeployment() .addClasspathResource(TEST_PROCESS_ATTACHED_TIMER) .deploy(); ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult(); assertNotNull(newDefinition); // when the process instance is migrated CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2)); Job job = managementService.createJobQuery().singleResult(); assertNotNull(job); assertEquals(newDefinition.getId(), job.getProcessDefinitionId()); repositoryService.deleteDeployment(deployment.getId(), true); }
.createProcessDefinitionQuery() .processDefinitionKey("oneTaskProcess") .deploymentId(secondDeploymentId) .singleResult() .getId();
.deploymentId(deployment.getId()) .singleResult();
.createProcessDefinitionQuery() .processDefinitionKey("oneTaskProcess") .deploymentId(secondDeploymentId) .singleResult() .getId();
/** * See https://app.camunda.com/jira/browse/CAM-9505 */ @Deployment(resources = TEST_PROCESS_ONE_JOB) public void testPreserveTimestampOnUpdatedIncident() { // given ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneJobProcess", Variables.createVariables().putValue("shouldFail", true)); executeAvailableJobs(); Incident incident = runtimeService.createIncidentQuery().singleResult(); assertNotNull(incident); Date timestamp = incident.getIncidentTimestamp(); org.camunda.bpm.engine.repository.Deployment deployment = repositoryService .createDeployment() .addClasspathResource(TEST_PROCESS_ONE_JOB) .deploy(); ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult(); assertNotNull(newDefinition); // when CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2)); Incident migratedIncident = runtimeService.createIncidentQuery().singleResult(); // then assertEquals(timestamp, migratedIncident.getIncidentTimestamp()); // cleanup repositoryService.deleteDeployment(deployment.getId(), true); }
@Deployment(resources = TEST_PROCESS_ONE_JOB) public void testSetProcessDefinitionVersionMigrateIncident() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneJobProcess", Variables.createVariables().putValue("shouldFail", true)); // with a failed job executeAvailableJobs(); // and an incident Incident incident = runtimeService.createIncidentQuery().singleResult(); assertNotNull(incident); // and a second deployment of the process org.camunda.bpm.engine.repository.Deployment deployment = repositoryService .createDeployment() .addClasspathResource(TEST_PROCESS_ONE_JOB) .deploy(); ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult(); assertNotNull(newDefinition); // when the process instance is migrated CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2)); // then the the incident should also be migrated Incident migratedIncident = runtimeService.createIncidentQuery().singleResult(); assertNotNull(migratedIncident); assertEquals(newDefinition.getId(), migratedIncident.getProcessDefinitionId()); assertEquals(instance.getId(), migratedIncident.getProcessInstanceId()); assertEquals(instance.getId(), migratedIncident.getExecutionId()); repositoryService.deleteDeployment(deployment.getId(), true); }
@Deployment(resources = TEST_PROCESS_ONE_JOB) public void testSetProcessDefinitionVersionMigrateJob() { // given a process instance ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneJobProcess"); // with a job Job job = managementService.createJobQuery().singleResult(); assertNotNull(job); // and a second deployment of the process org.camunda.bpm.engine.repository.Deployment deployment = repositoryService .createDeployment() .addClasspathResource(TEST_PROCESS_ONE_JOB) .deploy(); ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult(); assertNotNull(newDefinition); // when the process instance is migrated CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2)); // then the the job should also be migrated Job migratedJob = managementService.createJobQuery().singleResult(); assertNotNull(migratedJob); assertEquals(job.getId(), migratedJob.getId()); assertEquals(newDefinition.getId(), migratedJob.getProcessDefinitionId()); assertEquals(deployment.getId(), migratedJob.getDeploymentId()); JobDefinition newJobDefinition = managementService .createJobDefinitionQuery().processDefinitionId(newDefinition.getId()).singleResult(); assertNotNull(newJobDefinition); assertEquals(newJobDefinition.getId(), migratedJob.getJobDefinitionId()); repositoryService.deleteDeployment(deployment.getId(), true); }