blob: 076c50351f4c529612fac36de958a0050f83ba31 (
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
37
38
39
40
41
42
43
|
// Copyright 2017 Yahoo Holdings. 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 org.xml.sax.InputSource;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author lulf
* @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.getDocumentBuilder().parse(
inputSource((CollectionUtil.mkString(lines, "\n").replace("'", "\""))))
.getDocumentElement();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String joinLines(CharSequence... lines) {
return String.join("\n", lines);
}
private static InputSource inputSource(String str) {
return new InputSource(new StringReader(str));
}
}
|