Search in sources :

Example 41 with ProcessInstance

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

the class DynamicServiceTaskTest method testChangeExpression.

@Deployment
public void testChangeExpression() {
    // first test without changing the class name
    DummyTestBean testBean = new DummyTestBean();
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("bean", testBean);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertNotNull(historicVariableInstance);
        assertTrue((Boolean) historicVariableInstance.getValue());
    }
    assertProcessEnded(processInstance.getId());
    // now test with changing the class name
    testBean = new DummyTestBean();
    varMap = new HashMap<String, Object>();
    varMap.put("bean2", testBean);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    String processDefinitionId = processInstance.getProcessDefinitionId();
    ObjectNode infoNode = dynamicBpmnService.changeServiceTaskExpression("service", "${bean2.test(execution)}");
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertNotNull(historicVariableInstance);
        assertTrue((Boolean) historicVariableInstance.getValue());
    }
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 42 with ProcessInstance

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

the class DynamicServiceTaskTest method testChangeClassName.

@Deployment
public void testChangeClassName() {
    // first test without changing the class name
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("count", 0);
    varMap.put("count2", 0);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count"));
    assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count2"));
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
    // now test with changing the class name
    varMap = new HashMap<String, Object>();
    varMap.put("count", 0);
    varMap.put("count2", 0);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    String processDefinitionId = processInstance.getProcessDefinitionId();
    ObjectNode infoNode = dynamicBpmnService.changeServiceTaskClassName("service", "org.activiti.engine.test.bpmn.servicetask.DummyServiceTask2");
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count"));
    assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count2"));
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 43 with ProcessInstance

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

the class DynamicServiceTaskTest method testChangeDelegateExpression.

@Deployment
public void testChangeDelegateExpression() {
    // first test without changing the class name
    DummyTestDelegateBean testBean = new DummyTestDelegateBean();
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("bean", testBean);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertNotNull(historicVariableInstance);
        assertTrue((Boolean) historicVariableInstance.getValue());
    }
    assertProcessEnded(processInstance.getId());
    // now test with changing the class name
    testBean = new DummyTestDelegateBean();
    varMap = new HashMap<String, Object>();
    varMap.put("bean2", testBean);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    String processDefinitionId = processInstance.getProcessDefinitionId();
    ObjectNode infoNode = dynamicBpmnService.changeServiceTaskDelegateExpression("service", "${bean2}");
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertNotNull(historicVariableInstance);
        assertTrue((Boolean) historicVariableInstance.getValue());
    }
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 44 with ProcessInstance

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

the class CallActivityTest method testInstantiateChildProcess.

public void testInstantiateChildProcess() throws Exception {
    BpmnModel childBpmnModel = loadBPMNModel(CHILD_PROCESS_RESOURCE);
    Deployment childDeployment = processEngine.getRepositoryService().createDeployment().name("childProcessDeployment").addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();
    ProcessInstance childProcessInstance = runtimeService.startProcessInstanceByKey("childProcess");
    assertNotNull(childProcessInstance);
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 45 with ProcessInstance

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

the class CallActivityTest method testInstantiateSubprocess.

public void testInstantiateSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(CHILD_PROCESS_RESOURCE);
    Deployment childDeployment = processEngine.getRepositoryService().createDeployment().name("childProcessDeployment").addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();
    Deployment masterDeployment = processEngine.getRepositoryService().createDeployment().name("masterProcessDeployment").addBpmnModel("masterProcess.bpmn20.xml", mainBpmnModel).deploy();
    suspendProcessDefinitions(childDeployment);
    try {
        ProcessInstance masterProcessInstance = runtimeService.startProcessInstanceByKey("masterProcess");
        fail("Exception expected");
    } catch (ActivitiException ae) {
        assertTextPresent("Cannot start process instance. Process definition Child Process", ae.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel)

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