aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/config/model/test/TestUtil.java
blob: 94969aa53240f9c42223ce3fdad96fe6d8605d2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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.Arrays;
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<String> lines = new ArrayList<>();
        lines.add("<?xml version='1.0' encoding='utf-8' ?>");
        lines.addAll(Arrays.asList(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);
    }

}