Как проверить валидацию поля формы в модульном тестировании Camunda - PullRequest
0 голосов
/ 08 апреля 2019

Я создал диаграмму, которая содержит начальное событие - userTask (две пользовательские задачи) - конечное событие.
Во втором пользовательском задании у меня есть логическая форма.
Я хочу, чтобы, если я поставлю «true» в тестовом блоке, процесс будет завершен.
И если я поставлю «false» в тестовом модуле, процесс вернется к первой пользовательской задаче.
это мой файл bpmn:

testProcess.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://bpmn.io/schema/bpmn" id="Definitions_1e0hqjp" exporter="Camunda Modeler" exporterVersion="2.2.4">
  <process id="BudgetDeclaration" name="BudgetDeclaration" isExecutable="true">
    <startEvent id="start" name="شروع">
      <extensionElements>
        <camunda:formData>
          <camunda:formField id="prc_instance_id" label="prc_instance_id" type="long"></camunda:formField>
        </camunda:formData>
      </extensionElements>
    </startEvent>
    <sequenceFlow id="SequenceFlow_1gmutkt" sourceRef="start" targetRef="task1"></sequenceFlow>
    <userTask id="task1" name="task1" activiti:assignee="task1"></userTask>
    <sequenceFlow id="SequenceFlow_1v3uoyt" sourceRef="task1" targetRef="task2"></sequenceFlow>
    <userTask id="task2" name="task2" activiti:assignee="task2">
      <extensionElements>
        <activiti:formProperty id="form1" name="form1" type="boolean" required="true">
          <activiti:value id="true" name="true"></activiti:value>
        </activiti:formProperty>
        <camunda:formData>
          <camunda:formField id="prc_ok" label="بررسی اطلاعات" type="boolean">
            <camunda:properties>
              <camunda:property id="true" value="تایید"></camunda:property>
              <camunda:property id="false" value="نیاز به اصلاح"></camunda:property>
            </camunda:properties>
          </camunda:formField>
        </camunda:formData>
      </extensionElements>
    </userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="task2" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_BudgetDeclaration">
    <bpmndi:BPMNPlane bpmnElement="BudgetDeclaration" id="BPMNPlane_BudgetDeclaration">
      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
        <omgdc:Bounds height="36.0" width="36.0" x="160.0" y="111.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task1" id="BPMNShape_task1">
        <omgdc:Bounds height="80.0" width="100.0" x="260.0" y="88.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task2" id="BPMNShape_task2">
        <omgdc:Bounds height="80.0" width="100.0" x="400.0" y="89.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="590.0" y="111.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="SequenceFlow_1gmutkt" id="BPMNEdge_SequenceFlow_1gmutkt">
        <omgdi:waypoint x="196.0" y="129.0"></omgdi:waypoint>
        <omgdi:waypoint x="260.0" y="128.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="SequenceFlow_1v3uoyt" id="BPMNEdge_SequenceFlow_1v3uoyt">
        <omgdi:waypoint x="360.0" y="128.0"></omgdi:waypoint>
        <omgdi:waypoint x="400.0" y="129.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="500.0" y="129.0"></omgdi:waypoint>
        <omgdi:waypoint x="590.0" y="128.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

и это мой файл тестового класса:

FinalTest.txt

import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.ProcessEngineRule;

import static org.assertj.core.api.Assertions.assertThat;
import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat;
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*;
import static org.junit.Assert.assertEquals;

import org.junit.Rule;
import org.junit.Test;

public class FinalTest {
    @Rule
    public ProcessEngineRule rule = new ProcessEngineRule();

    @Test
    @Deployment(resources = { "testProcess.bpmn" })
    public void executeProcess() {
        ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("BudgetDeclaration");

        assertThat(processInstance).isActive();
        assertThat(processInstanceQuery().count()).isEqualTo(1);
        assertThat(task(processInstance)).isAssignedTo("task1");
        assertThat(task(processInstance)).isNotNull();
        complete(task(processInstance));
        assertThat(task(processInstance)).isAssignedTo("task2");
        assertThat(task(processInstance)).isNotNull();



        complete(task(processInstance));
        assertThat(processInstance).isEnded();

    }
}
...