Commit c85014c5 authored by cijujoseph's avatar cijujoseph

Updated with some comments

parent 0014669b
......@@ -24,15 +24,31 @@ import static org.mockito.Mockito.*;
@ContextConfiguration(locations = { "classpath:activiti.cfg.xml", "classpath:common-beans-and-mocks.xml" })
public class DMNProcessUnitTest extends AbstractBpmnTest {
/*
* Setting the App name to be downloaded if run with -Daps.app.download=true
* Also set the process definition key of the process that is being tested
*/
static {
appName = "Test App";
processDefinitionKey = "DMNProcess";
}
/*
* Test testing a success path of Start->Rules->Gateway->End
*/
@Test
public void testRuleExecutionSuccessPath() throws Exception {
/*
* Reset mocks that we will be asserting later in the test
*/
Mockito.reset(activiti_executeDecisionDelegate);
/*
* A listener for mock to do those things that the DMN step would
* normally do in this test. eg: In this test to take a success path, we
* want the DMN step to set a variable "output" with value "abc"
*/
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
......@@ -48,21 +64,49 @@ public class DMNProcessUnitTest extends AbstractBpmnTest {
}
}).when(activiti_executeDecisionDelegate).execute((DelegateExecution) any());
/*
* Starting the process using processDefinitionKey
*/
ProcessInstance processInstance = activitiRule.getRuntimeService()
.startProcessInstanceByKey(processDefinitionKey);
/*
* Once started assert that the process instance is not null and
* successfully started
*/
assertNotNull(processInstance);
/*
* Since the next step is a DMN Rule execution, assert that the
* corresponding APS Java Delegate responsible for running the rule is
* invoked only once
*/
verify(activiti_executeDecisionDelegate, times(1)).execute((DelegateExecution) any());
/*
* Using the custom assertion ProcessInstanceAssert, make sure that the
* process is now ended. Expected as per the success path.
*/
ProcessInstanceAssert.assertThat(processInstance).isComplete();
}
/*
* Test testing a fail path of Start->Rules->Gateway->User Task->End
*/
@Test
public void testRuleExecutionFailPath() throws Exception {
/*
* Reset mocks that we will be asserting later in the test
*/
Mockito.reset(activiti_executeDecisionDelegate);
/*
* A listener for mock to do those things that the DMN step would
* normally do in this test. eg: In this test to take a reject path, we
* want the DMN step to not set any variables to mock "none of the rules are
* evaluated"
*/
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
......@@ -77,20 +121,48 @@ public class DMNProcessUnitTest extends AbstractBpmnTest {
}
}).when(activiti_executeDecisionDelegate).execute((DelegateExecution) any());
/*
* Starting the process using processDefinitionKey
*/
ProcessInstance processInstance = activitiRule.getRuntimeService()
.startProcessInstanceByKey(processDefinitionKey);
/*
* Once started assert that the process instance is not null and
* successfully started
*/
assertNotNull(processInstance);
/*
* Since the next step is a DMN Rule execution, assert that the
* corresponding APS Java Delegate responsible for running the rule is
* invoked only once
*/
verify(activiti_executeDecisionDelegate, times(1)).execute((DelegateExecution) any());
/*
* Since the next step in the reject path is a user task, doing a query
* to find the user task count in the engine. Assert that it is only 1
*/
assertEquals(1, taskService.createTaskQuery().count());
/*
* Get the Task object for further task assertions
*/
Task rejectTask = taskService.createTaskQuery().singleResult();
TaskAssert.assertThat(rejectTask).hasAssignee("$INITIATOR", false, false)
.hasName("Rule Not Evaluated").complete();
/*
* Asserting the task for things such as assignee, task name etc. Also,
* at the end of it complete the task Using the custom assertion
* TaskAssert from the utils project here
*/
TaskAssert.assertThat(rejectTask).hasAssignee("$INITIATOR", false, false).hasName("Rule Not Evaluated")
.complete();
/*
* Using the custom assertion ProcessInstanceAssert, make sure that the
* process is now ended after the user task is completed.
*/
ProcessInstanceAssert.assertThat(processInstance).isComplete();
}
......
......@@ -21,6 +21,10 @@ import static org.junit.Assert.*;
@ContextConfiguration(locations = { "classpath:activiti.cfg.xml", "classpath:common-beans-and-mocks.xml" })
public class UserTaskUnitTest extends AbstractBpmnTest {
/*
* Setting the App name to be downloaded if run with -Daps.app.download=true
* Also set the process definition key of the process that is being tested
*/
static {
appName = "Test App";
processDefinitionKey = "UserTaskProcess";
......@@ -28,19 +32,47 @@ public class UserTaskUnitTest extends AbstractBpmnTest {
@Test
public void testProcessExecution() throws Exception {
/*
* Creating a map and setting a variable called "initiator" when
* starting the process.
*/
Map<String, Object> processVars = new HashMap<String, Object>();
processVars.put("initiator", "$INITIATOR");
/*
* Starting the process using processDefinitionKey and process variables
*/
ProcessInstance processInstance = activitiRule.getRuntimeService()
.startProcessInstanceByKey(processDefinitionKey, processVars);
/*
* Once started assert that the process instance is not null and
* successfully started
*/
assertNotNull(processInstance);
/*
* Since the next step after start is a user task, doing a query to find
* the user task count in the engine. Assert that it is only 1
*/
assertEquals(1, taskService.createTaskQuery().count());
/*
* Get the Task object for further task assertions
*/
Task task = taskService.createTaskQuery().singleResult();
TaskAssert.assertThat(task).hasAssignee("$INITIATOR", false, false).hasDueDate(2, TIME_UNIT_DAY)
.complete();
/*
* Asserting the task for things such as assignee, due date etc. Also,
* at the end of it complete the task Using the custom assertion
* TaskAssert from the utils project here
*/
TaskAssert.assertThat(task).hasAssignee("$INITIATOR", false, false).hasDueDate(2, TIME_UNIT_DAY).complete();
/*
* Using the custom assertion ProcessInstanceAssert, make sure that the
* process is now ended.
*/
ProcessInstanceAssert.assertThat(processInstance).isComplete();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment