@@ -339,6 +339,93 @@ public void testChangeNameAndDescription() {
339339 assertProcessEnded (processInstance .getId ());
340340 }
341341
342+ @ Test
343+ @ Deployment (resources = { "org/flowable/engine/test/bpmn/usertask/DynamicUserTaskTest.namedtask.bpmn20.xml" })
344+ public void testChangeNameAndDescriptionWithExistingName () {
345+ // Without an override, the static name from the model is used
346+ ProcessInstance processInstance = runtimeService .startProcessInstanceByKey ("dynamicUserTask" );
347+ String processDefinitionId = processInstance .getProcessDefinitionId ();
348+
349+ org .flowable .task .api .Task task = taskService .createTaskQuery ().processInstanceId (processInstance .getId ()).singleResult ();
350+ assertThat (task .getName ()).isEqualTo ("Task 1" );
351+ assertThat (task .getDescription ()).isNull ();
352+ taskService .complete (task .getId ());
353+
354+ assertProcessEnded (processInstance .getId ());
355+
356+ // A dynamic override must take precedence over the static task name and description
357+ ObjectNode infoNode = dynamicBpmnService .changeUserTaskName ("task1" , "Task name test" );
358+ dynamicBpmnService .changeUserTaskDescription ("task1" , "Task description test" , infoNode );
359+ dynamicBpmnService .saveProcessDefinitionInfo (processDefinitionId , infoNode );
360+
361+ processInstance = runtimeService .startProcessInstanceByKey ("dynamicUserTask" );
362+
363+ task = taskService .createTaskQuery ().processInstanceId (processInstance .getId ()).singleResult ();
364+ assertThat (task .getName ()).isEqualTo ("Task name test" );
365+ assertThat (task .getDescription ()).isEqualTo ("Task description test" );
366+ taskService .complete (task .getId ());
367+
368+ assertProcessEnded (processInstance .getId ());
369+ }
370+
371+ @ Test
372+ @ Deployment (resources = { "org/flowable/engine/test/bpmn/usertask/DynamicUserTaskTest.namedtask.bpmn20.xml" })
373+ public void testChangeDescriptionOnlyKeepsExistingName () {
374+ // Without an override, the static name from the model is used
375+ ProcessInstance processInstance = runtimeService .startProcessInstanceByKey ("dynamicUserTask" );
376+ String processDefinitionId = processInstance .getProcessDefinitionId ();
377+
378+ org .flowable .task .api .Task task = taskService .createTaskQuery ().processInstanceId (processInstance .getId ()).singleResult ();
379+ assertThat (task .getName ()).isEqualTo ("Task 1" );
380+ assertThat (task .getDescription ()).isNull ();
381+ taskService .complete (task .getId ());
382+
383+ assertProcessEnded (processInstance .getId ());
384+
385+ // Overriding only the description must keep the static task name intact
386+ ObjectNode infoNode = dynamicBpmnService .changeUserTaskDescription ("task1" , "Task description test" );
387+ dynamicBpmnService .saveProcessDefinitionInfo (processDefinitionId , infoNode );
388+
389+ processInstance = runtimeService .startProcessInstanceByKey ("dynamicUserTask" );
390+
391+ task = taskService .createTaskQuery ().processInstanceId (processInstance .getId ()).singleResult ();
392+ assertThat (task .getName ()).isEqualTo ("Task 1" );
393+ assertThat (task .getDescription ()).isEqualTo ("Task description test" );
394+ taskService .complete (task .getId ());
395+
396+ assertProcessEnded (processInstance .getId ());
397+ }
398+
399+ @ Test
400+ @ Deployment (resources = { "org/flowable/engine/test/bpmn/usertask/DynamicUserTaskTest.expressionname.bpmn20.xml" })
401+ public void testChangeNameWithNameExpression () {
402+ // Without an override, the name expression is resolved against the process variables
403+ Map <String , Object > variables = new HashMap <>();
404+ variables .put ("taskName" , "Resolved task name" );
405+ ProcessInstance processInstance = runtimeService .startProcessInstanceByKey ("dynamicUserTask" , variables );
406+ String processDefinitionId = processInstance .getProcessDefinitionId ();
407+
408+ org .flowable .task .api .Task task = taskService .createTaskQuery ().processInstanceId (processInstance .getId ()).singleResult ();
409+ assertThat (task .getName ()).isEqualTo ("Resolved task name" );
410+ taskService .complete (task .getId ());
411+
412+ assertProcessEnded (processInstance .getId ());
413+
414+ // A dynamic override must take precedence over the resolved name expression
415+ ObjectNode infoNode = dynamicBpmnService .changeUserTaskName ("task1" , "Overridden name" );
416+ dynamicBpmnService .saveProcessDefinitionInfo (processDefinitionId , infoNode );
417+
418+ variables = new HashMap <>();
419+ variables .put ("taskName" , "Resolved task name" );
420+ processInstance = runtimeService .startProcessInstanceByKey ("dynamicUserTask" , variables );
421+
422+ task = taskService .createTaskQuery ().processInstanceId (processInstance .getId ()).singleResult ();
423+ assertThat (task .getName ()).isEqualTo ("Overridden name" );
424+ taskService .complete (task .getId ());
425+
426+ assertProcessEnded (processInstance .getId ());
427+ }
428+
342429 @ Test
343430 @ Deployment (resources = { "org/flowable/engine/test/bpmn/usertask/DynamicUserTaskTest.assignment.bpmn20.xml" })
344431 public void testChangePriorityAndCategory () {
0 commit comments