cancel
Showing results for 
Search instead for 
Did you mean: 

exclusive gateway test case

tomi87
Champ in-the-making
Champ in-the-making
Hello I don't know how I should write the test for the following exclusive gateway:


   <exclusiveGateway id="XORAProjectOrNot" name="" />
      <sequenceFlow id="flow63" name="Project" sourceRef="XORAProjectOrNot"
         targetRef="sendInformationsFromTheProfessors">
         <conditionExpression xsi:type="tFormalExpression">${StudentAppInfo.project == true}</conditionExpression>
      </sequenceFlow>
      <sequenceFlow id="flow69" name="No Project" sourceRef="XORAProjectOrNot"
         targetRef="XORBProjectOrNot">
         <conditionExpression xsi:type="tFormalExpression">${StudentAppInfo.project  == false}</conditionExpression>
      </sequenceFlow>
I want to get the project value from:


<startEvent id="start">
         <extensionElements>
            <activiti:formProperty id="studentName" name="Studenten Name"
               required="true" type="string" />
            <activiti:formProperty id="emailAddress" name="Email address"
               required="true" type="string" />
            <activiti:formProperty id="dateFrom" name="Date from"
               required="true" type="long" />
            <activiti:formProperty id="dateToo" name="Date too"
               required="true" type="long" />
            <activiti:formProperty id="homeCountry" name="Home Country"
               required="true" type="string" />
            <activiti:formProperty id="homeUniversity"
               name="Home University" required="true" type="string" />
            <activiti:formProperty id="homeDepartment"
               name="Home Department" required="true" type="string" />
            <activiti:formProperty id="targetUniversity"
               name="Target University" required="true" type="string" />
            <activiti:formProperty id="targetDepartment"
               name="Target Department" required="true" type="string" />
            <activiti:formProperty id="research" name="Research"
               required="true" type="string" />
            <activiti:formProperty id="courseEnrollment"
               name="Course Enrollment" required="true" type="string" />
            <activiti:formProperty id="project" name="With project"
               required="true" type="boolean" />
         </extensionElements>
      </startEvent>
      <sequenceFlow id="flow114" sourceRef="start" targetRef="createRequest"></sequenceFlow>
      <serviceTask id="createRequest" name="Create Request"
         activiti:class="org.process1.CreateStudentApp"></serviceTask>


public class StudentAppInfo implements Serializable {

   private static final long serialVersionUID = 1L;

   private String studentName;
   private String emailAddress;
   
   private long dateFrom;
   private long dateToo;
   private long month;
   
   private String homeCountry;
   private String homeUniversity;
   private String homeDepartment;
   private String targetUniversity;
   private String targetDepartment;
   
   private String research;
   private String courseEnrollment;
   private Boolean project;

   public Boolean getProject() {
      return project;
   }
}

My idea is at first to enter everything
@Deployment(resources = { "Part1Application.bpmn20.xml" })
   public void startFormSubmit() {
      ProcessDefinition definition = activitiRule.getRepositoryService()
            .createProcessDefinitionQuery()
            .processDefinitionKey("part1Application").singleResult();
      assertNotNull(definition);

      // call the FormService interface
      FormService formService = activitiRule.getFormService();
      List<FormProperty> formList = formService.getStartFormData(
            definition.getId()).getFormProperties();
      assertEquals(12, formList.size());

      Map<String, String> formProperties = new HashMap<String, String>();
      formProperties.put("studentName", "Toni Muller");
      formProperties.put("emailAddress", "toni@localhost");
      formProperties.put("dateFrom", "1234");
      formProperties.put("dateToo", "2345");
      formProperties.put("homeCountry", "usa");
      formProperties.put("homeUniversity", "univbersityy");
      formProperties.put("homeDepartment", "Computer Science");
      formProperties.put("targetUniversity", "Universityaaa");
      formProperties.put("targetDepartment", "Communication Engineering");
      formProperties.put("research", "Enrollment Process");
      formProperties.put("courseEnrollment", "UML");
      formProperties.put("project", "true");

      // submit form properties
      formService.submitStartFormData(definition.getId(), formProperties);
      // view history query for form properties
      List<HistoricDetail> historyVariables = activitiRule
            .getHistoryService().createHistoricDetailQuery()
            .formProperties().list();

and then try to input the project value:
(it can't find "runtimeService." and "taskService." "Cannot be resolved" What can I do to fix it?)


import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.test.Deployment;
import org.junit.Rule;
import org.junit.Test;

Map<String, Object> variables = new HashMap<String, Object>();

    // Test with input == true
    variables.put("input", true);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("XORAProjectOrNot", variables);
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("send informations from the professors", task.getName());

    // Test with input == false
    variables.put("input", false);
    pi = runtimeService.startProcessInstanceByKey("XORAProjectOrNot", variables);
    task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("XOR B Project Or Not", task.getName());

My problem is that I don't know how to write it in the right way. Hope you can help me!
4 REPLIES 4

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
You need to put a variable with name studentAppInfo of type StudentAppInfo in the variables map…

tomi87
Champ in-the-making
Champ in-the-making
I understand it in this way:


@Rule
public ActivitiRule activitiRule = new ActivitiRule("activiti.cfg-mem.xml");

@Test
// deploys process with form properties
@Deployment(resources = { "Part1Application.bpmn20.xml" })
public void testProjectDecision() {
  StudentAppInfo studentAppInfo=new StudentAppInfo();
  Map<String, Object> variables = new HashMap<String, Object>();
 
  // Test with input == true
  studentAppInfo.setProject(true);
  variables.put("input", studentAppInfo.getProject());
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("XORAProjectOrNot", variables);
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  assertEquals("send informations from the professors", task.getName());

  // Test with input == false
  studentAppInfo.setProject(false);
  variables.put("input", studentAppInfo.getProject());
  pi = runtimeService.startProcessInstanceByKey("XORAProjectOrNot", variables);
  task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  assertEquals("XOR B Project Or Not", task.getName());
}
Is this was you mean ?

And is it useful to enter the other values for this test ?



And the "runtimeService" and the "taskService" still doesnt work. How can I solve this ?

ProcessInstance pi = runtimeService.startProcessInstanceByKey("XORAProjectOrNot", variables);
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();

pi = runtimeService.startProcessInstanceByKey("XORAProjectOrNot", variables);
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();

trademak
Star Contributor
Star Contributor
Hi,

You should use activitiRule.getRuntimeService() , like described here:

http://www.activiti.org/userguide/index.html#apiUnitTesting

Best regards,

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Is this was you mean ?
No

variables.put("input", studentAppInfo.getProject());here you set a variable named input, not a variable named 'StudentAppInfo', while here
<conditionExpression xsi:type="tFormalExpression">${StudentAppInfo.project == true}</conditionExpression>and here
<conditionExpression xsi:type="tFormalExpression">${StudentAppInfo.project == false}</conditionExpression>You reference the StudentAppInfo variable or object

Just do
variables.put("StudentAppInfo", studentAppInfo);
This 'error' you made has nothing to do with exclusive gateways or whatever, but more with a wrong use of EL and variables…