ServiceTaskValidator extends ExternalInvocationTaskValidator { @Override protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) { List<ServiceTask> serviceTasks = process.findFlowElementsOfType(ServiceTask.class); for (ServiceTask serviceTask : serviceTasks) { verifyImplementation(process, serviceTask, errors); verifyType(process, serviceTask, errors); verifyResultVariableName(process, serviceTask, errors); verifyWebservice(bpmnModel, process, serviceTask, errors); } }    }
@Test public void executeValidationShouldRiseErrorsForEmptyServiceTask() { Process process = new Process(); process.addFlowElement(new ServiceTask()); BpmnModel bpmnModel = new BpmnModel(); ArrayList<ValidationError> errors = new ArrayList<>(); validator.executeValidation(bpmnModel, process, errors); assertThat(errors).hasSize(1); assertThat(errors.get(0).getProblem()).isEqualTo("activiti-servicetask-missing-implementation"); assertThat(errors.get(0).getDefaultDescription()) .isEqualTo( "One of the attributes 'implementation', 'class', 'delegateExpression', 'type', 'operation', or 'expression' is mandatory on serviceTask." ); }
@Test public void executeValidationShouldNotRiseErrorsForServiceTasksSettingOnlyTheImplementation() { Process process = new Process(); ServiceTask serviceTask = new ServiceTask(); serviceTask.setImplementation("myImpl"); process.addFlowElement(serviceTask); BpmnModel bpmnModel = new BpmnModel(); ArrayList<ValidationError> errors = new ArrayList<>(); validator.executeValidation(bpmnModel, process, errors); assertThat(errors) .as("No error is expected: the default behavior will be used") .isEmpty(); }