blob: 16954e52edce65a47ec1c93d5f6d114515f73470 [file] [log] [blame]
Yuta HIGUCHIb34078e2017-08-17 12:06:02 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.util;
17
18import static org.junit.Assert.*;
19
20import org.junit.Test;
21
22public class XmlStringTest {
23
24 @Test
25 public void testToString() {
26 String input = "<root> <a some='foo '/><b attr='4' ><c>42</c></b></root>";
27 CharSequence xml = XmlString.prettifyXml(input);
28 String expected = "<root>\n"
29 + " <a some=\"foo \"/>\n"
30 + " <b attr=\"4\">\n"
31 + " <c>42</c>\n"
32 + " </b>\n"
33 + "</root>\n";
34 assertEquals(expected, xml.toString());
35 }
36
37 @Test
38 public void illFormed() {
39 String input = "<root> <a some='foo '/>";
40
41 assertEquals(input, XmlString.prettifyXml(input).toString());
42 }
43
Yuta HIGUCHI7da7e622018-02-13 20:24:51 -080044 @Test
45 public void fragments() {
46 String input = "<root/> <a some='foo '/>";
47 String expected = "<root/>\n"
48 + "<a some=\"foo \"/>\n";
49 assertEquals(expected, XmlString.prettifyXml(input).toString());
50 }
51
Yuta HIGUCHIb34078e2017-08-17 12:06:02 -070052}