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

com.yahoo.config.model.test.TestUtil Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.test;

import com.yahoo.collections.CollectionUtil;
import com.yahoo.config.model.builder.xml.XmlHelper;
import org.w3c.dom.Element;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Ulf Lilleengen
 * @author gjoranv
 */
public class TestUtil {
    /**
     * @param xmlLines XML with " replaced with '
     */
    public static Element parse(String... xmlLines) {
        List lines = new ArrayList<>();
        lines.add("");
        lines.addAll(List.of(xmlLines));

        try {
            return XmlHelper.getDocument(new StringReader(CollectionUtil.mkString(lines, "\n").replace("'", "\""))).getDocumentElement();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String joinLines(CharSequence... lines) {
        return String.join("\n", lines);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy