use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class TenancyTest method testStartProcessInstanceByMessageTenancy.
public void testStartProcessInstanceByMessageTenancy() {
// Deploy process both with and without tenant
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testMessageTenancy.bpmn20.xml").deploy();
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testMessageTenancy.bpmn20.xml").tenantId(TEST_TENANT_ID).deploy();
// Verify query
assertEquals(2, repositoryService.createProcessDefinitionQuery().messageEventSubscriptionName("My message").count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().messageEventSubscriptionName("My message").processDefinitionWithoutTenantId().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().messageEventSubscriptionName("My message").processDefinitionTenantId(TEST_TENANT_ID).count());
// Start a process instance by message without tenant
runtimeService.startProcessInstanceByMessage("My message");
runtimeService.startProcessInstanceByMessage("My message");
assertEquals(2, taskService.createTaskQuery().taskName("My task").count());
assertEquals(2, taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count());
assertEquals(0, taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count());
// Start a process instance by message with tenant
runtimeService.startProcessInstanceByMessageAndTenantId("My message", TEST_TENANT_ID);
runtimeService.startProcessInstanceByMessageAndTenantId("My message", TEST_TENANT_ID);
runtimeService.startProcessInstanceByMessageAndTenantId("My message", TEST_TENANT_ID);
assertEquals(5, taskService.createTaskQuery().taskName("My task").count());
assertEquals(2, taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count());
assertEquals(3, taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count());
// 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();
assertEquals(newTenantId, deployment.getTenantId());
// Verify deployment
assertEquals(2, repositoryService.createDeploymentQuery().list().size());
assertEquals(0, repositoryService.createDeploymentQuery().deploymentTenantId(TEST_TENANT_ID).list().size());
assertEquals(1, repositoryService.createDeploymentQuery().deploymentTenantId(newTenantId).list().size());
assertEquals(1, repositoryService.createDeploymentQuery().deploymentWithoutTenantId().list().size());
// Verify process definition
assertEquals(2, repositoryService.createProcessDefinitionQuery().list().size());
assertEquals(0, repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(TEST_TENANT_ID).list().size());
assertEquals(1, repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(newTenantId).list().size());
assertEquals(1, repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(newTenantId).list().size());
// Verify process instances
assertEquals(nrOfProcessInstancesNoTenant + nrOfProcessInstancesWithTenant, runtimeService.createProcessInstanceQuery().list().size());
assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceTenantId(TEST_TENANT_ID).list().size());
assertEquals(nrOfProcessInstancesWithTenant, runtimeService.createProcessInstanceQuery().processInstanceTenantId(newTenantId).list().size());
assertEquals(nrOfProcessInstancesNoTenant, runtimeService.createProcessInstanceQuery().processInstanceWithoutTenantId().list().size());
// Verify executions
assertEquals(3 * (nrOfProcessInstancesNoTenant + nrOfProcessInstancesWithTenant), runtimeService.createExecutionQuery().list().size());
assertEquals(3 * nrOfProcessInstancesNoTenant, runtimeService.createExecutionQuery().executionWithoutTenantId().list().size());
assertEquals(0, runtimeService.createExecutionQuery().executionTenantId(TEST_TENANT_ID).list().size());
assertEquals(3 * nrOfProcessInstancesWithTenant, runtimeService.createExecutionQuery().executionTenantId(newTenantId).list().size());
assertEquals(3 * nrOfProcessInstancesWithTenant, runtimeService.createExecutionQuery().executionTenantIdLike("NEW%").list().size());
// Verify tasks
assertEquals(2 * (nrOfProcessInstancesNoTenant + nrOfProcessInstancesWithTenant), taskService.createTaskQuery().list().size());
assertEquals(0, taskService.createTaskQuery().taskTenantId(TEST_TENANT_ID).list().size());
assertEquals(2 * nrOfProcessInstancesWithTenant, taskService.createTaskQuery().taskTenantId(newTenantId).list().size());
assertEquals(2 * nrOfProcessInstancesNoTenant, taskService.createTaskQuery().taskWithoutTenantId().list().size());
// Remove the tenant id and verify results
try {
repositoryService.changeDeploymentTenantId(deploymentId, "");
// should clash: there is already a process definition with the same key
fail();
} catch (Exception e) {
}
}
use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.
the class TenancyTest method testSignalFromProcessTenancy.
public void testSignalFromProcessTenancy() {
// 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 3 proc instances for the one with a tenant and 2 for the one without tenant
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalCatch", TEST_TENANT_ID);
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
runtimeService.startProcessInstanceByKey("testMtSignalCatch");
// verify
assertEquals(3, taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count());
assertEquals(2, taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count());
// Now, start 1 process instance that fires a signal event (not in tenant context), it should obly continue those without tenant
runtimeService.startProcessInstanceByKey("testMtSignalFiring");
assertEquals(0, taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count());
assertEquals(2, taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count());
// Start a process instance that is running in tenant context
runtimeService.startProcessInstanceByKeyAndTenantId("testMtSignalFiring", TEST_TENANT_ID);
assertEquals(3, taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count());
assertEquals(2, taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count());
// 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 testSignalThroughApiTenancy.
public void testSignalThroughApiTenancy() {
// 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
assertEquals(4, taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count());
assertEquals(5, taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count());
// Signal through API (with tenant)
runtimeService.signalEventReceivedWithTenantId("The Signal", TEST_TENANT_ID);
assertEquals(4, taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count());
assertEquals(0, taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count());
// Signal through API (without tenant)
runtimeService.signalEventReceived("The Signal");
assertEquals(4, taskService.createTaskQuery().taskName("Task after signal").taskTenantId(TEST_TENANT_ID).count());
assertEquals(5, taskService.createTaskQuery().taskName("Task after signal").taskWithoutTenantId().count());
// 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 testStartProcessInstanceByMessageTenancyReversed.
public void testStartProcessInstanceByMessageTenancyReversed() {
// same as above, but now reversed
// Deploy process both with and without tenant
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testMessageTenancy.bpmn20.xml").deploy();
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/tenant/TenancyTest.testMessageTenancy.bpmn20.xml").tenantId(TEST_TENANT_ID).deploy();
// Start a process instance by message with tenant
runtimeService.startProcessInstanceByMessageAndTenantId("My message", TEST_TENANT_ID);
runtimeService.startProcessInstanceByMessageAndTenantId("My message", TEST_TENANT_ID);
runtimeService.startProcessInstanceByMessageAndTenantId("My message", TEST_TENANT_ID);
assertEquals(3, taskService.createTaskQuery().taskName("My task").count());
assertEquals(0, taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count());
assertEquals(3, taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count());
// Start a process instance by message without tenant
runtimeService.startProcessInstanceByMessage("My message");
runtimeService.startProcessInstanceByMessage("My message");
assertEquals(5, taskService.createTaskQuery().taskName("My task").count());
assertEquals(2, taskService.createTaskQuery().taskName("My task").taskWithoutTenantId().count());
assertEquals(3, taskService.createTaskQuery().taskName("My task").taskTenantId(TEST_TENANT_ID).count());
// Cleanup
for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}
Aggregations