use of com.yahoo.document.serialization.XmlStream in project vespa by vespa-engine.
the class XmlStreamTestCase method testAttributeEscaping.
/**
* Test that XML attribute values are XML escaped.
*/
public void testAttributeEscaping() {
// String badString = "\"&<>'\n\r\u0000";
String badString = "\"&<>'";
XmlStream xml = new XmlStream();
xml.beginTag("foo");
xml.addAttribute("bar", badString);
xml.endTag();
String expected = "<foo bar=\""&<>'\"/>\n";
assertEquals(expected, xml.toString());
}
use of com.yahoo.document.serialization.XmlStream in project vespa by vespa-engine.
the class XmlStreamTestCase method testContentEscaping.
/**
* Test that content is XML escaped.
*/
public void testContentEscaping() {
// String badString = "\"&<>'\n\r\u0000";
String badString = "\"&<>'";
XmlStream xml = new XmlStream();
xml.beginTag("foo");
xml.addContent(badString);
xml.endTag();
String expected = "<foo>\"&<>'</foo>\n";
assertEquals(expected, xml.toString());
}
use of com.yahoo.document.serialization.XmlStream in project vespa by vespa-engine.
the class XmlStreamTestCase method testNormalUsage.
/**
* A catch all test checking that regular usage looks good.
*/
public void testNormalUsage() {
XmlStream xml = new XmlStream();
xml.setIndent(" ");
xml.beginTag("foo");
xml.addAttribute("bar", "foo");
xml.addAttribute("foo", "bar");
xml.addContent("foo");
xml.beginTag("bar");
xml.endTag();
xml.beginTag("foo");
xml.beginTag("bar");
xml.addAttribute("foo", "bar");
xml.addContent("bar");
xml.endTag();
xml.endTag();
xml.addContent("bar");
xml.beginTag("foo");
xml.addContent("foo");
xml.addContent("bar");
xml.endTag();
xml.endTag();
String expected = "<foo bar=\"foo\" foo=\"bar\">\n" + " foo\n" + " <bar/>\n" + " <foo>\n" + " <bar foo=\"bar\">bar</bar>\n" + " </foo>\n" + " bar\n" + " <foo>foobar</foo>\n" + "</foo>\n";
assertEquals(expected, xml.toString());
}
use of com.yahoo.document.serialization.XmlStream in project vespa by vespa-engine.
the class XmlStreamTestCase method testIllegalAttributeNames.
/**
* Test that XML tag and attribute names are checked for validity.
* Only the obvious illegal characters are tested currently.
*/
public void testIllegalAttributeNames() {
String[] illegalNames = { ">foo", "foo<bar", " foo", "bar ", "foo bar", "foo\"bar", "&foo" };
XmlStream xml = new XmlStream();
for (String name : illegalNames) {
try {
xml.beginTag(name);
assertTrue(false);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().indexOf("cannot be used as an XML tag name") != -1);
}
}
xml.beginTag("test");
for (String name : illegalNames) {
try {
xml.addAttribute(name, "");
assertTrue(false);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().indexOf("cannot be used as an XML attribute name") != -1);
}
}
}
use of com.yahoo.document.serialization.XmlStream in project vespa by vespa-engine.
the class PredicateFieldValueTest method requireThatXmlOutputIsEmptyForNullPredicate.
@Test
public void requireThatXmlOutputIsEmptyForNullPredicate() {
XmlStream expected = new XmlStream();
expected.beginTag("tag");
expected.endTag();
assertEquals(expected.toString(), printXml("tag", new PredicateFieldValue()));
}
Aggregations