<commit_before>/*
 * ProActive Parallel Suite(TM):
 * The Open Source library for parallel and distributed
 * Workflows & Scheduling, Orchestration, Cloud Automation
 * and Big Data Analysis on Enterprise Grids & Clouds.
 *
 * Copyright (c) 2007 - 2017 ActiveEon
 * Contact: <EMAIL>
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation: version 3 of
 * the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * If needed, contact us to obtain a release under GPL Version 2 or 3
 * or a different license than the AGPL.
 */
package org.ow2.proactive.scheduling.api.graphql.fetchers;

import static com.google.common.truth.Truth.assertThat;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

import javax.persistence.EntityManager;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.ow2.proactive.scheduler.common.task.OnTaskError;
import org.ow2.proactive.scheduler.common.task.RestartMode;
import org.ow2.proactive.scheduler.common.task.TaskStatus;
import org.ow2.proactive.scheduler.common.task.flow.FlowBlock;
import org.ow2.proactive.scheduler.core.db.EnvironmentModifierData;
import org.ow2.proactive.scheduler.core.db.JobData;
import org.ow2.proactive.scheduler.core.db.ScriptData;
import org.ow2.proactive.scheduler.core.db.SelectorData;
import org.ow2.proactive.scheduler.core.db.TaskData;
import org.ow2.proactive.scheduler.core.db.TaskDataVariable;
import org.ow2.proactive.scheduling.api.graphql.schema.type.Task;

import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;


/**
 * @author ActiveEon Team
 */
@RunWith(MockitoJUnitRunner.class)
public class TaskDataFetcherTest {

    @Mock
    private EntityManager entityManager;

    @InjectMocks
    private TaskDataFetcher taskDataFetcher;

    @Test
    public void testDataMapping() throws Exception {

        TaskData.DBTaskId dbTaskId = new TaskData.DBTaskId();
        dbTaskId.setJobId(1);
        dbTaskId.setTaskId(2);

        TaskData taskData = new TaskData();
        taskData.setAdditionalClasspath(ImmutableList.of("classpath1", "classpath2", "classpath3"));
        taskData.setCleanScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setDataspaceSelectors(ImmutableList.of(new SelectorData())); // currently, not in GraphQL data model
        taskData.setDependentTasks(null); // currently, not in GraphQL data model
        taskData.setDescription("description");
        taskData.setEnvModifiers(ImmutableList.of(new EnvironmentModifierData())); // currently, not in GraphQL data model
        taskData.setEnvScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setExecutionDuration(3);
        taskData.setExecutionHostName("hostname");
        taskData.setFinishedTime(4);
        taskData.setFlowBlock(FlowBlock.parse(FlowBlock.START.name())); // currently not in GraphQL data model
        taskData.setFlowScript(new ScriptData()); // currently not in GraphQL data model
        taskData.setGenericInformation(ImmutableMap.of("gk1", "gv1"));
        taskData.setId(dbTaskId);
        taskData.setIfBranch(new TaskData()); // currently, not in GraphQL data model
        taskData.setInErrorTime(5);
        taskData.setIteration(6); // currently, not in GraphQL data model
        taskData.setJavaHome("javaHome");
        taskData.setJobData(new JobData()); // currently, not in GraphQL data model
        taskData.setJoinedBranches(ImmutableList.of(new TaskData.DBTaskId())); // currently, not in GraphQL data model
        taskData.setJvmArguments(ImmutableList.of("arg1", "arg2"));
        taskData.setMatchingBlock("matchingBlock"); // currently, not in GraphQL data model
        taskData.setMaxNumberOfExecution(7);
        taskData.setNumberOfExecutionLeft(8);
        taskData.setNumberOfExecutionOnFailureLeft(9);
        taskData.setOnTaskErrorString(OnTaskError.NONE);
        taskData.setParallelEnvNodesNumber(10); // currently, not in GraphQL data model
        taskData.setPostScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setPreciousLogs(true);
        taskData.setPreciousResult(false);
        taskData.setPreScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setReplication(8); // currently, not in GraphQL data model
        taskData.setRestartModeId(RestartMode.ANYWHERE.getIndex());
        taskData.setResultPreview("resultPreview");
        taskData.setRunAsMe(true);
        taskData.setScheduledTime(9);<commit_msg>Change EnvModifiers to set (#25)<commit_after>/*
 * ProActive Parallel Suite(TM):
 * The Open Source library for parallel and distributed
 * Workflows & Scheduling, Orchestration, Cloud Automation
 * and Big Data Analysis on Enterprise Grids & Clouds.
 *
 * Copyright (c) 2007 - 2017 ActiveEon
 * Contact: <EMAIL>
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation: version 3 of
 * the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * If needed, contact us to obtain a release under GPL Version 2 or 3
 * or a different license than the AGPL.
 */
package org.ow2.proactive.scheduling.api.graphql.fetchers;

import static com.google.common.truth.Truth.assertThat;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

import javax.persistence.EntityManager;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.ow2.proactive.scheduler.common.task.OnTaskError;
import org.ow2.proactive.scheduler.common.task.RestartMode;
import org.ow2.proactive.scheduler.common.task.TaskStatus;
import org.ow2.proactive.scheduler.common.task.flow.FlowBlock;
import org.ow2.proactive.scheduler.core.db.EnvironmentModifierData;
import org.ow2.proactive.scheduler.core.db.JobData;
import org.ow2.proactive.scheduler.core.db.ScriptData;
import org.ow2.proactive.scheduler.core.db.SelectorData;
import org.ow2.proactive.scheduler.core.db.TaskData;
import org.ow2.proactive.scheduler.core.db.TaskDataVariable;
import org.ow2.proactive.scheduling.api.graphql.schema.type.Task;

import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;


/**
 * @author ActiveEon Team
 */
@RunWith(MockitoJUnitRunner.class)
public class TaskDataFetcherTest {

    @Mock
    private EntityManager entityManager;

    @InjectMocks
    private TaskDataFetcher taskDataFetcher;

    @Test
    public void testDataMapping() throws Exception {

        TaskData.DBTaskId dbTaskId = new TaskData.DBTaskId();
        dbTaskId.setJobId(1);
        dbTaskId.setTaskId(2);

        TaskData taskData = new TaskData();
        taskData.setAdditionalClasspath(ImmutableList.of("classpath1", "classpath2", "classpath3"));
        taskData.setCleanScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setDataspaceSelectors(ImmutableList.of(new SelectorData())); // currently, not in GraphQL data model
        taskData.setDependentTasks(null); // currently, not in GraphQL data model
        taskData.setDescription("description");
        taskData.setEnvModifiers(ImmutableSet.of(new EnvironmentModifierData())); // currently, not in GraphQL data model
        taskData.setEnvScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setExecutionDuration(3);
        taskData.setExecutionHostName("hostname");
        taskData.setFinishedTime(4);
        taskData.setFlowBlock(FlowBlock.parse(FlowBlock.START.name())); // currently not in GraphQL data model
        taskData.setFlowScript(new ScriptData()); // currently not in GraphQL data model
        taskData.setGenericInformation(ImmutableMap.of("gk1", "gv1"));
        taskData.setId(dbTaskId);
        taskData.setIfBranch(new TaskData()); // currently, not in GraphQL data model
        taskData.setInErrorTime(5);
        taskData.setIteration(6); // currently, not in GraphQL data model
        taskData.setJavaHome("javaHome");
        taskData.setJobData(new JobData()); // currently, not in GraphQL data model
        taskData.setJoinedBranches(ImmutableList.of(new TaskData.DBTaskId())); // currently, not in GraphQL data model
        taskData.setJvmArguments(ImmutableList.of("arg1", "arg2"));
        taskData.setMatchingBlock("matchingBlock"); // currently, not in GraphQL data model
        taskData.setMaxNumberOfExecution(7);
        taskData.setNumberOfExecutionLeft(8);
        taskData.setNumberOfExecutionOnFailureLeft(9);
        taskData.setOnTaskErrorString(OnTaskError.NONE);
        taskData.setParallelEnvNodesNumber(10); // currently, not in GraphQL data model
        taskData.setPostScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setPreciousLogs(true);
        taskData.setPreciousResult(false);
        taskData.setPreScript(new ScriptData()); // currently, not in GraphQL data model
        taskData.setReplication(8); // currently, not in GraphQL data model
        taskData.setRestartModeId(RestartMode.ANYWHERE.getIndex());
        taskData.setResultPreview("resultPreview");
        taskData.setRunAsMe(true);
        taskData.setScheduledTime(9);
{'fraction_non_alphanumeric': 0.0987396948734957, 'fraction_numerical': 0.008338860987396949, 'mean_word_length': 4.081367356764564, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4338806', 'n_tokens_mistral': 3071, 'n_tokens_neox': 3031, 'n_words': 763}