Search in sources :

Example 81 with Deployment

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);
        }
    }
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiException(org.activiti.engine.ActivitiException)

Example 82 with Deployment

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);
    }
}
Also used : Deployment(org.activiti.engine.repository.Deployment) Job(org.activiti.engine.runtime.Job)

Example 83 with Deployment

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, ""));
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ActivitiException(org.activiti.engine.ActivitiException)

Example 84 with Deployment

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);
}
Also used : Task(org.activiti.engine.task.Task) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 85 with Deployment

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();
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Aggregations

Deployment (org.activiti.engine.repository.Deployment)96 ArrayList (java.util.ArrayList)11 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)11 ProcessEngine (org.activiti.engine.ProcessEngine)10 RepositoryService (org.activiti.engine.RepositoryService)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)8 Test (org.junit.Test)8 ActivitiException (org.activiti.engine.ActivitiException)7 Test (org.junit.jupiter.api.Test)7 HttpGet (org.apache.http.client.methods.HttpGet)6 BPMNDeployment (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment)6 InputStream (java.io.InputStream)5 HashSet (java.util.HashSet)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5