Search in sources :

Example 1 with XmlStream

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=\"&quot;&amp;&lt;&gt;'\"/>\n";
    assertEquals(expected, xml.toString());
}
Also used : XmlStream(com.yahoo.document.serialization.XmlStream)

Example 2 with XmlStream

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>\"&amp;&lt;&gt;'</foo>\n";
    assertEquals(expected, xml.toString());
}
Also used : XmlStream(com.yahoo.document.serialization.XmlStream)

Example 3 with XmlStream

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());
}
Also used : XmlStream(com.yahoo.document.serialization.XmlStream)

Example 4 with XmlStream

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);
        }
    }
}
Also used : XmlStream(com.yahoo.document.serialization.XmlStream)

Example 5 with XmlStream

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()));
}
Also used : XmlStream(com.yahoo.document.serialization.XmlStream) Test(org.junit.Test)

Aggregations

XmlStream (com.yahoo.document.serialization.XmlStream)7 Test (org.junit.Test)2 FeatureSet (com.yahoo.document.predicate.FeatureSet)1 Predicate (com.yahoo.document.predicate.Predicate)1