Back to Repositories

Testing NoopTaskMapper Implementation in Conductor OSS

This test suite validates the NoopTaskMapper functionality in Conductor’s task mapping system, focusing on the correct mapping of NOOP task types within workflow definitions. The tests ensure proper task model generation and attribute mapping for no-operation tasks.

Test Coverage Overview

The test coverage focuses on the core functionality of NoopTaskMapper, specifically verifying the getMappedTasks method.

Key areas covered include:
  • Task type verification for NOOP tasks
  • Task model generation and attributes
  • Integration with TaskMapperContext
  • Workflow task mapping validation

Implementation Analysis

The testing approach utilizes JUnit framework with a focus on behavioral verification. The implementation follows a builder pattern for TaskMapperContext creation and employs systematic task model validation.

Key patterns include:
  • Builder pattern for test context setup
  • Direct assertion validation
  • Workflow model initialization
  • Task definition configuration

Technical Details

Testing infrastructure includes:
  • JUnit 4 test framework
  • Custom IDGenerator for task identification
  • TaskMapperContext builder utility
  • WorkflowModel and TaskModel implementations
  • TaskDef and WorkflowDef configuration objects

Best Practices Demonstrated

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

Notable practices include:
  • Clear test method naming
  • Proper test setup and initialization
  • Focused test scope
  • Explicit assertions
  • Clean code organization
  • Effective use of builder pattern for test context

conductor-oss/conductor

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

            
/*
 * Copyright 2023 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 NoopTaskMapperTest {

    @Test
    public void getMappedTasks() {

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

        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 NoopTaskMapper().getMappedTasks(taskMapperContext);

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