
package com.asakusafw.bridge.hadoop;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.junit.Test;

import com.asakusafw.bridge.stage.StageInfo;

/**
 * Test for {@link ConfigurationEditor}.
 */
public class ConfigurationEditorTest {

    /**
     * test for merge.
     */
    @Test
    public void merge() {
        Map<String, String> entries = new LinkedHashMap<>();
        entries.put("a", "A");
        entries.put("b", "B");
        entries.put("c", "C");

        Configuration conf = new Configuration(false);
        ConfigurationEditor.merge(conf, entries);

        for (Map.Entry<String, String> entry : entries.entrySet()) {
            assertThat(conf.get(entry.getKey()), is(entry.getValue()));
        }
    }

    /**
     * test for {@link StageInfo}.
     */
    @Test
    public void stage_info() {
        Map<String, String> args = new LinkedHashMap<>();
        args.put("a", "A");
        args.put("b", "B");
        args.put("c", "C");

        StageInfo info = new StageInfo("u", "b", "f", "s", "e", args);

        Configuration conf = new Configuration(false);
        assertThat(ConfigurationEditor.findStageInfo(conf), is(nullValue()));

        ConfigurationEditor.putStageInfo(conf, info);
        StageInfo restored = ConfigurationEditor.findStageInfo(conf);
        assertThat(restored, is(info));
    }
}
