Search in sources :

Example 56 with ProcessDefinition

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

the class ProcessDefinitionSuspensionTest method testContinueProcessAfterProcessDefinitionSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testContinueProcessAfterProcessDefinitionSuspend() {
    // Start Process Instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    // Verify one task is created
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    // Suspend process definition
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    // Process should be able to continue
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 57 with ProcessDefinition

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

the class ProcessDefinitionSuspensionTest method testDelayedActivateProcessDefinition.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedActivateProcessDefinition() {
    Date startTime = new Date();
    processEngineConfiguration.getClock().setCurrentTime(startTime);
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    // Try to start process instance. It should fail now.
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail();
    } catch (ActivitiException e) {
        assertTextPresentIgnoreCase("suspended", e.getMessage());
    }
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Activate in a day from now
    long oneDayFromStart = startTime.getTime() + (24 * 60 * 60 * 1000);
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), false, new Date(oneDayFromStart));
    // Move clock two days and let job executor run
    long twoDaysFromStart = startTime.getTime() + (2 * 24 * 60 * 60 * 1000);
    processEngineConfiguration.getClock().setCurrentTime(new Date(twoDaysFromStart));
    waitForJobExecutorToProcessAllJobs(5000L, 50L);
    // Starting a process instance should now succeed
    runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 58 with ProcessDefinition

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

the class ProcessDefinitionSuspensionTest method testDelayedSuspendProcessDefinitionIncludingProcessInstances.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedSuspendProcessDefinitionIncludingProcessInstances() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    Date startTime = new Date();
    processEngineConfiguration.getClock().setCurrentTime(startTime);
    // Start some process instances
    int nrOfProcessInstances = 30;
    for (int i = 0; i < nrOfProcessInstances; i++) {
        runtimeService.startProcessInstanceById(processDefinition.getId());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Suspend process definition in one week from now
    long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000);
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, new Date(oneWeekFromStartTime));
    // Verify we can start process instances
    runtimeService.startProcessInstanceById(processDefinition.getId());
    nrOfProcessInstances = nrOfProcessInstances + 1;
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    // Move clock 9 days further and let job executor run
    long eightDaysSinceStartTime = oneWeekFromStartTime + (2 * 24 * 60 * 60 * 1000);
    processEngineConfiguration.getClock().setCurrentTime(new Date(eightDaysSinceStartTime));
    waitForJobExecutorToProcessAllJobs(5000L, 50L);
    // Try to start process instance. It should fail now.
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail();
    } catch (ActivitiException e) {
        assertTextPresentIgnoreCase("suspended", e.getMessage());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Activate again
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null);
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 59 with ProcessDefinition

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

the class RepositoryServiceTest method testProcessDefinitionEntitySerializable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testProcessDefinitionEntitySerializable() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessDefinition processDefinition = repositoryService.getProcessDefinition(procDefId);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(processDefinition);
        byte[] bytes = baos.toByteArray();
        assertTrue(bytes.length > 0);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) Deployment(org.activiti.engine.test.Deployment)

Example 60 with ProcessDefinition

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

the class RepositoryServiceTest method testStartProcessInstanceById.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testStartProcessInstanceById() {
    List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
    assertEquals(1, processDefinitions.size());
    ProcessDefinition processDefinition = processDefinitions.get(0);
    assertEquals("oneTaskProcess", processDefinition.getKey());
    assertNotNull(processDefinition.getId());
}
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