Created
June 6, 2018 20:14
-
-
Save luanpotter/fb34841379ce48643ce035ca1f878884 to your computer and use it in GitHub Desktop.
a simple test using xmlbeam that fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import static com.google.common.truth.Truth.assertThat; | |
import org.w3c.dom.Node; | |
import org.xmlbeam.XBProjector; | |
import org.xmlbeam.types.XBAutoMap; | |
public class SimpleTest { | |
@Test | |
public void test1() { | |
// fetch the node, this works fine | |
String xml2 = "<a><b><![CDATA[c]]></b></a>"; | |
XBAutoMap<Node> map2 = new XBProjector().onXMLString(xml2).createMapOf(Node.class); | |
String c2 = map2.get("//a/b").getTextContent(); | |
assertThat(c2).isEqualTo("c"); | |
} | |
@Test | |
public void test2() { | |
// no cdata, works with String | |
String xml = "<a><b>c></b></a>"; | |
XBAutoMap<String> map = new XBProjector().onXMLString(xml).createMapOf(String.class); | |
String c = map.get("//a/b"); | |
assertThat(c).isEqualTo("c"); | |
// but this doesn't work, it should | |
XBAutoMap<String> map2 = new XBProjector().onXMLString(xml).createMapOf(String.class); | |
String c2 = map2.get("//a/b/text()"); | |
assertThat(c2).isEqualTo("c"); | |
} | |
@Test | |
public void test3() { | |
// this fails | |
String xml = "<a><b><![CDATA[c]]></b></a>"; | |
XBAutoMap<String> map = new XBProjector().onXMLString(xml).createMapOf(String.class); | |
String c = map.get("//a/b"); | |
assertThat(c).isEqualTo("c"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment