Back to Repositories

Testing SET_VARIABLE Task Mapping Implementation in conductor-oss/conductor

This test suite validates the SetVariableTaskMapper functionality in Conductor’s core execution module. It ensures proper mapping of SET_VARIABLE task types and verifies the generation of task models with appropriate configurations.

Test Coverage Overview

The test suite provides coverage for the SetVariableTaskMapper component, focusing on task mapping functionality.

Key areas tested include:
  • Task type verification for SET_VARIABLE tasks
  • Task model generation and mapping
  • Integration with workflow context and task definitions
  • Proper task ID handling and generation

Implementation Analysis

The testing approach utilizes JUnit to validate the task mapper’s behavior through isolated unit tests. The implementation follows a builder pattern for creating test contexts and employs assertion-based verification.

Key patterns include:
  • Builder pattern for TaskMapperContext creation
  • Direct mapper instantiation and testing
  • Workflow model construction and configuration

Technical Details

Testing tools and components:
  • JUnit testing framework
  • TaskMapperContext builder
  • IDGenerator for task identification
  • WorkflowModel and TaskModel objects
  • TaskDef and WorkflowTask configurations

Best Practices Demonstrated

The test suite demonstrates several testing best practices in Java unit testing.

Notable practices include:
  • Clear test method naming and organization
  • Proper test setup and initialization
  • Explicit assertions for verification
  • Isolated component testing
  • Comprehensive object construction for test scenarios

conductor-oss/conductor

core/src/test/java/com/netflix/conductor/core/execution/mapper/SetVariableTaskMapperTest.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.List;

import org.junit.Assert;
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;

public class SetVariableTaskMapperTest {

    @Test
    public void getMappedTasks() {

        WorkflowTask workflowTask = new WorkflowTask();
        workflowTask.setType(TaskType.TASK_TYPE_SET_VARIABLE);

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

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

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

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

        Assert.assertNotNull(mappedTasks);
        Assert.assertEquals(1, mappedTasks.size());
        Assert.assertEquals(TaskType.TASK_TYPE_SET_VARIABLE, mappedTasks.get(0).getTaskType());
    }
}