org.activiti.engine.test.Deployment Java Examples

The following examples show how to use org.activiti.engine.test.Deployment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testDeeplyNestedErrorThrownOnlyAutomaticSteps() {
  // input == 1 -> error2 is thrown -> caught on subprocess2 -> end event in subprocess -> proc inst end 1
  String procId = runtimeService.startProcessInstanceByKey("deeplyNestedErrorThrown", 
          CollectionUtil.singletonMap("input", 1)).getId();
  assertProcessEnded(procId);
  
  HistoricProcessInstance hip;
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    hip = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
    assertEquals("processEnd1", hip.getEndActivityId());
  }
  // input == 2 -> error2 is thrown -> caught on subprocess1 -> proc inst end 2
  procId = runtimeService.startProcessInstanceByKey("deeplyNestedErrorThrown", 
          CollectionUtil.singletonMap("input", 1)).getId();
  assertProcessEnded(procId);
  
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    hip = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
    assertEquals("processEnd1", hip.getEndActivityId());
  }
}
 
Example #2
Source File: BusinessProcessContextTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testChangeProcessScopedBeanProperty() throws Exception {

  // resolve the creditcard bean (@BusinessProcessScoped) and set a value:
  getBeanInstance(CreditCard.class).setCreditcardNumber("123");
  String pid = getBeanInstance(BusinessProcess.class).startProcessByKey("testConversationalBeanStoreFlush").getId();

  getBeanInstance(BusinessProcess.class).startTask(taskService.createTaskQuery().singleResult().getId());

  // assert that the value of creditCardNumber is '123'
  assertEquals("123", getBeanInstance(CreditCard.class).getCreditcardNumber());
  // set a different value:
  getBeanInstance(CreditCard.class).setCreditcardNumber("321");
  // complete the task
  getBeanInstance(BusinessProcess.class).completeTask();

  getBeanInstance(BusinessProcess.class).associateExecutionById(pid);

  // now assert that the value of creditcard is "321":
  assertEquals("321", getBeanInstance(CreditCard.class).getCreditcardNumber());

  // complete the task to allow the process instance to terminate
  taskService.complete(taskService.createTaskQuery().singleResult().getId());

}
 
Example #3
Source File: ProcessInstanceIdentityLinkTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSetAuthenticatedUserAndCompleteLastTask() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("identityLinktest");

  // There are two tasks

  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());

  identityService.setAuthenticatedUserId("kermit");
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  identityService.setAuthenticatedUserId(null);

  assertProcessEnded(processInstance.getId());

}
 
Example #4
Source File: BpmnParseTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParseNamespaceInConditionExpressionType() {
  ProcessDefinition processDefinition = processEngineConfiguration.getActiviti5CompatibilityHandler().getProcessDefinitionByKey("resolvableNamespacesProcess");
  ProcessDefinitionEntity rawEntity = (ProcessDefinitionEntity) processDefinition;
  
  // Test that the process definition has been deployed
  assertNotNull(rawEntity);
  ActivityImpl activity = rawEntity.findActivity("ExclusiveGateway_1");
  assertNotNull(activity);
  
  // Test that the conditions has been resolved
  for (PvmTransition transition : activity.getOutgoingTransitions()) {
    if (transition.getDestination().getId().equals("Task_2")) {
      assertTrue(transition.getProperty("conditionText").equals("#{approved}"));
    } else if (transition.getDestination().getId().equals("Task_3")) {
      assertTrue(transition.getProperty("conditionText").equals("#{!approved}"));
    } else {
      fail("Something went wrong");
    }
    
  }
}
 
Example #5
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneSubProcess.bpmn20.xml" })
public void testRemoveVariableLocalWithParentScope() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("variable1", "value1");
  vars.put("variable2", "value2");

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startSimpleSubProcess", vars);
  Task currentTask = taskService.createTaskQuery().singleResult();
  runtimeService.setVariableLocal(currentTask.getExecutionId(), "localVariable", "local value");

  assertEquals("local value", runtimeService.getVariableLocal(currentTask.getExecutionId(), "localVariable"));

  runtimeService.removeVariableLocal(currentTask.getExecutionId(), "localVariable");

  assertNull(runtimeService.getVariable(currentTask.getExecutionId(), "localVariable"));
  assertNull(runtimeService.getVariableLocal(currentTask.getExecutionId(), "localVariable"));

  assertEquals("value1", runtimeService.getVariable(processInstance.getId(), "variable1"));
  assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "variable2"));

  assertEquals("value1", runtimeService.getVariable(currentTask.getExecutionId(), "variable1"));
  assertEquals("value2", runtimeService.getVariable(currentTask.getExecutionId(), "variable2"));

  checkHistoricVariableUpdateEntity("localVariable", processInstance.getId());
}
 
Example #6
Source File: ExecutionListenerTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/examples/bpmn/executionlistener/ExecutionListenersCurrentActivity.bpmn20.xml" })
public void testExecutionListenerCurrentActivity() {

  CurrentActivityExecutionListener.clear();

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionListenersProcess");
  assertProcessEnded(processInstance.getId());

  List<CurrentActivity> currentActivities = CurrentActivityExecutionListener.getCurrentActivities();
  assertEquals(3, currentActivities.size());

  assertEquals("theStart", currentActivities.get(0).getActivityId());
  assertEquals("Start Event", currentActivities.get(0).getActivityName());

  assertEquals("noneEvent", currentActivities.get(1).getActivityId());
  assertEquals("None Event", currentActivities.get(1).getActivityName());

  assertEquals("theEnd", currentActivities.get(2).getActivityId());
  assertEquals("End Event", currentActivities.get(2).getActivityName());
}
 
Example #7
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testRemoveVariableLocal() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  Task currentTask = taskService.createTaskQuery().singleResult();

  taskService.setVariableLocal(currentTask.getId(), "variable1", "value1");
  assertEquals("value1", taskService.getVariable(currentTask.getId(), "variable1"));
  assertEquals("value1", taskService.getVariableLocal(currentTask.getId(), "variable1"));

  taskService.removeVariableLocal(currentTask.getId(), "variable1");

  assertNull(taskService.getVariable(currentTask.getId(), "variable1"));
  assertNull(taskService.getVariableLocal(currentTask.getId(), "variable1"));

  checkHistoricVariableUpdateEntity("variable1", processInstance.getId());
}
 
Example #8
Source File: InclusiveGatewayTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testNoIdOnSequenceFlow() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("inclusiveNoIdOnSequenceFlow", CollectionUtil.singletonMap("input", 3));
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  assertEquals("Input is more than one", task.getName());

  // Both should be enabled on 1
  pi = runtimeService.startProcessInstanceByKey("inclusiveNoIdOnSequenceFlow", CollectionUtil.singletonMap("input", 1));
  List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();
  assertEquals(2, tasks.size());
  Map<String, String> expectedNames = new HashMap<String, String>();
  expectedNames.put("Input is one", "Input is one");
  expectedNames.put("Input is more than one", "Input is more than one");
  for (Task t : tasks) {
    expectedNames.remove(t.getName());
  }
  assertEquals(0, expectedNames.size());
}
 
Example #9
Source File: HistoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByProcessInstanceIds() {
  HashSet<String> processInstanceIds = new HashSet<String>();
  for (int i = 0; i < 4; i++) {
    processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
  }
  processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());

  // start an instance that will not be part of the query
  runtimeService.startProcessInstanceByKey("oneTaskProcess2", "2");

  HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceIds(processInstanceIds);
  assertEquals(5, processInstanceQuery.count());

  List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
  assertNotNull(processInstances);
  assertEquals(5, processInstances.size());

  for (HistoricProcessInstance historicProcessInstance : processInstances) {
    assertTrue(processInstanceIds.contains(historicProcessInstance.getId()));
  }
}
 
Example #10
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelSubProcess.bpmn20.xml" })
public void testParallelSubProcessHistory() {
  runtimeService.startProcessInstanceByKey("miParallelSubprocess");
  for (Task task : taskService.createTaskQuery().list()) {
    taskService.complete(task.getId());
  }

  // Validate history
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("miSubProcess").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance hai : historicActivityInstances) {
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getEndTime());
    }
  }
}
 
Example #11
Source File: AsyncExclusiveJobsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/** 
 * Test for https://activiti.atlassian.net/browse/ACT-4035.
 */
@Deployment
public void testExclusiveJobs() {
	
	if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
	
		// The process has two script tasks in parallel, both exclusive.
		// They should be executed with at least 6 seconds in between (as they both sleep for 6 seconds)
		runtimeService.startProcessInstanceByKey("testExclusiveJobs");
		waitForJobExecutorToProcessAllJobs(20000L, 500L);
		
		HistoricActivityInstance scriptTaskAInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskA").singleResult();
		HistoricActivityInstance scriptTaskBInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskB").singleResult();
		
		long endTimeA = scriptTaskAInstance.getEndTime().getTime();
		long endTimeB = scriptTaskBInstance.getEndTime().getTime();
		long endTimeDifference = 0;
		if (endTimeB > endTimeA) {
			endTimeDifference = endTimeB - endTimeA;
		} else {
			endTimeDifference = endTimeA - endTimeB;
		}
		assertTrue(endTimeDifference > 6000); // > 6000 -> jobs were executed in parallel
	}
	
}
 
Example #12
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/engine/test/history/calledProcess.bpmn20.xml",
        "org/activiti5/engine/test/history/HistoricActivityInstanceTest.testCallSimpleSubProcess.bpmn20.xml"
      })
public void testHistoricActivityInstanceCalledProcessId() {    
  runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

  HistoricActivityInstance historicActivityInstance = historyService
    .createHistoricActivityInstanceQuery()
    .activityId("callSubProcess")
    .singleResult();
  
  HistoricProcessInstance oldInstance = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("calledProcess").singleResult();
  
  assertEquals(oldInstance.getId(), historicActivityInstance.getCalledProcessInstanceId());
}
 
Example #13
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTwoSubProcessInParallelWithinSubProcess() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
    assertEquals(2, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("myVar", historicVariable.getName());
    assertEquals("test101112", historicVariable.getTextValue());

    HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
    assertEquals("myVar1", historicVariable1.getName());
    assertEquals("test789", historicVariable1.getTextValue());

    assertEquals(18, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(7, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #14
Source File: BusinessProcessBeanTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/activiti/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveProcessInstanceBean() {
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);

  assertNull(getBeanInstance(ProcessInstance.class));
  assertNull(getBeanInstance("processInstanceId"));
  assertNull(getBeanInstance(Execution.class));
  assertNull(getBeanInstance("executionId"));

  String pid = businessProcess.startProcessByKey("businessProcessBeanTest").getId();

  // assert that now we can resolve the ProcessInstance-bean
  assertEquals(pid, getBeanInstance(ProcessInstance.class).getId());
  assertEquals(pid, getBeanInstance("processInstanceId"));
  assertEquals(pid, getBeanInstance(Execution.class).getId());
  assertEquals(pid, getBeanInstance("executionId"));

  taskService.complete(taskService.createTaskQuery().singleResult().getId());
}
 
Example #15
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testCatchErrorOnParallelMultiInstance() {
  String procId = runtimeService.startProcessInstanceByKey("catchErrorOnParallelMi").getId();
  List<Task> tasks = taskService.createTaskQuery().list();
  assertEquals(5, tasks.size());

  // Complete two subprocesses, just to make it a bit more complex
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("throwError", false);
  taskService.complete(tasks.get(2).getId(), vars);
  taskService.complete(tasks.get(3).getId(), vars);

  // Reach the error event
  vars.put("throwError", true);
  taskService.complete(tasks.get(1).getId(), vars);

  assertEquals(0, taskService.createTaskQuery().count());
  assertProcessEnded(procId);
}
 
Example #16
Source File: TaskBatchDeleteTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testDeleteCancelledMultiInstanceTasks() throws Exception {
    
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testBatchDeleteOfTask");
    assertNotNull(processInstance);
    assertFalse(processInstance.isEnded());
    
    Task lastTask = taskService.createTaskQuery().processInstanceId(processInstance.getId())
            .taskDefinitionKey("multiInstance").listPage(4, 1).get(0);
    
    taskService.addCandidateGroup(lastTask.getId(), "sales");
    
    Task firstTask = taskService.createTaskQuery().processInstanceId(processInstance.getId())
            .taskDefinitionKey("multiInstance").listPage(0, 1).get(0);
    assertNotNull(firstTask);
    
    taskService.complete(firstTask.getId());
    
    // Process should have ended fine
    processInstance = runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstance.getId())
            .singleResult();
    assertNull(processInstance);
}
 
Example #17
Source File: ProcessInstanceIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testParticipantUserLink() {
  Authentication.setAuthenticatedUserId(null);
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
  
  String processInstanceId = runtimeService
    .createProcessInstanceQuery()
    .singleResult()
    .getId();
  
  runtimeService.addParticipantUser(processInstanceId, "kermit");
  
  List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
  IdentityLink identityLink = identityLinks.get(0);
  
  assertNull(identityLink.getGroupId());
  assertEquals("kermit", identityLink.getUserId());
  assertEquals(IdentityLinkType.PARTICIPANT, identityLink.getType());
  assertEquals(processInstanceId, identityLink.getProcessInstanceId());
  
  assertEquals(1, identityLinks.size());

  runtimeService.deleteParticipantUser(processInstanceId, "kermit");
  
  assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
 
Example #18
Source File: ExpressionBeanAccessTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testConfigurationBeanAccess() {
  // Exposed bean returns 'I'm exposed' when to-string is called in first
  // service-task
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("expressionBeanAccess");
  assertEquals("I'm exposed", runtimeService.getVariable(pi.getId(), "exposedBeanResult"));

  // After signaling, an expression tries to use a bean that is present in
  // the configuration but is not added to the beans-list
  try {
    runtimeService.trigger(runtimeService.createExecutionQuery().processInstanceId(pi.getId()).onlyChildExecutions().singleResult().getId());
    fail("Exception expected");
  } catch (ActivitiException ae) {
    assertNotNull(ae.getCause());
    assertTrue(ae.getCause() instanceof RuntimeException);
    RuntimeException runtimeException = (RuntimeException) ae.getCause();
    assertTrue(runtimeException.getCause() instanceof PropertyNotFoundException);
  }
}
 
Example #19
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testChangeFormKey() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getFormKey());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskFormKey("task1", "test2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test2", task.getFormKey());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example #20
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testDeployDifferentFiles() {
  String bpmnResourceName = "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml";
  repositoryService.createDeployment().enableDuplicateFiltering().addClasspathResource(bpmnResourceName).name("twice").deploy();

  String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId();
  List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId);

  // verify bpmn file name
  assertEquals(1, deploymentResources.size());
  assertEquals(bpmnResourceName, deploymentResources.get(0));

  bpmnResourceName = "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml";
  repositoryService.createDeployment().enableDuplicateFiltering().addClasspathResource(bpmnResourceName).name("twice").deploy();
  List<org.activiti.engine.repository.Deployment> deploymentList = repositoryService.createDeploymentQuery().list();
  assertEquals(2, deploymentList.size());

  for (org.activiti.engine.repository.Deployment deployment : deploymentList) {
    repositoryService.deleteDeployment(deployment.getId());
  }
}
 
Example #21
Source File: JobExecutorExceptionsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/activiti/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testQueryByExceptionWithRealJobExecutor() {
  TimerJobQuery query = managementService.createTimerJobQuery().withException();
  Assert.assertEquals(0, query.count());

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exceptionInJobExecution");

  // Timer is set for 4 hours, so move clock 5 hours
  processEngineConfiguration.getClock().setCurrentTime(new Date(new Date().getTime() + 5 * 60 * 60 * 1000));

  // The execution is waiting in the first usertask. This contains a
  // boundary timer event which we will execute manual for testing purposes.
  JobTestHelper.waitForJobExecutorOnCondition(processEngineConfiguration, 5000L, 100L, new Callable<Boolean>() {
    public Boolean call() throws Exception {
      return managementService.createTimerJobQuery().withException().count() == 1;
    }
  });

  query = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).withException();
  Assert.assertEquals(1, query.count());
}
 
Example #22
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialCallActivity.bpmn20.xml",
    "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.externalSubProcess.bpmn20.xml" })
public void testSequentialCallActivity() {
  String procId = runtimeService.startProcessInstanceByKey("miSequentialCallActivity").getId();

  for (int i = 0; i < 3; i++) {
    List<Task> tasks = taskService.createTaskQuery().orderByTaskName().asc().list();
    assertEquals(2, tasks.size());
    assertEquals("task one", tasks.get(0).getName());
    assertEquals("task two", tasks.get(1).getName());
    taskService.complete(tasks.get(0).getId());
    taskService.complete(tasks.get(1).getId());
  }

  assertProcessEnded(procId);
}
 
Example #23
Source File: EventBasedGatewayTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={
        "org/activiti5/engine/test/bpmn/gateway/EventBasedGatewayTest.testCatchAlertAndTimer.bpmn20.xml",
        "org/activiti5/engine/test/bpmn/gateway/EventBasedGatewayTest.throwAlertSignal.bpmn20.xml"})
public void testCatchSignalCancelsTimer() {
  
  runtimeService.startProcessInstanceByKey("catchSignal");
      
  assertEquals(1, createEventSubscriptionQuery().count());    
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());
  assertEquals(1, managementService.createTimerJobQuery().count());
  
  runtimeService.startProcessInstanceByKey("throwSignal");
  
  assertEquals(0, createEventSubscriptionQuery().count());    
  assertEquals(1, runtimeService.createProcessInstanceQuery().count());    
  assertEquals(0, managementService.createTimerJobQuery().count());
  
  Task task = taskService.createTaskQuery()
    .taskName("afterSignal")
    .singleResult();
  
  assertNotNull(task);
  
  taskService.complete(task.getId());
     
}
 
Example #24
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelNoWaitState() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(7, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(2, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #25
Source File: CamelExceptionTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/camel/exception/bpmnExceptionInRouteSynchronous.bpmn20.xml" })
public void testNonBpmnExceptionInCamel() {
  // Signal ThrowBpmnExceptionBean to throw a non BPMN Exception
  ThrowBpmnExceptionBean.setExceptionType(ThrowBpmnExceptionBean.ExceptionType.NON_BPMN_EXCEPTION);

  try {
    runtimeService.startProcessInstanceByKey("exceptionInRouteSynchron");
  } catch (ActivitiException e) {
    assertEquals(Exception.class, e.getCause().getClass());
    assertEquals("arbitary non bpmn exception", e.getCause().getMessage());

    assertFalse(ExceptionServiceMock.isCalled());
    assertFalse(NoExceptionServiceMock.isCalled());

    return;
  }
  fail("Activiti exception expected");
}
 
Example #26
Source File: ExclusiveTimerEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testCatchingTimerEvent() throws Exception {
  Clock clock = processEngineConfiguration.getClock();
  // Set the clock fixed
  Date startTime = new Date();
  clock.setCurrentTime(startTime);
  processEngineConfiguration.setClock(clock);

  // After process start, there should be 3 timers created
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("exclusiveTimers");
  TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
  assertEquals(3, jobQuery.count());

  // After setting the clock to time '50minutes and 5 seconds', the timers should fire
  clock.setCurrentTime(new Date(startTime.getTime() + ((50 * 60 * 1000) + 5000)));
  processEngineConfiguration.setClock(clock);
  waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(5000L, 200L);

  assertEquals(0, jobQuery.count());
  assertProcessEnded(pi.getProcessInstanceId());
  
  processEngineConfiguration.resetClock();
}
 
Example #27
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testQueryByDeploymentIdIn() throws Exception {
  org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
  runtimeService.startProcessInstanceByKey("oneTaskProcess");
  List<String> deploymentIds = new ArrayList<String>();
  deploymentIds.add(deployment.getId());
  assertNotNull(taskService.createTaskQuery().deploymentIdIn(deploymentIds).singleResult());
  assertEquals(1, taskService.createTaskQuery().deploymentIdIn(deploymentIds).count());

  deploymentIds.add("invalid");
  assertNotNull(taskService.createTaskQuery().deploymentIdIn(deploymentIds).singleResult());
  assertEquals(1, taskService.createTaskQuery().deploymentIdIn(deploymentIds).count());

  deploymentIds = new ArrayList<String>();
  deploymentIds.add("invalid");
  assertNull(taskService.createTaskQuery().deploymentIdIn(deploymentIds).singleResult());
  assertEquals(0, taskService.createTaskQuery().deploymentIdIn(deploymentIds).count());
}
 
Example #28
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test events related to error-events
 */
@Deployment
public void testActivityErrorEvents() throws Exception {
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("errorProcess");
	assertNotNull(processInstance);
	
	// Error-handling should have ended the process
	ProcessInstance afterErrorInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId())
			.singleResult();
	assertNull(afterErrorInstance);
	
	ActivitiErrorEvent errorEvent = null;
	
	for(ActivitiEvent event : listener.getEventsReceived()) {
		if(event instanceof ActivitiErrorEvent) {
			if(errorEvent == null) {
				errorEvent = (ActivitiErrorEvent) event;
			} else {
				fail("Only one ActivityErrorEvent expected");
			}
		}
	}
	
	assertNotNull(errorEvent);
	assertEquals(ActivitiEventType.ACTIVITY_ERROR_RECEIVED, errorEvent.getType());
	assertEquals("catchError", errorEvent.getActivityId());
	assertEquals("123", errorEvent.getErrorCode());
	assertEquals(processInstance.getId(), errorEvent.getProcessInstanceId());
	assertEquals(processInstance.getProcessDefinitionId(), errorEvent.getProcessDefinitionId());
	assertFalse(processInstance.getId().equals(errorEvent.getExecutionId()));
}
 
Example #29
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorOnCallActivity-parent.bpmn20.xml",
    "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml" })
public void testUncaughtErrorOnCallActivity() {
  runtimeService.startProcessInstanceByKey("uncaughtErrorOnCallActivity");
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task in subprocess", task.getName());

  try {
    // Completing the task will reach the end error event,
    // which is never caught in the process
    taskService.complete(task.getId());
  } catch (BpmnError e) {
    assertTextPresent("No catching boundary event found for error with errorCode 'myError', neither in same process nor in parent process", e.getMessage());
  }
}
 
Example #30
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testZeroLoopCardinalityOnParallelUserTask() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelUserTaskMi");
    assertEquals(1L, historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).finished().count());
  }
}