Search in sources :

Example 51 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class RepositoryServiceTest method testGetBpmnModel.

@Deployment
public void testGetBpmnModel() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    // Some basic assertions
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    assertNotNull(bpmnModel);
    assertEquals(1, bpmnModel.getProcesses().size());
    assertTrue(!bpmnModel.getLocationMap().isEmpty());
    assertTrue(!bpmnModel.getFlowLocationMap().isEmpty());
    // Test the flow
    org.activiti.bpmn.model.Process process = bpmnModel.getProcesses().get(0);
    List<StartEvent> startEvents = process.findFlowElementsOfType(StartEvent.class);
    assertEquals(1, startEvents.size());
    StartEvent startEvent = startEvents.get(0);
    assertEquals(1, startEvent.getOutgoingFlows().size());
    assertEquals(0, startEvent.getIncomingFlows().size());
    String nextElementId = startEvent.getOutgoingFlows().get(0).getTargetRef();
    UserTask userTask = (UserTask) process.getFlowElement(nextElementId);
    assertEquals("First Task", userTask.getName());
    assertEquals(1, userTask.getOutgoingFlows().size());
    assertEquals(1, userTask.getIncomingFlows().size());
    nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
    ParallelGateway parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
    assertEquals(2, parallelGateway.getOutgoingFlows().size());
    nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
    assertEquals(1, parallelGateway.getIncomingFlows().size());
    userTask = (UserTask) process.getFlowElement(nextElementId);
    assertEquals(1, userTask.getOutgoingFlows().size());
    nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
    parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
    assertEquals(1, parallelGateway.getOutgoingFlows().size());
    assertEquals(2, parallelGateway.getIncomingFlows().size());
    nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
    EndEvent endEvent = (EndEvent) process.getFlowElement(nextElementId);
    assertEquals(0, endEvent.getOutgoingFlows().size());
    assertEquals(1, endEvent.getIncomingFlows().size());
}
Also used : ParallelGateway(org.activiti.bpmn.model.ParallelGateway) StartEvent(org.activiti.bpmn.model.StartEvent) UserTask(org.activiti.bpmn.model.UserTask) EndEvent(org.activiti.bpmn.model.EndEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.test.Deployment)

Example 52 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class RuntimeServiceTest method testStartProcessInstanceByProcessInstanceBuilder.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testStartProcessInstanceByProcessInstanceBuilder() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
    // by key
    ProcessInstance processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("123").start();
    assertNotNull(processInstance);
    assertEquals("123", processInstance.getBusinessKey());
    assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
    processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
    // by key, with processInstance name with variables
    processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("456").addVariable("var", "value").processInstanceName("processName1").start();
    assertNotNull(processInstance);
    assertEquals(2, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
    assertEquals("processName1", processInstance.getName());
    assertEquals("456", processInstance.getBusinessKey());
    assertEquals("value", runtimeService.getVariable(processInstance.getId(), "var"));
    processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
    // by id
    processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("789").start();
    assertNotNull(processInstance);
    assertEquals(3, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
    assertEquals("789", processInstance.getBusinessKey());
    processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
    // by id with variables
    processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101123").addVariable("var", "value2").start();
    assertNotNull(processInstance);
    assertEquals(4, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
    assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "var"));
    assertEquals("101123", processInstance.getBusinessKey());
    processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
    // by id and processInstance name
    processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101124").processInstanceName("processName2").start();
    assertNotNull(processInstance);
    assertEquals(5, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
    assertEquals("processName2", processInstance.getName());
    assertEquals("101124", processInstance.getBusinessKey());
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 53 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ProcessDefinitionSuspensionTest method testStartProcessInstanceForSuspendedProcessDefinition.

@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml" })
public void testStartProcessInstanceForSuspendedProcessDefinition() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    // By id
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail("Exception is expected but not thrown");
    } catch (ActivitiException e) {
        assertTextPresentIgnoreCase("cannot start process instance", e.getMessage());
    }
    // By Key
    try {
        runtimeService.startProcessInstanceByKey(processDefinition.getKey());
        fail("Exception is expected but not thrown");
    } catch (ActivitiException e) {
        assertTextPresentIgnoreCase("cannot start process instance", e.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 54 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ProcessDefinitionSuspensionTest method testProcessDefinitionActiveByDefault.

@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml" })
public void testProcessDefinitionActiveByDefault() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertFalse(processDefinition.isSuspended());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 55 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ProcessDefinitionSuspensionTest method testQueryForActiveDefinitions.

@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml", "org/activiti/engine/test/db/processTwo.bpmn20.xml" })
public void testQueryForActiveDefinitions() {
    // default = all definitions
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().list();
    assertEquals(2, processDefinitionList.size());
    assertEquals(2, repositoryService.createProcessDefinitionQuery().active().count());
    ProcessDefinition processDefinition = processDefinitionList.get(0);
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)211 Deployment (org.activiti.engine.test.Deployment)82 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)42 ArrayList (java.util.ArrayList)29 ActivitiException (org.activiti.engine.ActivitiException)25 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)23 RepositoryService (org.activiti.engine.RepositoryService)20 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)19 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Task (org.activiti.engine.task.Task)16 Date (java.util.Date)14 Test (org.junit.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashMap (java.util.HashMap)12 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)11 InputStream (java.io.InputStream)10 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)9