@Deployment(
      resources = {
        "org/activiti/examples/bpmn/event/timer/BoundaryTimerEventTest.testInterruptingTimerDuration.bpmn"
      })
  @Test
  public void testInterruptingTimerDuration() {

    // Start process instance
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("escalationExample");

    // There should be one task, with a timer : first line support
    TaskService taskService = activitiRule.getTaskService();
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("First line support", task.getName());

    // Manually execute the job
    ManagementService managementService = activitiRule.getManagementService();
    Job timer = managementService.createJobQuery().singleResult();
    managementService.executeJob(timer.getId());

    // The timer has fired, and the second task (secondlinesupport) now exists
    task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Second line support", task.getName());
  }
Exemplo n.º 2
0
  @Test
  @Deployment(resources = {PROCESS_RESOURCE})
  public void processRejected() throws InterruptedException {
    Map<String, Object> procVars = createStartFormVariables();

    ProcessInstance pi =
        activitiRule
            .getProcessEngine()
            .getRuntimeService()
            .startProcessInstanceByKey(PROCESS_KEY, procVars);

    //		assertNotNull(pi);

    Task task = activitiRule.getTaskService().createTaskQuery().singleResult();
    //		assertNotNull(task);

    Map<String, Object> taskVars = new HashMap<String, Object>();
    taskVars.put("decide", "reject");
    activitiRule.getProcessEngine().getTaskService().complete(task.getId(), taskVars);

    HistoryService historyService = activitiRule.getHistoryService();

    HistoricProcessInstance historicProcessInstance =
        historyService
            .createHistoricProcessInstanceQuery()
            .processInstanceId(pi.getProcessInstanceId())
            .singleResult();

    //		assertNotNull(historicProcessInstance);
    // check that only one process running
    //		assertEquals(pi.getProcessInstanceId(), historicProcessInstance.getId());

    List<HistoricActivityInstance> activityList =
        historyService
            .createHistoricActivityInstanceQuery()
            .processInstanceId(pi.getProcessInstanceId())
            .list();

    JobQuery jquery = activitiRule.getManagementService().createJobQuery();

    // check how many tasks must be done
    //		assertEquals("done task count", 6, activityList.size());

    // and the job is done
    //		assertEquals("job is done", 0, jquery.count());

    //		assertEquals(0, activitiRule.getProcessEngine().getRuntimeService()
    //				.createProcessInstanceQuery().count());

  }
  private String startAndComplete() {
    RuntimeService runtimeService = activitiRule.getRuntimeService();

    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("isbn", "123456");
    String processInstanceID =
        runtimeService.startProcessInstanceByKey("bookorder", variableMap).getId();

    TaskService taskService = activitiRule.getTaskService();
    Task task = taskService.createTaskQuery().taskCandidateGroup("sales").singleResult();
    variableMap = new HashMap<String, Object>();
    variableMap.put("extraInfo", "Extra information");
    variableMap.put("isbn", "654321");
    taskService.complete(task.getId(), variableMap);
    return processInstanceID;
  }
  @Test
  public void startProcess() throws Exception {
    RepositoryService repositoryService = activitiRule.getRepositoryService();
    TaskService taskService = activitiRule.getTaskService();
    repositoryService
        .createDeployment()
        .addInputStream("process1.bpmn20.xml", new FileInputStream(filename))
        .deploy();
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("name", "Activiti");
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey("MyProcess", variableMap);
    assertNotNull(processInstance.getId());
    System.out.println(
        "id " + processInstance.getId() + " " + processInstance.getProcessDefinitionId());

    assertNotNull(taskService.createTaskQuery().taskAssignee("fg").singleResult());
  }