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());
}
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());
}
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());
}
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();
}
}
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());
}
Aggregations