Camunda单元测试中如何测试表单字段验证

时间:2019-04-08 10:43:13

标签: java unit-testing camunda

我创建了一个包含开始事件-userTask(两个userTasks)-结束事件的图。
在第二个userTask中,我具有布尔形式。
我想如果在测试单元中输入“ true”,则过程将结束。
如果我在测试单元中输入“ false”,则过程将返回到第一个userTask。
这是我的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();

    }
}

0 个答案:

没有答案
相关问题