Skip to content

Commit

Permalink
Add tests for completing a task
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Jan 14, 2019
1 parent f2b8819 commit b47126b
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 3 deletions.
22 changes: 22 additions & 0 deletions distro/src/readme.html
Expand Up @@ -27,6 +27,28 @@ <h1>Links</h1>

<h1>Flowable Release Notes</h1>

<h3>Release Notes - Flowable - 6.4.1</h3>

<h4>Highlights</h4>

<ul>
<li>A runtime activity instance table has been added to allow you to query for the activity instances that have been executed for a running process instance without needing
to go to the history tables. This includes active and completed activity instances. When a process instance is completed or terminated, the runtime activity instance will be deleted and only available in the historic activity instance table.</li>
<li>The sequence flows that are taken are now also stored as part of the runtime and historic activity instance data. This provides a more complete audit history of the process instance execution.</li>
<li>A new table has been added to keep track of all changes that happen with a user task. A HistoricTaskLogEntry is created when the assignee of a task changes, or the owner, or for example the due date.
By default the user task logging is disabled, with the enableHistoricTaskLogging property in the process engine configuration, the user task logging can be enabled.</li>
<li>Several improvements have fixes have been done to the CMMN Engine.</li>
<li>A new runtime and historic entity link table has been added to store the relationship between parent entities and all children. This means for example that when a parent process instance has a sub process, and the sub process has a user task, that for the user task
two entity links are created, one between the parent process instance and the user task, and another with the sub process instance and the user task. The same is true when a case instance starts a process instance via the CMMN Process Task for example. This makes it possible
to get all child tasks for a parent process instance for example. By default, storing entity links is not enabled in the Flowable Engines, but using the enableEntityLinks property in the process engine configuration and/or cmmn engine configuration this can be enabled.</li>
<li>A first version of case instance change state has been added to the Flowable CMMN Engine. In the CmmnRuntimeService you can now use the createChangePlanItemStateBuilder to define and execute the case instance change state logic.
This first version supports changing state focused on human tasks. In the next version more support will be added for more complex cases.</li>
<li>REST services have been added to make it easier to fetch a form definition associated with a user task or a start event. Also, completing a form for a user task or starting a process instance with a form is now a lot easier via REST.
Getting a BPMN user task form can be done via GET process-api/runtime/tasks/{taskId}/form for example, and completing a user task can be done via POST process-api/runtime/tasks/{taskId} as it was possible already before. But now the payload can contain a form definition id
and outcome value to complete the user task with a form.</li>
<li>Various small bugfixes and improvements all around.</li>
</ul>

<h3>Release Notes - Flowable - 6.4.0</h3>

<h4>Highlights</h4>
Expand Down
5 changes: 5 additions & 0 deletions modules/flowable-engine-configurator/pom.xml
Expand Up @@ -53,6 +53,11 @@
<artifactId>flowable-cmmn-engine-configurator</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-engine-configurator</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
@@ -0,0 +1,138 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.engine.configurator.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

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

import org.flowable.app.api.repository.AppDeployment;
import org.flowable.app.engine.test.FlowableAppTestCase;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.impl.interceptor.EngineConfigurationConstants;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.form.api.FormDefinition;
import org.flowable.form.engine.FormEngineConfiguration;
import org.flowable.identitylink.api.IdentityLinkType;
import org.flowable.task.api.Task;
import org.junit.Test;

/**
* @author Tijs Rademakers
*/
public class ProcessTest extends FlowableAppTestCase {

@Test
public void testCompleteTask() throws Exception {
ProcessEngineConfiguration processEngineConfiguration = (ProcessEngineConfiguration) appEngineConfiguration.getEngineConfigurations()
.get(EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
TaskService taskService = processEngineConfiguration.getTaskService();

AppDeployment deployment = appRepositoryService.createDeployment()
.addClasspathResource("org/flowable/engine/configurator/test/oneTaskProcess.bpmn20.xml").deploy();

try {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTask");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);

runtimeService.addUserIdentityLink(processInstance.getId(), "anotherUser", IdentityLinkType.STARTER);
taskService.addUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);

assertEquals(2, runtimeService.getIdentityLinksForProcessInstance(processInstance.getId()).size());
assertEquals(1, taskService.getIdentityLinksForTask(task.getId()).size());

taskService.complete(task.getId());

try {
assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstance.getId()).size());
fail("object not found expected");
} catch (FlowableObjectNotFoundException e) {
// expected
}

try {
assertEquals(0, taskService.getIdentityLinksForTask(task.getId()).size());
fail("object not found expected");
} catch (FlowableObjectNotFoundException e) {
// expected
}

assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());


} finally {
appRepositoryService.deleteDeployment(deployment.getId(), true);
}
}

@Test
public void testCompleteTaskWithForm() throws Exception {
ProcessEngineConfiguration processEngineConfiguration = (ProcessEngineConfiguration) appEngineConfiguration.getEngineConfigurations()
.get(EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
TaskService taskService = processEngineConfiguration.getTaskService();

AppDeployment deployment = appRepositoryService.createDeployment()
.addClasspathResource("org/flowable/engine/configurator/test/oneTaskWithFormProcess.bpmn20.xml")
.addClasspathResource("org/flowable/engine/configurator/test/simple.form").deploy();

try {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTask");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);

runtimeService.addUserIdentityLink(processInstance.getId(), "anotherUser", IdentityLinkType.STARTER);
taskService.addUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT);

assertEquals(2, runtimeService.getIdentityLinksForProcessInstance(processInstance.getId()).size());
assertEquals(1, taskService.getIdentityLinksForTask(task.getId()).size());

FormEngineConfiguration formEngineConfiguration = (FormEngineConfiguration) appEngineConfiguration.getEngineConfigurations()
.get(EngineConfigurationConstants.KEY_FORM_ENGINE_CONFIG);
FormDefinition formDefinition = formEngineConfiguration.getFormRepositoryService().createFormDefinitionQuery().formDefinitionKey("form1").singleResult();
assertNotNull(formDefinition);

Map<String, Object> variables = new HashMap<String, Object>();
variables.put("input1", "test");
taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), null, variables);

try {
assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstance.getId()).size());
fail("object not found expected");
} catch (FlowableObjectNotFoundException e) {
// expected
}

try {
assertEquals(0, taskService.getIdentityLinksForTask(task.getId()).size());
fail("object not found expected");
} catch (FlowableObjectNotFoundException e) {
// expected
}

assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());


} finally {
appRepositoryService.deleteDeployment(deployment.getId(), true);
}
}
}
Expand Up @@ -15,6 +15,7 @@
<list>
<bean class="org.flowable.engine.configurator.ProcessEngineConfigurator" />
<bean class="org.flowable.cmmn.engine.configurator.CmmnEngineConfigurator" />
<bean class="org.flowable.form.engine.configurator.FormEngineConfigurator" />
</list>
</property>
</bean>
Expand Down
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:flowable="http://flowable.org/bpmn"
targetNamespace="http://flowable.org/bpmn">
<process id="oneTask">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" />
<userTask id="theTask" name="my task" flowable:formKey="form1" />
<sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
</definitions>
@@ -0,0 +1,13 @@
{
"key": "form1",
"name": "My first form",
"fields": [
{
"id": "input1",
"name": "Input1",
"type": "text",
"required": false,
"placeholder": "empty"
}
]
}
Expand Up @@ -41,7 +41,7 @@ public List<IdentityLink> execute(CommandContext commandContext) {
ExecutionEntity processInstance = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);

if (processInstance == null) {
throw new FlowableObjectNotFoundException("Cannot find process definition with id " + processInstanceId, ExecutionEntity.class);
throw new FlowableObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
}

return (List) processInstance.getIdentityLinks();
Expand Down
Expand Up @@ -15,6 +15,7 @@
import java.io.Serializable;
import java.util.List;

import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.util.CommandContextUtil;
Expand All @@ -40,6 +41,10 @@ public GetIdentityLinksForTaskCmd(String taskId) {
@Override
public List<IdentityLink> execute(CommandContext commandContext) {
TaskEntity task = CommandContextUtil.getTaskService().getTask(taskId);

if (task == null) {
throw new FlowableObjectNotFoundException("task not found");
}

List<IdentityLink> identityLinks = (List) task.getIdentityLinks();

Expand Down
Expand Up @@ -98,8 +98,7 @@ public TaskResponse updateTask(@ApiParam(name = "taskId") @PathVariable String t
return restResponseFactory.createTaskResponse(task);
}

@ApiOperation(value = "Tasks actions", tags = { "Tasks" },
notes = "")
@ApiOperation(value = "Tasks actions", tags = { "Tasks" }, notes = "")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Indicates the action was executed."),
@ApiResponse(code = 400, message = "When the body contains an invalid value or when the assignee is missing when the action requires it."),
Expand Down

0 comments on commit b47126b

Please sign in to comment.