Back to Repositories

Testing Human Task Mapping Implementation in Conductor-OSS

This test suite validates the functionality of the HumanTaskMapper component in Conductor OSS, focusing on the mapping of human tasks within workflow definitions. It ensures proper task type assignment and context handling for human-based workflow activities.

Test Coverage Overview

The test coverage focuses on the core functionality of mapping human tasks in Conductor workflows.

Key areas tested include:
  • Task type verification for human tasks
  • Workflow task mapping validation
  • Task ID generation and assignment
  • TaskMapperContext integration

Implementation Analysis

The testing approach utilizes JUnit for unit testing with Mockito for dependency mocking. The test implements a clear Given-When-Then pattern to validate the HumanTaskMapper’s getMappedTasks functionality.

Technical implementation includes:
  • Mock ParametersUtils for isolation
  • WorkflowModel and WorkflowDef setup
  • TaskMapperContext builder pattern usage

Technical Details

Testing tools and configuration:
  • JUnit 4 testing framework
  • Mockito mocking framework
  • IDGenerator for task identification
  • TaskMapperContext builder
  • WorkflowTask and TaskModel objects

Best Practices Demonstrated

The test exhibits several testing best practices for workflow component validation.

Notable practices include:
  • Clear test method naming
  • Proper test setup isolation
  • Explicit assertion validation
  • Clean separation of concerns
  • Effective use of mocking

conductor-oss/conductor

core/src/test/java/com/netflix/conductor/core/execution/mapper/HumanTaskMapperTest.java

            
/*
 * Copyright 2022 Conductor Authors.
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 com.netflix.conductor.core.execution.mapper;

import java.util.HashMap;
import java.util.List;

import org.junit.Test;

import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.tasks.TaskType;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;
import com.netflix.conductor.core.utils.IDGenerator;
import com.netflix.conductor.core.utils.ParametersUtils;
import com.netflix.conductor.model.TaskModel;
import com.netflix.conductor.model.WorkflowModel;

import static com.netflix.conductor.common.metadata.tasks.TaskType.TASK_TYPE_HUMAN;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

public class HumanTaskMapperTest {

    @Test
    public void getMappedTasks() {

        // Given
        WorkflowTask workflowTask = new WorkflowTask();
        workflowTask.setName("human_task");
        workflowTask.setType(TaskType.HUMAN.name());
        String taskId = new IDGenerator().generate();

        ParametersUtils parametersUtils = mock(ParametersUtils.class);
        WorkflowModel workflow = new WorkflowModel();
        WorkflowDef workflowDef = new WorkflowDef();
        workflow.setWorkflowDefinition(workflowDef);

        TaskMapperContext taskMapperContext =
                TaskMapperContext.newBuilder()
                        .withWorkflowModel(workflow)
                        .withTaskDefinition(new TaskDef())
                        .withWorkflowTask(workflowTask)
                        .withTaskInput(new HashMap<>())
                        .withRetryCount(0)
                        .withTaskId(taskId)
                        .build();

        HumanTaskMapper humanTaskMapper = new HumanTaskMapper(parametersUtils);
        // When
        List<TaskModel> mappedTasks = humanTaskMapper.getMappedTasks(taskMapperContext);

        // Then
        assertEquals(1, mappedTasks.size());
        assertEquals(TASK_TYPE_HUMAN, mappedTasks.get(0).getTaskType());
    }
}