diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-01-24 17:05:31 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-01-24 18:23:06 (GMT) |
commit | 12740e2b70c48e478af53de31624c388e1e89e0f (patch) | |
tree | 2ca29487cfcb094cd594cb60363a267a632f024b /test/com | |
parent | 54587c45febd330e2b8e117fe0815569bd37e366 (diff) | |
download | stroke-12740e2b70c48e478af53de31624c388e1e89e0f.zip stroke-12740e2b70c48e478af53de31624c388e1e89e0f.tar.bz2 |
Fix XML serialisation.
Also port the unit tests from Swiften.
Diffstat (limited to 'test/com')
-rw-r--r-- | test/com/isode/stroke/serializer/xml/XMLElementTest.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/test/com/isode/stroke/serializer/xml/XMLElementTest.java b/test/com/isode/stroke/serializer/xml/XMLElementTest.java new file mode 100644 index 0000000..8377193 --- /dev/null +++ b/test/com/isode/stroke/serializer/xml/XMLElementTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010 Remko Tronçon + * All rights reserved. + */ +package com.isode.stroke.serializer.xml; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class XMLElementTest { + + @Test + public void testSerialize() { + XMLElement testling = new XMLElement("foo", "http://example.com"); + testling.setAttribute("myatt", "myval"); + XMLElement barElement = new XMLElement("bar"); + barElement.addNode(new XMLTextNode("Blo")); + testling.addNode(barElement); + XMLElement bazElement = new XMLElement("baz"); + bazElement.addNode(new XMLTextNode("Bli&</stream>")); + testling.addNode(bazElement); + + String result = testling.serialize(); + String expectedResult = + "<foo myatt=\"myval\" xmlns=\"http://example.com\">" + + "<bar>Blo</bar>" + + "<baz>Bli&</stream></baz>" + + "</foo>"; + + assertEquals(expectedResult, result); + } + + @Test + public void testSerialize_NoChildren() { + XMLElement testling = new XMLElement("foo", "http://example.com"); + + assertEquals("<foo xmlns=\"http://example.com\"/>", testling.serialize()); + } + + @Test + public void testSerialize_SpecialAttributeCharacters() { + XMLElement testling = new XMLElement("foo"); + testling.setAttribute("myatt", "<\"'&>"); + + assertEquals("<foo myatt=\"<"'&>\"/>", testling.serialize()); + } + + @Test + public void testSerialize_EmptyAttributeValue() { + XMLElement testling = new XMLElement("foo"); + testling.setAttribute("myatt", ""); + + assertEquals("<foo myatt=\"\"/>", testling.serialize()); + } +} + + |