@Test
  public void testCouponValidation() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());

    /** Invalid coupon hash */
    for (Task task : tasks) {
      assertNotNull(task);
      assertEquals("get coupon", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("hash", "abc");
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());

    /** Valid coupon hash */
    for (Task task : tasks) {
      assertNotNull(task);
      assertEquals("get coupon", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("hash", "abcd");
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // check if the price was reduced correctly
    Object price = runtimeService.getVariable(processInstance.getId(), "price");
    assertNotNull(price);
    assertEquals(new Double(130), price);

    // 'get bank transfer data' should be next on the list
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get bank transfer data", tasks.get(0).getName());
  }
  @Test
  public void testBankTransferValidation() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());

    // Invalid bank data
    for (Task task : tasks) {
      assertNotNull(task);
      assertEquals("get bank transfer data", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("bankName", "Bank austria"); // invalid bank-name
      formData.put("bankCode", "12000");
      formData.put("accountNumber", "12345678901");
      formData.put("holdersName", "Max Muster");
      formService.submitTaskFormData(task.getId(), formData);
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    // As of an error the form should be empty
    assertEquals(0, formService.getTaskFormData(tasks.get(0).getId()).getFormProperties().size());

    // Valid bank data
    for (Task task : tasks) {
      assertNotNull(task);
      assertEquals("get bank transfer data", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("bankName", "Bank Austria");
      formData.put("bankCode", "12000");
      formData.put("accountNumber", "12345678901");
      formData.put("holdersName", "Max Muster");
      formService.submitTaskFormData(task.getId(), formData); // Stack trace starts here
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get acknowledgement", tasks.get(0).getName());
  }
  @Test
  public void testRemindCustomer() {
    createNewProcess();
    runtimeService.setVariable(pid, "RemainderAmount", "0");
    Task nextTask = taskService.createTaskQuery().singleResult();
    HashMap<String, String> map = new HashMap<String, String>();
    formService.submitTaskFormData(nextTask.getId(), map);

    Task nextTask2 = taskService.createTaskQuery().singleResult();
    formService.submitTaskFormData(nextTask2.getId(), map);

    Task nextTask3 = taskService.createTaskQuery().singleResult();
    formService.submitTaskFormData(nextTask3.getId(), map);

    Task lastTasks = taskService.createTaskQuery().singleResult();
  }
 @Test
 public void testMail() {
   createNewProcess();
   Task nextTask = taskService.createTaskQuery().singleResult();
   HashMap<String, String> map = new HashMap<String, String>();
   formService.submitTaskFormData(nextTask.getId(), map);
 }
  @Test
  public void testAcknowledgement() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get acknowledgement", tasks.get(0).getName());

    for (Task task : tasks) {
      Map<String, String> formData = new HashMap<String, String>();
      formService.submitTaskFormData(task.getId(), formData); // Stack trace starts here
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(0, tasks.size());
  }
 @RequestMapping(value = "/complete-task/{taskId}")
 public String completeTask(@PathVariable String taskId, HttpServletRequest request) {
   TaskFormData taskFormData = formService.getTaskFormData(taskId);
   boolean hasFormKey =
       taskFormData.getFormKey() != null && taskFormData.getFormKey().length() > 0;
   List<FormProperty> formProperties = taskFormData.getFormProperties();
   Map<String, String> formValues =
       generateFormValueMap(hasFormKey, formProperties, request); // 生成提交数据
   formService.submitTaskFormData(taskId, formValues);
   return "redirect:/identity/user";
 }
Exemplo n.º 7
0
  /**
   * 完成任务
   *
   * @return
   */
  public String completeTask() {
    HttpServletRequest request = ServletActionContext.getRequest();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(SpringSecurityUtils.getCurrentUsername());

    FormService formService = processEngine.getFormService();
    TaskFormData taskFormData = formService.getTaskFormData(taskId);

    Map<String, String> map = new HashMap<String, String>();

    for (FormProperty formProperty : taskFormData.getFormProperties()) {
      if (formProperty.isWritable()) {
        String name = formProperty.getId();
        map.put(name, request.getParameter(name));
      }
    }

    formService.submitTaskFormData(taskId, map);

    return RELOAD;
  }
  @Test
  public void testPaymentModality() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(2, tasks.size());
    List<String> expected = new ArrayList<String>();
    expected.add("get payment modalities");
    expected.add("get coupon");
    assertTrue(expected.contains(tasks.get(0).getName()));
    assertTrue(expected.contains(tasks.get(1).getName()));

    for (Task task : tasks) {
      assertNotNull(task);
      if (task.getName().equals("get payment modalities")) {
        Map<String, String> formData = new HashMap<String, String>();
        formData.put("paymentMethod", "bankTransferMethod");
        formService.submitTaskFormData(task.getId(), formData);

        break;
      }
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get coupon", tasks.get(0).getName());
  }
  @Test
  public void testAddressValidation() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    // Verify kermit can now retrieve the task
    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get address", tasks.get(0).getName());

    /** Invalid address */
    for (Task task : tasks) {
      assertEquals("get address", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("firstName", "Max");
      formData.put("lastName", "Muster");
      formData.put("street", "Mustergasse 2");
      formData.put("zip", "1080"); // wrong zip-code!
      formData.put("city", "Wien");
      formData.put("country", "Austria");
      formData.put("telNo", "1234567");
      formData.put("mailAddress", this.yourEMail);
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // There should only be one task available at this stage
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get address", tasks.get(0).getName());

    /** Valid address */
    for (Task task : tasks) {
      assertEquals("get address", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("firstName", "Max");
      formData.put("lastName", "Muster");
      formData.put("street", "Mustergasse 2");
      formData.put("zip", "1090");
      formData.put("city", "Wien");
      formData.put("country", "Austria");
      formData.put("telNo", "1234567");
      formData.put("mailAddress", this.yourEMail);
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // check if the customer was set correctly
    Customer customer = (Customer) runtimeService.getVariable(processInstance.getId(), "customer");
    assertNotNull(customer);
    assertEquals("Max", customer.getFirstName());
    assertEquals("Muster", customer.getLastName());
    assertEquals("Mustergasse 2", customer.getAddress().getStreet());

    // There should now be 2 tasks available
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(2, tasks.size());
    List<String> expected = new ArrayList<String>();
    expected.add("get payment modalities");
    expected.add("get coupon");
    assertTrue(expected.contains(tasks.get(0).getName()));
    assertTrue(expected.contains(tasks.get(1).getName()));
  }