|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2009 the original author or authors. |
| 2 | + * Copyright 2002-2010 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
28 | 28 | import javax.xml.transform.stax.StAXResult;
|
29 | 29 | import javax.xml.transform.stream.StreamResult;
|
30 | 30 |
|
31 |
| -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; |
| 31 | +import static org.custommonkey.xmlunit.XMLAssert.*; |
32 | 32 | import org.custommonkey.xmlunit.XMLUnit;
|
| 33 | +import static org.junit.Assert.assertTrue; |
33 | 34 | import org.junit.Before;
|
34 | 35 | import org.junit.Test;
|
35 | 36 | import org.w3c.dom.Attr;
|
@@ -86,6 +87,30 @@ public void marshalDOMResult() throws Exception {
|
86 | 87 | assertXMLEqual("Marshaller writes invalid DOMResult", expected, result);
|
87 | 88 | }
|
88 | 89 |
|
| 90 | + @Test |
| 91 | + public void marshalEmptyDOMResult() throws Exception { |
| 92 | + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); |
| 93 | + documentBuilderFactory.setNamespaceAware(true); |
| 94 | + DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); |
| 95 | + DOMResult domResult = new DOMResult(); |
| 96 | + marshaller.marshal(flights, domResult); |
| 97 | + assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document); |
| 98 | + Document result = (Document) domResult.getNode(); |
| 99 | + Document expected = builder.newDocument(); |
| 100 | + Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights"); |
| 101 | + Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns"); |
| 102 | + namespace.setNodeValue("http://samples.springframework.org/flight"); |
| 103 | + flightsElement.setAttributeNode(namespace); |
| 104 | + expected.appendChild(flightsElement); |
| 105 | + Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight"); |
| 106 | + flightsElement.appendChild(flightElement); |
| 107 | + Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number"); |
| 108 | + flightElement.appendChild(numberElement); |
| 109 | + Text text = expected.createTextNode("42"); |
| 110 | + numberElement.appendChild(text); |
| 111 | + assertXMLEqual("Marshaller writes invalid DOMResult", expected, result); |
| 112 | + } |
| 113 | + |
89 | 114 | @Test
|
90 | 115 | public void marshalStreamResultWriter() throws Exception {
|
91 | 116 | StringWriter writer = new StringWriter();
|
|
0 commit comments