cancel
Showing results for 
Search instead for 
Did you mean: 

jump to a Task in a test

tomi87
Champ in-the-making
Champ in-the-making
I want to write a test for a task in the middle of a bpmn20.xml file.
At first I want to enter some values in the beginning of the  bpmn20.xml file and then jump to my task wich I want to test.
How should I start with the test, that I can direct jump to my task?
And is it possible ?

For example:
my  bpmn20.xml file:
<process id="myFILE">
      <startEvent id="start">
         <extensionElements>
            <activiti:formProperty id="stname" name="St. name"
               required="true" type="string" />
         </extensionElements>
      </startEvent>
      <sequenceFlow id="flow114" sourceRef="start" targetRef="createRequest"></sequenceFlow>
      <serviceTask id="createRequest" name="Create Request"
         activiti:class="org.process1.CreateStApp"></serviceTask>


other Tasks which I want to skip (inclusive some other exclusive gateways)

Here I want to start my Test:

   <userTask id="decideToBeABC" name="decide to be ABC"
      activiti:candidateGroups="Adv">
      <extensionElements>
         <activiti:formProperty id="stname" name="St. name"
            expression="${stAppInfo.stname}" writable="false" />
         <activiti:formProperty id="requestAccepted"
            name="Do you accepted this request?" required="true" type="enum">
            <activiti:value id="true" name="Yes" />
            <activiti:value id="false" name="No" />
         </activiti:formProperty>
      </extensionElements>
   </userTask>
      <sequenceFlow id="flow115"  sourceRef="decideToBeABC" targetRef="XORAAdOrNot"></sequenceFlow>
<!– XOR requestAccepted or not –>
      <exclusiveGateway id="XORAAdOrNot"  />
      <sequenceFlow id="flow63" name="Adv" sourceRef="XORAAdOrNot"
         targetRef="sendInf">
         <conditionExpression xsi:type="tFormalExpression">${requestAccepted== true}
         </conditionExpression>
      </sequenceFlow>
      <sequenceFlow id="flow69" name="No Adv" sourceRef="XORAAdOrNot"
         targetRef="furtherrr">
         <conditionExpression xsi:type="tFormalExpression">${requestAccepted== false}
         </conditionExpression>
      </sequenceFlow>
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
I'm afraid that's not possible, activiti forces you to follow the process-flow as it is defined. You should separate the logic to reach the certain step, in a separate method in your test. In other tests, you can use this method to move the execution until the point you want, and test from there (eg. startProcessAndCompleteToStepX()). This way, you're test will contain only a single line of "stuff" you don't want to test…

tomi87
Champ in-the-making
Champ in-the-making
OK I get it!
But now everytime when I start JUNIT it says true. I can copy my Testclass to some other folders or delete the xml file, Junit says everything true and no errors.

I don't think there is something wrong in the beginning from my code.
But I don't know whats happen.

public class TenMinuteAND {
@Rule
@Test
@Deployment(resources={"FinancialReportProcess.bpmn20.xml"})
public void startFormSubmit() {
  
     ProcessEngine processEngine = ProcessEngineConfiguration
       .createStandaloneProcessEngineConfiguration()
       .buildProcessEngine();

     RuntimeService runtimeService = processEngine.getRuntimeService();
    
     ProcessInstance pi = runtimeService.startProcessInstanceByKey("financialReport");
    
     TaskService taskService = processEngine.getTaskService();
     Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    

frederikherema1
Star Contributor
Star Contributor
WHy is the @Rule-annotation above your method? have you tries debugging the unit-test and see if the test-method actually runs (after removing the @rule)