Search in sources :

Example 61 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testTaskOperationsFailAfterProcessInstanceSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskOperationsFailAfterProcessInstanceSuspend() {
    // Start a new process instance with one task
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    final Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    // Suspend the process instance
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    // Completing the task should fail
    try {
        taskService.complete(task.getId());
        fail("It is not allowed to complete a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Claiming the task should fail
    try {
        taskService.claim(task.getId(), "jos");
        fail("It is not allowed to claim a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variable on the task should fail
    try {
        taskService.setVariable(task.getId(), "someVar", "someValue");
        fail("It is not allowed to set a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variable on the task should fail
    try {
        taskService.setVariableLocal(task.getId(), "someVar", "someValue");
        fail("It is not allowed to set a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variables on the task should fail
    try {
        HashMap<String, String> variables = new HashMap<String, String>();
        variables.put("varOne", "one");
        variables.put("varTwo", "two");
        taskService.setVariables(task.getId(), variables);
        fail("It is not allowed to set variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variables on the task should fail
    try {
        HashMap<String, String> variables = new HashMap<String, String>();
        variables.put("varOne", "one");
        variables.put("varTwo", "two");
        taskService.setVariablesLocal(task.getId(), variables);
        fail("It is not allowed to set variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variable on the task should fail
    try {
        taskService.removeVariable(task.getId(), "someVar");
        fail("It is not allowed to remove a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variable on the task should fail
    try {
        taskService.removeVariableLocal(task.getId(), "someVar");
        fail("It is not allowed to remove a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variables on the task should fail
    try {
        taskService.removeVariables(task.getId(), Arrays.asList("one", "two"));
        fail("It is not allowed to remove variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variables on the task should fail
    try {
        taskService.removeVariablesLocal(task.getId(), Arrays.asList("one", "two"));
        fail("It is not allowed to remove variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding candidate groups on the task should fail
    try {
        taskService.addCandidateGroup(task.getId(), "blahGroup");
        fail("It is not allowed to add a candidate group on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding candidate users on the task should fail
    try {
        taskService.addCandidateUser(task.getId(), "blahUser");
        fail("It is not allowed to add a candidate user on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding candidate users on the task should fail
    try {
        taskService.addGroupIdentityLink(task.getId(), "blahGroup", IdentityLinkType.CANDIDATE);
        fail("It is not allowed to add a candidate user on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding an identity link on the task should fail
    try {
        taskService.addUserIdentityLink(task.getId(), "blahUser", IdentityLinkType.OWNER);
        fail("It is not allowed to add an identityLink on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding a comment on the task should fail
    try {
        taskService.addComment(task.getId(), processInstance.getId(), "test comment");
        fail("It is not allowed to add a comment on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding an attachment on the task should fail
    try {
        taskService.createAttachment("text", task.getId(), processInstance.getId(), "testName", "testDescription", "http://test.com");
        fail("It is not allowed to add an attachment on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Set an assignee on the task should fail
    try {
        taskService.setAssignee(task.getId(), "mispiggy");
        fail("It is not allowed to set an assignee on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Set an owner on the task should fail
    try {
        taskService.setOwner(task.getId(), "kermit");
        fail("It is not allowed to set an owner on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Set priority on the task should fail
    try {
        taskService.setPriority(task.getId(), 99);
        fail("It is not allowed to set a priority on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
}
Also used : Task(org.activiti.engine.task.Task) ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 62 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testSubmitTaskFormAfterProcessInstanceSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSubmitTaskFormAfterProcessInstanceSuspend() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    try {
        formService.submitTaskFormData(taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId(), new HashMap<String, String>());
        fail();
    } catch (ActivitiException e) {
    // This is expected
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 63 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testSignalEventReceivedAfterProcessInstanceSuspended.

@Deployment
public void testSignalEventReceivedAfterProcessInstanceSuspended() {
    final String signal = "Some Signal";
    // Test if process instance can be completed using the signal 
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // Now test when suspending the process instance: the process instance shouldn't be continued
    processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    runtimeService.signalEventReceived(signal, new HashMap<String, Object>());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    // Activate and try again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 64 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testCannotSuspendSuspendedProcessInstance.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testCannotSuspendSuspendedProcessInstance() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertFalse(processInstance.isSuspended());
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    try {
        runtimeService.suspendProcessInstanceById(processInstance.getId());
        fail("Expected activiti exception");
    } catch (ActivitiException e) {
    // expected
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 65 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testTaskQueryAfterProcessInstanceSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskQueryAfterProcessInstanceSuspend() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    task = taskService.createTaskQuery().active().singleResult();
    assertNotNull(task);
    // Suspend
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    assertEquals(1, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().active().count());
    // Activate
    runtimeService.activateProcessInstanceById(processInstance.getId());
    assertEquals(1, taskService.createTaskQuery().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(1, taskService.createTaskQuery().active().count());
    // Completing should end the process instance
    task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessInstance (org.activiti.engine.runtime.ProcessInstance)822 Deployment (org.activiti.engine.test.Deployment)708 Task (org.activiti.engine.task.Task)374 HashMap (java.util.HashMap)242 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)182 Execution (org.activiti.engine.runtime.Execution)76 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)64 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)57 Job (org.activiti.engine.runtime.Job)55 Date (java.util.Date)53 JsonNode (com.fasterxml.jackson.databind.JsonNode)49 Calendar (java.util.Calendar)48 ActivitiException (org.activiti.engine.ActivitiException)41 ArrayList (java.util.ArrayList)38 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)38 HttpGet (org.apache.http.client.methods.HttpGet)38 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)27 StringEntity (org.apache.http.entity.StringEntity)27 HttpPost (org.apache.http.client.methods.HttpPost)25 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)24