How to test business logic

Testing the business logic of an enterprise application is mostly a little be tricky. In different to simple UI tests which can be performed with typical test-frameworks like HtmlUnit or Selenium, testing the business logic from the view of multiple test users can get very complicated very quickly. For example, if you test several steps in a comprehensive workflow for different users, you need to test if these users are allowed to perform specific tasks in the workflow. In such a scenario you need a group of test users to verify the different situations of access levels and you need to login and logout these users several times during your test case.

With the new release of Imixs Workflow the open source project provides now a powerful test framework which can be easily used in a JUnit Test. The Framework makes use of the Imixs REST API and simplifies the way to test complex workflow scenarios. To build your test case can setup a new WorkflowTestSuite and register a list of users which will be affected from the test case:

@Before
 public void setup() {
 testSuite = WorkflowTestSuite.getInstance();
 testSuite.setHost("http://localhost:8080/minutes-rest/");
 testSuite.joinParty("admin", "password");
 testSuite.joinParty("anna", "password");
 testSuite.joinParty("ronny", "password");
 testSuite.joinParty("eddy", "password");
 testSuite.joinParty("Anonymous", null);
 }

With this setup you can now easily test different scenarios and also create a new process instance or process specific workflow steps.

The following example shows how to test if a user currently has more than one task in his task list:

@Test
 public void worklistTest() throws Exception {
   Assert.assertNotNull(testSuite.getClient("anna"));
   List<ItemCollection> result = testSuite.getWorklist("anna");
   Assert.assertTrue(result.size() > 1);
}

Also the creation and the processing of a single workitem can be performed easily:

@Test
 public void processWorkitemTest() throws Exception {
   ItemCollection workitem=new ItemCollection();
    workitem.replaceItemValue("type", "profile");
    workitem.replaceItemValue("$ModelVersion", "1.0.1"); 
    workitem.replaceItemValue("$processid", 200);
    workitem.replaceItemValue("$activityid", 10);
    workitem.replaceItemValue("txtName","some test");
    workitem=testSuite.processWorkitem(workitem, "anna");
    Assert.assertNotNull(workitem);
    String uid= workitem.getItemValueString("$UniqueID");
    WorkflowTestSuite.log(Level.INFO,"UID=" +uid);
    Assert.assertFalse(uid.isEmpty());
 }

The important aspect of the WorkflowTestSuite is, that each test will be performed through the REST API of the Imxis Workflow Engine. So the test framework guaranties that during a test case the user will be authenticated against the back-end and the specific access level of each users joining the test case can be tested. This simplifies the way to test complex workflows and will improve your enterprise software development.

The Imixs WorkflowTestSuite is part of the upcoming release 3.1.7 of Imxis Workflow. Read more details here.