All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sahagin.share.runresults.RootFuncRunResult Maven / Gradle / Ivy

There is a newer version: 0.10.1
Show newest version
package org.sahagin.share.runresults;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.sahagin.share.CommonUtils;
import org.sahagin.share.srctree.TestFunction;
import org.sahagin.share.yaml.YamlUtils;
import org.sahagin.share.yaml.YamlConvertException;
import org.sahagin.share.yaml.YamlConvertible;

public class RootFuncRunResult implements YamlConvertible {
    private static final String MSG_SRC_TREE_FORMAT_MISMATCH
    = "expected formatVersion is \"%s\", but actual is \"%s\"";

    private String rootFunctionKey;
    private TestFunction rootFunction;
    private List runFailures = new ArrayList(16);
    private List lineScreenCaptures = new ArrayList(32);

    public String getRootFunctionKey() {
        return rootFunctionKey;
    }

    public void setRootFunctionKey(String rootFunctionKey) {
        this.rootFunctionKey = rootFunctionKey;
    }

    public TestFunction getRootFunction() {
        return rootFunction;
    }

    public void setRootFunction(TestFunction rootFunction) {
        this.rootFunction = rootFunction;
    }

    public List getRunFailures() {
        return runFailures;
    }

    public void addRunFailure(RunFailure runFailure) {
        this.runFailures.add(runFailure);
    }

    public List getLineScreenCaptures() {
        return lineScreenCaptures;
    }

    public void addLineScreenCapture(LineScreenCapture lineScreenCapture) {
        this.lineScreenCaptures.add(lineScreenCapture);
    }

    @Override
    public Map toYamlObject() {
        Map result = new HashMap(4);
        result.put("rootFunctionKey", rootFunctionKey);
        result.put("runFailures", YamlUtils.toYamlObjectList(runFailures));
        result.put("lineScreenCaptures", YamlUtils.toYamlObjectList(lineScreenCaptures));
        result.put("formatVersion", CommonUtils.formatVersion());
        return result;
    }

    @Override
    public void fromYamlObject(Map yamlObject)
            throws YamlConvertException {
        rootFunctionKey = YamlUtils.getStrValue(yamlObject, "rootFunctionKey");
        List> runFailuresYamlObj
        = YamlUtils.getYamlObjectListValue(yamlObject, "runFailures");
        runFailures = new ArrayList(runFailuresYamlObj.size());
        for (Map runFailureYamlObj : runFailuresYamlObj) {
            RunFailure runFailure = new RunFailure();
            runFailure.fromYamlObject(runFailureYamlObj);
            runFailures.add(runFailure);
        }
        List> lineScreenCapturesYamlObj
        = YamlUtils.getYamlObjectListValue(yamlObject, "lineScreenCaptures");
        lineScreenCaptures = new ArrayList(lineScreenCapturesYamlObj.size());
        for (Map lineScreenCaptureYamlObj : lineScreenCapturesYamlObj) {
            LineScreenCapture lineScreenCapture = new LineScreenCapture();
            lineScreenCapture.fromYamlObject(lineScreenCaptureYamlObj);
            lineScreenCaptures.add(lineScreenCapture);
        }
        String formatVersion = YamlUtils.getStrValue(yamlObject, "formatVersion");
        // "*" means arbitrary version (this is only for testing sahagin itself)
        if (!formatVersion.equals("*")
                && !formatVersion.equals(CommonUtils.formatVersion())) {
            throw new YamlConvertException(String.format
                    (MSG_SRC_TREE_FORMAT_MISMATCH, CommonUtils.formatVersion(), formatVersion));
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy