Search in sources :

Example 1 with ChangeDeploymentTenantIdCmd

use of org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd in project Activiti by Activiti.

the class HistoricProcessInstanceCollectionResourceTest method testQueryProcessInstances.

/**
   * Test querying historic process instance based on variables. 
   * GET history/historic-process-instances
   */
@Deployment
public void testQueryProcessInstances() throws Exception {
    Calendar startTime = Calendar.getInstance();
    processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    startTime.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES);
    assertResultsPresentInDataResponse(url + "?finished=true", processInstance.getId());
    assertResultsPresentInDataResponse(url + "?finished=false", processInstance2.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionId=" + processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance2.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionId=" + processInstance.getProcessDefinitionId() + "&finished=true", processInstance.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionKey=oneTaskProcess", processInstance.getId(), processInstance2.getId());
    // Without tenant ID, before setting tenant
    assertResultsPresentInDataResponse(url + "?withoutTenantId=true", processInstance.getId(), processInstance2.getId());
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    startTime.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", "myTenant");
    // Without tenant ID, after setting tenant
    assertResultsPresentInDataResponse(url + "?withoutTenantId=true", processInstance.getId(), processInstance2.getId());
    // Tenant id
    assertResultsPresentInDataResponse(url + "?tenantId=myTenant", processInstance3.getId());
    assertResultsPresentInDataResponse(url + "?tenantId=anotherTenant");
    // Tenant id like
    assertResultsPresentInDataResponse(url + "?tenantIdLike=" + encode("%enant"), processInstance3.getId());
    assertResultsPresentInDataResponse(url + "?tenantIdLike=anotherTenant");
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url + "?processDefinitionKey=oneTaskProcess&sort=startTime"), 200);
    // Check status and size
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    assertEquals(3, dataNode.size());
    assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText());
    assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText());
    assertEquals(processInstance3.getId(), dataNode.get(2).get("id").asText());
}
Also used : Task(org.activiti.engine.task.Task) ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ChangeDeploymentTenantIdCmd

use of org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd in project Activiti by Activiti.

the class HistoricTaskInstanceCollectionResourceTest method testQueryTaskInstances.

/**
   * Test querying historic task instance. 
   * GET history/historic-task-instances
   */
@Deployment
public void testQueryTaskInstances() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    Calendar created = Calendar.getInstance();
    created.set(Calendar.YEAR, 2001);
    created.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(created.getTime());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "testBusinessKey", processVariables);
    processEngineConfiguration.getClock().reset();
    Task task1 = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task1.getId());
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "local", "test");
    taskService.setOwner(task.getId(), "test");
    taskService.setDueDate(task.getId(), new GregorianCalendar(2013, 0, 1).getTime());
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", processVariables, "myTenant");
    Task task2 = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult();
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_TASK_INSTANCES);
    assertResultsPresentInDataResponse(url, 3, task.getId(), task2.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionName=" + "The%20One%20Task%20Process", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionNameLike=" + "The%25", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionKey=" + "oneTaskProcess", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionKeyLike=" + "oneTask%25", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?taskMinPriority=" + "0", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?taskMaxPriority=" + "60", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processBusinessKey=" + "testBusinessKey", 2, task.getId());
    assertResultsPresentInDataResponse(url + "?processBusinessKeyLike=" + "testBusin%25", 2, task.getId());
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 2, task.getId());
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 1, task2.getId());
    assertResultsPresentInDataResponse(url + "?taskAssignee=kermit", 2, task2.getId());
    assertResultsPresentInDataResponse(url + "?taskAssigneeLike=" + encode("%mit"), 2, task2.getId());
    assertResultsPresentInDataResponse(url + "?taskAssignee=fozzie", 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskOwner=test", 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskOwnerLike=" + encode("t%"), 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskInvolvedUser=test", 1, task.getId());
    assertResultsPresentInDataResponse(url + "?dueDateAfter=" + dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime()), 1, task.getId());
    assertResultsPresentInDataResponse(url + "?dueDateAfter=" + dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime()), 0);
    assertResultsPresentInDataResponse(url + "?dueDateBefore=" + dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime()), 0);
    assertResultsPresentInDataResponse(url + "?dueDateBefore=" + dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime()), 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskCreatedOn=" + dateFormat.format(created.getTime()), 1, task1.getId());
    created.set(Calendar.YEAR, 2002);
    assertResultsPresentInDataResponse(url + "?taskCreatedBefore=" + dateFormat.format(created.getTime()), 1, task1.getId());
    created.set(Calendar.YEAR, 2000);
    assertResultsPresentInDataResponse(url + "?taskCreatedAfter=" + dateFormat.format(created.getTime()), 3, task1.getId(), task2.getId());
    // Without tenant id
    assertResultsPresentInDataResponse(url + "?withoutTenantId=true", 2, task.getId(), task1.getId());
    // Tenant id
    assertResultsPresentInDataResponse(url + "?tenantId=myTenant", 1, task2.getId());
    assertResultsPresentInDataResponse(url + "?tenantId=anotherTenant", 0);
    // Tenant id like
    assertResultsPresentInDataResponse(url + "?tenantIdLike=" + encode("%enant"), 1, task2.getId());
    assertResultsPresentInDataResponse(url + "?tenantIdLike=anotherTenant", 0);
}
Also used : Task(org.activiti.engine.task.Task) ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with ChangeDeploymentTenantIdCmd

use of org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd in project Activiti by Activiti.

the class JobResourceTest method testGetJob.

/**
   * Test getting a single job. 
   */
@Deployment(resources = { "org/activiti/rest/service/api/management/JobResourceTest.testTimerProcess.bpmn20.xml" })
public void testGetJob() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(timerJob);
    Calendar now = Calendar.getInstance();
    now.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(now.getTime());
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId())), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(timerJob.getId(), responseNode.get("id").textValue());
    assertEquals(timerJob.getExceptionMessage(), responseNode.get("exceptionMessage").textValue());
    assertEquals(timerJob.getExecutionId(), responseNode.get("executionId").textValue());
    assertEquals(timerJob.getProcessDefinitionId(), responseNode.get("processDefinitionId").textValue());
    assertEquals(timerJob.getProcessInstanceId(), responseNode.get("processInstanceId").textValue());
    assertEquals(timerJob.getRetries(), responseNode.get("retries").intValue());
    assertEquals(timerJob.getDuedate(), getDateFromISOString(responseNode.get("dueDate").textValue()));
    assertEquals("", responseNode.get("tenantId").textValue());
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB, timerJob.getId())), HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myTenant", responseNode.get("tenantId").textValue());
}
Also used : ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 4 with ChangeDeploymentTenantIdCmd

use of org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd in project Activiti by Activiti.

the class ExecutionCollectionResourceTest method testGetExecutions.

/**
   * Test getting a list of executions, using all possible filters.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutions() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    String id = processInstance.getId();
    runtimeService.addUserIdentityLink(id, "kermit", "whatever");
    Execution childExecution = runtimeService.createExecutionQuery().activityId("processTask").singleResult();
    assertNotNull(childExecution);
    // Test without any parameters
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION);
    assertResultsPresentInDataResponse(url, id, childExecution.getId());
    // Process instance id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=" + id;
    assertResultsPresentInDataResponse(url, id);
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=anotherId";
    assertResultsPresentInDataResponse(url);
    // Process instance business key
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=myBusinessKey";
    assertResultsPresentInDataResponse(url, id);
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=anotherBusinessKey";
    assertResultsPresentInDataResponse(url);
    // Process definition key
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processOne";
    assertResultsPresentInDataResponse(url, id, childExecution.getId());
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processTwo";
    assertResultsPresentInDataResponse(url);
    // Process definition id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId();
    assertResultsPresentInDataResponse(url, id, childExecution.getId());
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=anotherId";
    assertResultsPresentInDataResponse(url);
    // Parent id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=" + id;
    assertResultsPresentInDataResponse(url, childExecution.getId());
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=anotherId";
    assertResultsPresentInDataResponse(url);
    // Activity id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=processTask";
    assertResultsPresentInDataResponse(url, childExecution.getId());
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=anotherId";
    assertResultsPresentInDataResponse(url);
    // Without tenant ID, before tenant is set
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true";
    assertResultsPresentInDataResponse(url, id, childExecution.getId());
    // Update the tenant for the deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    // Without tenant ID, after tenant is set
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true";
    assertResultsPresentInDataResponse(url);
    // Tenant id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant";
    assertResultsPresentInDataResponse(url, id, childExecution.getId());
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant2";
    assertResultsPresentInDataResponse(url);
    // Tenant id like
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%enant");
    assertResultsPresentInDataResponse(url, id, childExecution.getId());
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%whatever");
    assertResultsPresentInDataResponse(url);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 5 with ChangeDeploymentTenantIdCmd

use of org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd in project Activiti by Activiti.

the class ProcessInstanceCollectionResourceTest method testGetProcessInstancesTenant.

/**
   * Test getting a list of process instance, using all tenant filters.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testGetProcessInstancesTenant() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    String id = processInstance.getId();
    // Test without tenant id
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?withoutTenantId=true";
    assertResultsPresentInDataResponse(url, id);
    // Update the tenant for the deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    // Test tenant id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantId=myTenant";
    assertResultsPresentInDataResponse(url, id);
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantId=anotherTenant";
    assertResultsPresentInDataResponse(url);
    // Test tenant id like
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantIdLike=" + encode("%enant");
    assertResultsPresentInDataResponse(url, id);
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantIdLike=" + encode("%what");
    assertResultsPresentInDataResponse(url);
    // Test without tenant id
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?withoutTenantId=true";
    assertResultsPresentInDataResponse(url);
}
Also used : ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ChangeDeploymentTenantIdCmd (org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 Deployment (org.activiti.engine.test.Deployment)10 Calendar (java.util.Calendar)6 Task (org.activiti.engine.task.Task)5 HttpGet (org.apache.http.client.methods.HttpGet)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 Job (org.activiti.engine.runtime.Job)2 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 ActivitiException (org.activiti.engine.ActivitiException)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 Execution (org.activiti.engine.runtime.Execution)1