use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class TenancyTest method testCallActivityWithTenant.
// Bug from http://forums.activiti.org/content/callactiviti-tenant-id
public void testCallActivityWithTenant() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
String tenantId = "apache";
// deploying both processes. Process 1 will call Process 2
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testCallActivityWithTenant-process01.bpmn20.xml").tenantId(tenantId).deploy();
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testCallActivityWithTenant-process02.bpmn20.xml").tenantId(tenantId).deploy();
// Starting Process 1. Process 1 will be executed successfully but
// when the call to process 2 is made internally it will throw the
// exception
ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId("process1", null, singletonMap("sendFor", "test"), tenantId);
assertThat(processInstance).isNotNull();
assertThat(historyService.createHistoricProcessInstanceQuery().processDefinitionKey("process2").processInstanceTenantId(tenantId).count()).isEqualTo(1);
assertThat(historyService.createHistoricProcessInstanceQuery().processDefinitionKey("process2").count()).isEqualTo(1);
// following line if executed will give activiti object not found
// exception as the process1 is linked to a tenant id.
assertThatExceptionOfType(Exception.class).isThrownBy(() -> runtimeService.startProcessInstanceByKey("process1"));
// Cleanup
for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}
}
use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class TenancyTest method testSignalAsyncThroughApiTenancy.
public void testSignalAsyncThroughApiTenancy() {
// Deploy process both with and without tenant
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testMultiTenancySignals.bpmn20.xml").deploy();
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testMultiTenancySignals.bpmn20.xml").tenantId(TEST_TENANT_ID).deploy();
// Start 4 proc instances for the one with a tenant and 5 for the one
// without tenant
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
// Verify
assertThat(taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count()).isEqualTo(4);
assertThat(taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count()).isEqualTo(5);
// Signal through API (with tenant)
runtimeService.signalEventReceivedAsyncWithTenantId("The Signal", TEST_TENANT_ID);
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count()).isEqualTo(0);
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count()).isEqualTo(0);
for (Job job : managementService.createJobQuery().list()) {
managementService.executeJob(job.getId());
}
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count()).isEqualTo(4);
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count()).isEqualTo(0);
// Signal through API (without tenant)
runtimeService.signalEventReceivedAsync("The Signal");
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count()).isEqualTo(4);
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count()).isEqualTo(0);
for (Job job : managementService.createJobQuery().list()) {
managementService.executeJob(job.getId());
}
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count()).isEqualTo(4);
assertThat(taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count()).isEqualTo(5);
// Cleanup
for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}
use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class TenancyTest method testChangeDeploymentTenantId.
public void testChangeDeploymentTenantId() {
// Generate 8 tasks with tenant
String processDefinitionIdWithTenant = deployTestProcessWithTwoTasksWithTestTenant();
int nrOfProcessInstancesWithTenant = 4;
for (int i = 0; i < nrOfProcessInstancesWithTenant; i++) {
runtimeService.startProcessInstanceById(processDefinitionIdWithTenant);
}
// Generate 10 tasks without tenant
String processDefinitionIdNoTenant = deployTwoTasksTestProcess();
int nrOfProcessInstancesNoTenant = 5;
for (int i = 0; i < nrOfProcessInstancesNoTenant; i++) {
runtimeService.startProcessInstanceById(processDefinitionIdNoTenant);
}
// Migrate deployment with tenant to another tenant
String newTenantId = "NEW TENANT ID";
String deploymentId = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionIdWithTenant).singleResult().getDeploymentId();
repositoryService.changeDeploymentTenantId(deploymentId, newTenantId);
// Verify tenant id
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
assertThat(deployment.getTenantId()).isEqualTo(newTenantId);
// Verify deployment
assertThat(repositoryService.createDeploymentQuery().list()).hasSize(2);
assertThat(repositoryService.createDeploymentQuery().deploymentTenantId(TEST_TENANT_ID).list()).hasSize(0);
assertThat(repositoryService.createDeploymentQuery().deploymentTenantId(newTenantId).list()).hasSize(1);
assertThat(repositoryService.createDeploymentQuery().deploymentWithoutTenantId().list()).hasSize(1);
// Verify process definition
assertThat(repositoryService.createProcessDefinitionQuery().list()).hasSize(2);
assertThat(repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(TEST_TENANT_ID).list()).hasSize(0);
assertThat(repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(newTenantId).list()).hasSize(1);
assertThat(repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(newTenantId).list()).hasSize(1);
// Verify process instances
assertThat(runtimeService.createProcessInstanceQuery().list()).hasSize(nrOfProcessInstancesNoTenant + nrOfProcessInstancesWithTenant);
assertThat(runtimeService.createProcessInstanceQuery().processInstanceTenantId(TEST_TENANT_ID).list()).hasSize(0);
assertThat(runtimeService.createProcessInstanceQuery().processInstanceTenantId(newTenantId).list()).hasSize(nrOfProcessInstancesWithTenant);
assertThat(runtimeService.createProcessInstanceQuery().processInstanceWithoutTenantId().list()).hasSize(nrOfProcessInstancesNoTenant);
// Verify executions
assertThat(runtimeService.createExecutionQuery().list()).hasSize(3 * (nrOfProcessInstancesNoTenant + nrOfProcessInstancesWithTenant));
assertThat(runtimeService.createExecutionQuery().executionWithoutTenantId().list()).hasSize(3 * nrOfProcessInstancesNoTenant);
assertThat(runtimeService.createExecutionQuery().executionTenantId(TEST_TENANT_ID).list()).hasSize(0);
assertThat(runtimeService.createExecutionQuery().executionTenantId(newTenantId).list()).hasSize(3 * nrOfProcessInstancesWithTenant);
assertThat(runtimeService.createExecutionQuery().executionTenantIdLike("NEW%").list()).hasSize(3 * nrOfProcessInstancesWithTenant);
// Verify tasks
assertThat(taskService.createTaskQuery().list()).hasSize(2 * (nrOfProcessInstancesNoTenant + nrOfProcessInstancesWithTenant));
assertThat(taskService.createTaskQuery().taskTenantId(TEST_TENANT_ID).list()).hasSize(0);
assertThat(taskService.createTaskQuery().taskTenantId(newTenantId).list()).hasSize(2 * nrOfProcessInstancesWithTenant);
assertThat(taskService.createTaskQuery().taskWithoutTenantId().list()).hasSize(2 * nrOfProcessInstancesNoTenant);
// Remove the tenant id and verify results
// should clash: there is already a process definition with the same key
assertThatExceptionOfType(Exception.class).isThrownBy(() -> repositoryService.changeDeploymentTenantId(deploymentId, ""));
}
use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class SubProcessTest method testSimpleSubProcess.
@Test
public void testSimpleSubProcess() {
Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/activiti/examples/bpmn/subprocess/SubProcessTest.fixSystemFailureProcess.bpmn20.xml").deploy();
// After staring the process, both tasks in the subprocess should be
// active
ProcessInstance pi = runtimeService.startProcessInstanceByKey("fixSystemFailure");
List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc().list();
// Tasks are ordered by name (see query)
assertThat(tasks).hasSize(2);
Task investigateHardwareTask = tasks.get(0);
Task investigateSoftwareTask = tasks.get(1);
assertThat(investigateHardwareTask.getName()).isEqualTo("Investigate hardware");
assertThat(investigateSoftwareTask.getName()).isEqualTo("Investigate software");
// Completing both the tasks finishes the subprocess and enables the
// task after the subprocess
taskService.complete(investigateHardwareTask.getId());
taskService.complete(investigateSoftwareTask.getId());
Task writeReportTask = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
assertThat(writeReportTask.getName()).isEqualTo("Write report");
// Clean up
repositoryService.deleteDeployment(deployment.getId(), true);
}
use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class AbstractActivitiTestCase method deployOneTaskTestProcess.
/**
* Creates and deploys the one task process. See {@link #createOneTaskTestProcess()}.
*
* @return The process definition id (NOT the process definition key) of deployed one task process.
*/
public String deployOneTaskTestProcess() {
BpmnModel bpmnModel = createOneTaskTestProcess();
Deployment deployment = repositoryService.createDeployment().addBpmnModel("oneTasktest.bpmn20.xml", bpmnModel).deploy();
// For auto-cleanup
deploymentIdsForAutoCleanup.add(deployment.getId());
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
return processDefinition.getId();
}
Aggregations