Back to Repositories

Testing JOIN Task Mapping Implementation in Conductor-OSS

This test suite validates the JoinTaskMapper functionality in Conductor’s core execution engine, specifically focusing on the mapping of JOIN task types within workflow definitions. It ensures proper task generation and type assignment for workflow join operations.

Test Coverage Overview

The test suite provides coverage for the JOIN task mapping functionality in Conductor workflows.

Key areas tested include:
  • Workflow task type validation for JOIN operations
  • Task ID generation and assignment
  • Join condition configuration with multiple dependent tasks
  • Proper task model creation and type assignment

Implementation Analysis

The testing approach utilizes JUnit to verify the JOIN task mapping logic through isolated unit tests. The implementation follows a builder pattern for creating test contexts and employs assertion-based verification.

Technical patterns include:
  • Builder pattern for TaskMapperContext creation
  • Workflow model initialization and configuration
  • Task definition setup and validation

Technical Details

Testing tools and configuration:
  • JUnit testing framework
  • IDGenerator for unique task identification
  • WorkflowModel and TaskModel for workflow state representation
  • TaskMapperContext for test context setup
  • Assertion utilities for result validation

Best Practices Demonstrated

The test implementation showcases several testing best practices for workflow component validation.

Notable practices include:
  • Isolated test setup with clear arrangement phase
  • Explicit test data configuration
  • Clear assertion statements for result validation
  • Proper separation of test context setup and execution

conductor-oss/conductor

core/src/test/java/com/netflix/conductor/core/execution/mapper/JoinTaskMapperTest.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.Arrays;
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.model.TaskModel;
import com.netflix.conductor.model.WorkflowModel;

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

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

public class JoinTaskMapperTest {

    @Test
    public void getMappedTasks() {

        WorkflowTask workflowTask = new WorkflowTask();
        workflowTask.setType(TaskType.JOIN.name());
        workflowTask.setJoinOn(Arrays.asList("task1", "task2"));

        String taskId = new IDGenerator().generate();

        WorkflowDef wd = new WorkflowDef();
        WorkflowModel workflow = new WorkflowModel();
        workflow.setWorkflowDefinition(wd);

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

        List<TaskModel> mappedTasks = new JoinTaskMapper().getMappedTasks(taskMapperContext);

        assertNotNull(mappedTasks);
        assertEquals(TASK_TYPE_JOIN, mappedTasks.get(0).getTaskType());
    }
}