Time for action – unit testing to see the result

Now we will test the business process that we created. For this, we will have to perform the following steps:

  1. Right-click on the SimpleLeaveProcess.bpmn file and browse to Activiti | Generate unit test, as shown in the following screenshot:
    Time for action – unit testing to see the result
  2. On performing the previous step, a test class file is created in src/test/java package, as shown in the following screenshot:
    Time for action – unit testing to see the result
  3. In the ProcessTestMyProcess.java file, replace the code with the following:
    @Test
      public void startProcess() throws Exception {
        RepositoryService repositoryService = activitiRule.getRepositoryService();
        repositoryService.createDeployment().addInputStream("SimpleLeaveProcess.bpmn20.xml",
          new FileInputStream(filename)).deploy();
        RuntimeService runtimeService = activitiRule.getRuntimeService();
        Map<String, Object> variableMap = new HashMap<String, Object>();
        variableMap.put("Empname", "Irshad");
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leaveProcess", variableMap);
        assertNotNull(processInstance.getId());
        System.out.println("id " + processInstance.getId() + " "
          + processInstance.getProcessDefinitionId());
      }
  4. To view the test result, you can right-click on the ProcessTestMyProcess class file and browse to Run As | JUnit Test, as shown in the following screenshot:
    Time for action – unit testing to see the result
  5. The output after executing the test case is shown in the following screenshot:
    Time for action – unit testing to see the result

What just happened?

We have created a test file to test a business process in Activiti.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset