public void testNamespaceOverride() throws Exception { doTest( "<c:x xmlns:c=\"ns1\">\n" + " <c:y/>\n" + " <c:x xmlns:c=\"ns2\">\n" + " <c:y/>\n" + " </c:x>\n" + " <c:y/>\n" + "</c:x>\n", "TAG: name='x' namespace='ns1'\n" + "ATT: name='xmlns:c' value='ns1'\n" + "TAG: name='y' namespace='ns1'\n" + "ENDTAG: name='y' namespace='ns1'\n" + "TAG: name='x' namespace='ns2'\n" + "ATT: name='xmlns:c' value='ns2'\n" + "TAG: name='y' namespace='ns2'\n" + "ENDTAG: name='y' namespace='ns2'\n" + "ENDTAG: name='x' namespace='ns2'\n" + "TAG: name='y' namespace='ns1'\n" + "ENDTAG: name='y' namespace='ns1'\n" + "ENDTAG: name='x' namespace='ns1'\n", XmlBuilder.ProcessingOrder.TAGS_AND_ATTRIBUTES); }
public void testErrors() throws Exception { doTest( "<root>" + "<foo>" + "<bar" + "<" + "</root>", "TAG: name='root' namespace=''\n" + "TAG: name='foo' namespace=''\n" + "ERROR: 'Element foo is not closed'\n" + "ENDTAG: name='foo' namespace=''\n" + "TAG: name='bar' namespace=''\n" + "ERROR: 'Tag start is not closed'\n" + "ENDTAG: name='bar' namespace=''\n" + "TAG: name='' namespace=''\n" + "ERROR: 'Tag name expected'\n" + "ENDTAG: name='' namespace=''\n" + "ENDTAG: name='root' namespace=''\n", XmlBuilder.ProcessingOrder.TAGS_AND_TEXTS ); }
public void testRealJspx() throws Exception { doTest( /* Test: */ "<jsp:root xmlns:jsp=\"http://java.sun.com/JSP/Page\" xmlns=\"http://www.w3.org/1999/xhtml\" version=\"2.0\"\n" + " xmlns:spring=\"http://www.springframework.org/tags\" xmlns:c=\"http://java.sun.com/jsp/jstl/core\">\n" + "<html>\n" + " <c:set var=\"foo\" value=\"${1}\"/>\n" + " <c:set var=\"foobar\" value=\"${2}\"/>\n" + " <spring:bind path=\"test.fieldName\">\n" + " <jsp:scriptlet></jsp:scriptlet>\n" + " </spring:bind>\n" + "</html>\n" + "</jsp:root>", /* Expected result: */ "TAG: name='root' namespace='http://java.sun.com/JSP/Page'\n" + "ATT: name='xmlns:jsp' value='http://java.sun.com/JSP/Page'\n" + "ATT: name='xmlns' value='http://www.w3.org/1999/xhtml'\n" + "ATT: name='version' value='2.0'\n" + "ATT: name='xmlns:spring' value='http://www.springframework.org/tags'\n" + "ATT: name='xmlns:c' value='http://java.sun.com/jsp/jstl/core'\n" + "TAG: name='html' namespace='http://www.w3.org/1999/xhtml'\n" + "TAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "ATT: name='var' value='foo'\n" + "ATT: name='value' value='${1}'\n" + "ENDTAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "TAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "ATT: name='var' value='foobar'\n" + "ATT: name='value' value='${2}'\n" + "ENDTAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "TAG: name='bind' namespace='http://www.springframework.org/tags'\n" + "ATT: name='path' value='test.fieldName'\n" + "TAG: name='scriptlet' namespace='http://java.sun.com/JSP/Page'\n" + "ENDTAG: name='scriptlet' namespace='http://java.sun.com/JSP/Page'\n" + "ENDTAG: name='bind' namespace='http://www.springframework.org/tags'\n" + "ENDTAG: name='html' namespace='http://www.w3.org/1999/xhtml'\n" + "ENDTAG: name='root' namespace='http://java.sun.com/JSP/Page'\n", XmlBuilder.ProcessingOrder.TAGS_AND_ATTRIBUTES); }
public void testRealJspxNoAttributes() throws Exception { doTest( /* Test: */ "<jsp:root xmlns:jsp=\"http://java.sun.com/JSP/Page\" xmlns=\"http://www.w3.org/1999/xhtml\" version=\"2.0\"\n" + " xmlns:spring=\"http://www.springframework.org/tags\" xmlns:c=\"http://java.sun.com/jsp/jstl/core\">\n" + "<html>\n" + " <c:set var=\"foo\" value=\"${1}\"/>\n" + " <c:set var=\"foobar\" value=\"${2}\"/>\n" + " <spring:bind path=\"test.fieldName\">\n" + " <jsp:scriptlet></jsp:scriptlet>\n" + " </spring:bind>\n" + "</html>\n" + "</jsp:root>", /* Expected result: */ "TAG: name='root' namespace='http://java.sun.com/JSP/Page'\n" + "TAG: name='html' namespace='http://www.w3.org/1999/xhtml'\n" + "TAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "ENDTAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "TAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "ENDTAG: name='set' namespace='http://java.sun.com/jsp/jstl/core'\n" + "TAG: name='bind' namespace='http://www.springframework.org/tags'\n" + "TAG: name='scriptlet' namespace='http://java.sun.com/JSP/Page'\n" + "ENDTAG: name='scriptlet' namespace='http://java.sun.com/JSP/Page'\n" + "ENDTAG: name='bind' namespace='http://www.springframework.org/tags'\n" + "ENDTAG: name='html' namespace='http://www.w3.org/1999/xhtml'\n" + "ENDTAG: name='root' namespace='http://java.sun.com/JSP/Page'\n", XmlBuilder.ProcessingOrder.TAGS); }
public void testSimpleEntityResolution() throws Exception { doTest( "<root><</root>", "TAG: name='root' namespace=''\n" + "TEXT: '<' DISPLAY: '<'\n" + "ENDTAG: name='root' namespace=''\n", XmlBuilder.ProcessingOrder.TAGS_AND_TEXTS); }
public void testCDATA() throws Exception { doTest( "<root><![CDATA[<asis/>]]></root>", "TAG: name='root' namespace=''\n" + "TEXT: '<![CDATA[<asis/>]]>' DISPLAY: '<asis/>'\n" + "ENDTAG: name='root' namespace=''\n", XmlBuilder.ProcessingOrder.TAGS_AND_TEXTS ); }
public void testComments() throws Exception { doTest( "<root>" + "<foo>" + "<!--aa-->" + "</foo>" + "<foo>" + "<!---->" + "</foo>" + "<foo>" + "aaa<!--aa-->aaa" + "</foo>" + "<foo>" + "\naaa\n<!--aa-->\naaa\n" + "</foo>" + "</root>", "TAG: name='root' namespace=''\n" + "TAG: name='foo' namespace=''\n" + "ENDTAG: name='foo' namespace=''\n" + "TAG: name='foo' namespace=''\n" + "ENDTAG: name='foo' namespace=''\n" + "TAG: name='foo' namespace=''\n" + "TEXT: 'aaaaaa' DISPLAY: 'aaaaaa'\n" + "ENDTAG: name='foo' namespace=''\n" + "TAG: name='foo' namespace=''\n" + "TEXT: '\naaa\n\naaa\n' DISPLAY: '\naaa\n\naaa\n'\n" + "ENDTAG: name='foo' namespace=''\n" + "ENDTAG: name='root' namespace=''\n", XmlBuilder.ProcessingOrder.TAGS_AND_TEXTS ); }
public void testEmptyXml() throws Exception { doTest("<root/>", "TAG: name='root' namespace=''\n" + "ENDTAG: name='root' namespace=''\n", XmlBuilder.ProcessingOrder.TAGS_AND_ATTRIBUTES); }
private static void doTest(String xml, String expectedEventSequence, final XmlBuilder.ProcessingOrder tagsAndAttributes) { final TestXmlBuilder builder = new TestXmlBuilder(tagsAndAttributes); new XmlBuilderDriver(xml).build(builder); assertEquals(expectedEventSequence, builder.getResult()); }
private static void doTest(String xml, String expectedEventSequence, final XmlBuilder.ProcessingOrder tagsAndAttributes) throws Exception { final TestXmlBuilder builder = new TestXmlBuilder(tagsAndAttributes); new XmlBuilderDriver(xml).build(builder); assertEquals(expectedEventSequence, builder.getResult()); }