Skip to content

Commit fda498c

Browse files
committed
more testing
1 parent 86780cb commit fda498c

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/test/java/tools/jackson/dataformat/xml/ser/XmlGeneratorInitializerTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tools.jackson.databind.ObjectWriter;
66
import tools.jackson.dataformat.xml.XmlMapper;
77
import tools.jackson.dataformat.xml.XmlTestUtil;
8+
import tools.jackson.dataformat.xml.XmlWriteFeature;
89

910
import static org.junit.jupiter.api.Assertions.assertEquals;
1011
import static org.junit.jupiter.api.Assertions.fail;
@@ -13,7 +14,7 @@ public class XmlGeneratorInitializerTest extends XmlTestUtil
1314
{
1415
private final XmlMapper MAPPER = newMapper();
1516

16-
// [dataformat-xml#150]: DTD writing
17+
// [dataformat-xml#150]: DTD writing -- ok cases
1718
@Test
1819
public void testDTDWithOnlyRootElement() throws Exception
1920
{
@@ -59,6 +60,25 @@ public void testDTDWithInternalSubset() throws Exception
5960
w.writeValueAsString(new StringBean("test")));
6061
}
6162

63+
// Verify prolog ordering: XML declaration must come before DOCTYPE
64+
@Test
65+
public void testDTDWithXmlDeclaration() throws Exception
66+
{
67+
XmlMapper mapper = XmlMapper.builder()
68+
.configure(XmlWriteFeature.WRITE_XML_DECLARATION, true)
69+
.build();
70+
ObjectWriter w = mapper.writer().with(
71+
new XmlGeneratorInitializer()
72+
.setDTD("StringBean", "system", "http://foo.bar", null));
73+
// XML declaration is emitted with single quotes, DOCTYPE with double quotes,
74+
// so cannot use a2q() on the whole string here.
75+
assertEquals("<?xml version='1.0' encoding='UTF-8'?>"
76+
+"<!DOCTYPE StringBean PUBLIC \"http://foo.bar\" \"system\">"
77+
+"<StringBean><text>test</text></StringBean>",
78+
w.writeValueAsString(new StringBean("test")));
79+
}
80+
81+
// [dataformat-xml#150]: DTD writing -- failing cases
6282
@Test
6383
public void testDTDInvalidNoRoot() throws Exception
6484
{

0 commit comments

Comments
 (0)