|
|
|
|
@ -16,7 +16,28 @@
@@ -16,7 +16,28 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.oxm.xstream; |
|
|
|
|
|
|
|
|
|
import com.thoughtworks.xstream.converters.Converter; |
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.Reader; |
|
|
|
|
import java.io.StringReader; |
|
|
|
|
import java.io.StringWriter; |
|
|
|
|
import java.io.Writer; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
import javax.xml.parsers.DocumentBuilder; |
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
|
|
import javax.xml.stream.XMLEventWriter; |
|
|
|
|
import javax.xml.stream.XMLOutputFactory; |
|
|
|
|
import javax.xml.stream.XMLStreamWriter; |
|
|
|
|
import javax.xml.transform.Result; |
|
|
|
|
import javax.xml.transform.Source; |
|
|
|
|
import javax.xml.transform.dom.DOMResult; |
|
|
|
|
import javax.xml.transform.sax.SAXResult; |
|
|
|
|
import javax.xml.transform.stream.StreamResult; |
|
|
|
|
import javax.xml.transform.stream.StreamSource; |
|
|
|
|
|
|
|
|
|
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter; |
|
|
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; |
|
|
|
|
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; |
|
|
|
|
@ -26,7 +47,6 @@ import org.junit.Before;
@@ -26,7 +47,6 @@ import org.junit.Before;
|
|
|
|
|
import org.junit.Ignore; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.mockito.InOrder; |
|
|
|
|
import org.springframework.util.xml.StaxUtils; |
|
|
|
|
import org.w3c.dom.Document; |
|
|
|
|
import org.w3c.dom.Element; |
|
|
|
|
import org.w3c.dom.Node; |
|
|
|
|
@ -36,37 +56,11 @@ import org.xml.sax.ContentHandler;
@@ -36,37 +56,11 @@ import org.xml.sax.ContentHandler;
|
|
|
|
|
import org.xmlunit.builder.Input; |
|
|
|
|
import org.xmlunit.xpath.JAXPXPathEngine; |
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder; |
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
|
|
import javax.xml.stream.XMLEventWriter; |
|
|
|
|
import javax.xml.stream.XMLOutputFactory; |
|
|
|
|
import javax.xml.stream.XMLStreamWriter; |
|
|
|
|
import javax.xml.transform.Result; |
|
|
|
|
import javax.xml.transform.Source; |
|
|
|
|
import javax.xml.transform.dom.DOMResult; |
|
|
|
|
import javax.xml.transform.sax.SAXResult; |
|
|
|
|
import javax.xml.transform.stream.StreamResult; |
|
|
|
|
import javax.xml.transform.stream.StreamSource; |
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.Reader; |
|
|
|
|
import java.io.StringReader; |
|
|
|
|
import java.io.StringWriter; |
|
|
|
|
import java.io.Writer; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
import org.springframework.util.xml.StaxUtils; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
import static org.junit.Assert.assertThat; |
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
import static org.mockito.BDDMockito.eq; |
|
|
|
|
import static org.mockito.BDDMockito.inOrder; |
|
|
|
|
import static org.mockito.BDDMockito.isA; |
|
|
|
|
import static org.mockito.BDDMockito.mock; |
|
|
|
|
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo; |
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
import static org.mockito.BDDMockito.*; |
|
|
|
|
import static org.xmlunit.matchers.CompareMatcher.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Arjen Poutsma |
|
|
|
|
@ -80,8 +74,9 @@ public class XStreamMarshallerTests {
@@ -80,8 +74,9 @@ public class XStreamMarshallerTests {
|
|
|
|
|
|
|
|
|
|
private Flight flight; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void createMarshaller() throws Exception { |
|
|
|
|
public void createMarshaller() { |
|
|
|
|
marshaller = new XStreamMarshaller(); |
|
|
|
|
Map<String, String> aliases = new HashMap<>(); |
|
|
|
|
aliases.put("flight", Flight.class.getName()); |
|
|
|
|
@ -90,6 +85,7 @@ public class XStreamMarshallerTests {
@@ -90,6 +85,7 @@ public class XStreamMarshallerTests {
|
|
|
|
|
flight.setFlightNumber(42L); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void marshalDOMResult() throws Exception { |
|
|
|
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); |
|
|
|
|
@ -190,7 +186,7 @@ public class XStreamMarshallerTests {
@@ -190,7 +186,7 @@ public class XStreamMarshallerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void converters() throws Exception { |
|
|
|
|
marshaller.setConverters(new Converter[]{new EncodedByteArrayConverter()}); |
|
|
|
|
marshaller.setConverters(new EncodedByteArrayConverter()); |
|
|
|
|
byte[] buf = new byte[]{0x1, 0x2}; |
|
|
|
|
Writer writer = new StringWriter(); |
|
|
|
|
marshaller.marshal(buf, new StreamResult(writer)); |
|
|
|
|
@ -229,8 +225,7 @@ public class XStreamMarshallerTests {
@@ -229,8 +225,7 @@ public class XStreamMarshallerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void useAttributesForClassStringListMap() throws Exception { |
|
|
|
|
marshaller |
|
|
|
|
.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber"))); |
|
|
|
|
marshaller.setUseAttributeFor(Collections.singletonMap(Flight.class, Collections.singletonList("flightNumber"))); |
|
|
|
|
Writer writer = new StringWriter(); |
|
|
|
|
marshaller.marshal(flight, new StreamResult(writer)); |
|
|
|
|
String expected = "<flight flightNumber=\"42\" />"; |
|
|
|
|
@ -349,6 +344,7 @@ public class XStreamMarshallerTests {
@@ -349,6 +344,7 @@ public class XStreamMarshallerTests {
|
|
|
|
|
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(expected)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void assertXpathExists(String xPathExpression, String inXMLString){ |
|
|
|
|
Source source = Input.fromString(inXMLString).build(); |
|
|
|
|
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source); |
|
|
|
|
|