- Removed GenericMarshaller & GenericUnmarshaller
- Made Marshaller and Unmarshaller generic
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.jaxb;
|
||||
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.xml.sax.ContentHandler;
|
||||
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
|
||||
public abstract class AbstractJaxbMarshallerTestCase extends AbstractMarshallerTestCase {
|
||||
|
||||
public void testMarshalSaxResult() throws Exception {
|
||||
MockControl handlerControl = MockControl.createStrictControl(ContentHandler.class);
|
||||
ContentHandler handlerMock = (ContentHandler) handlerControl.getMock();
|
||||
handlerMock.setDocumentLocator(null);
|
||||
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
handlerMock.startDocument();
|
||||
handlerMock.startPrefixMapping("", "http://samples.springframework.org/flight");
|
||||
handlerMock.startElement("http://samples.springframework.org/flight", "flights", "flights", null);
|
||||
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
handlerMock.startElement("http://samples.springframework.org/flight", "flight", "flight", null);
|
||||
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
handlerMock.startElement("http://samples.springframework.org/flight", "number", "number", null);
|
||||
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
handlerMock.characters(new char[]{'4', '2'}, 0, 2);
|
||||
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "number", "number");
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "flight");
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "flights");
|
||||
handlerMock.endPrefixMapping("");
|
||||
handlerMock.endDocument();
|
||||
|
||||
handlerControl.replay();
|
||||
SAXResult result = new SAXResult(handlerMock);
|
||||
marshaller.marshal(flights, result);
|
||||
handlerControl.verify();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -16,153 +16,78 @@
|
||||
|
||||
package org.springframework.oxm.jaxb;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.datatype.Duration;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
import javax.xml.namespace.QName;
|
||||
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.stax.StAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public class Jaxb2MarshallerTest {
|
||||
public class Jaxb2MarshallerTest extends AbstractMarshallerTestCase {
|
||||
|
||||
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb";
|
||||
|
||||
private static final String EXPECTED_STRING =
|
||||
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
|
||||
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
|
||||
|
||||
private Jaxb2Marshaller marshaller;
|
||||
|
||||
private Flights flights;
|
||||
|
||||
@Before
|
||||
public void createMarshaller() throws Exception {
|
||||
@Override
|
||||
public Marshaller createMarshaller() throws Exception {
|
||||
marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setContextPath(CONTEXT_PATH);
|
||||
marshaller.afterPropertiesSet();
|
||||
return marshaller;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createFlights() {
|
||||
FlightType flight = new FlightType();
|
||||
flight.setNumber(42L);
|
||||
flights = new Flights();
|
||||
flights.getFlight().add(flight);
|
||||
return flights;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalDOMResult() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
DOMResult domResult = new DOMResult(document);
|
||||
marshaller.marshal(flights, domResult);
|
||||
Document expected = builder.newDocument();
|
||||
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
|
||||
expected.appendChild(flightsElement);
|
||||
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
|
||||
flightsElement.appendChild(flightElement);
|
||||
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
|
||||
flightElement.appendChild(numberElement);
|
||||
Text text = expected.createTextNode("42");
|
||||
numberElement.appendChild(text);
|
||||
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
|
||||
}
|
||||
public void marshalSAXResult() throws Exception {
|
||||
ContentHandler handlerMock = createStrictMock(ContentHandler.class);
|
||||
handlerMock.setDocumentLocator(isA(Locator.class));
|
||||
handlerMock.startDocument();
|
||||
handlerMock.startPrefixMapping("", "http://samples.springframework.org/flight");
|
||||
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("flights"),
|
||||
isA(Attributes.class));
|
||||
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("flight"),
|
||||
isA(Attributes.class));
|
||||
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("number"),
|
||||
isA(Attributes.class));
|
||||
handlerMock.characters(isA(char[].class), eq(0), eq(2));
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "number", "number");
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "flight");
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "flights");
|
||||
handlerMock.endPrefixMapping("");
|
||||
handlerMock.endDocument();
|
||||
replay(handlerMock);
|
||||
|
||||
@Test
|
||||
public void marshalStreamResultWriter() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
SAXResult result = new SAXResult(handlerMock);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalStreamResultOutputStream() throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
StreamResult result = new StreamResult(os);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
|
||||
new String(os.toByteArray(), "UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalStaxResultXMLStreamWriter() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
StringWriter writer = new StringWriter();
|
||||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
|
||||
Result result = StaxUtils.createStaxResult(streamWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalStaxResultXMLEventWriter() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
StringWriter writer = new StringWriter();
|
||||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
|
||||
Result result = StaxUtils.createStaxResult(eventWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalStaxResultXMLStreamWriterJaxp14() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
StringWriter writer = new StringWriter();
|
||||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
|
||||
StAXResult result = new StAXResult(streamWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalStaxResultXMLEventWriterJaxp14() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
StringWriter writer = new StringWriter();
|
||||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
|
||||
StAXResult result = new StAXResult(eventWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
verify(handlerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,7 +95,8 @@ public class Jaxb2MarshallerTest {
|
||||
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setContextPath(CONTEXT_PATH);
|
||||
marshaller.setMarshallerProperties(
|
||||
Collections.singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE));
|
||||
Collections.<String, Object>singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT,
|
||||
Boolean.TRUE));
|
||||
marshaller.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -197,43 +123,13 @@ public class Jaxb2MarshallerTest {
|
||||
marshaller.marshal(flights, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalSaxResult() throws Exception {
|
||||
ContentHandler handlerMock = createStrictMock(ContentHandler.class);
|
||||
handlerMock.setDocumentLocator(isA(Locator.class));
|
||||
handlerMock.startDocument();
|
||||
handlerMock.startPrefixMapping("", "http://samples.springframework.org/flight");
|
||||
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("flights"),
|
||||
isA(Attributes.class));
|
||||
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("flight"),
|
||||
isA(Attributes.class));
|
||||
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("number"),
|
||||
isA(Attributes.class));
|
||||
handlerMock.characters(isA(char[].class), eq(0), eq(2));
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "number", "number");
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "flight");
|
||||
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "flights");
|
||||
handlerMock.endPrefixMapping("");
|
||||
handlerMock.endDocument();
|
||||
replay(handlerMock);
|
||||
|
||||
SAXResult result = new SAXResult(handlerMock);
|
||||
marshaller.marshal(flights, result);
|
||||
verify(handlerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsContextPath() throws Exception {
|
||||
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
|
||||
assertTrue("Jaxb2Marshaller does not support Flights",
|
||||
marshaller.supports(createFlights.getGenericReturnType()));
|
||||
assertTrue("Jaxb2Marshaller does not support Flights", marshaller.supports(createFlights.getReturnType()));
|
||||
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
|
||||
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
|
||||
marshaller.supports(createFlight.getGenericReturnType()));
|
||||
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
|
||||
JAXBElement<Jaxb2MarshallerTest> testElement =
|
||||
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
|
||||
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
|
||||
marshaller.supports(createFlight.getReturnType()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,39 +138,10 @@ public class Jaxb2MarshallerTest {
|
||||
marshaller.setClassesToBeBound(new Class[]{Flights.class, FlightType.class});
|
||||
marshaller.afterPropertiesSet();
|
||||
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
|
||||
assertTrue("Jaxb2Marshaller does not support Flights",
|
||||
marshaller.supports(createFlights.getGenericReturnType()));
|
||||
assertTrue("Jaxb2Marshaller does not support Flights", marshaller.supports(createFlights.getReturnType()));
|
||||
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
|
||||
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
|
||||
marshaller.supports(createFlight.getGenericReturnType()));
|
||||
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
|
||||
JAXBElement<Jaxb2MarshallerTest> testElement =
|
||||
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
|
||||
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsPrimitives() throws Exception {
|
||||
Method primitives = getClass()
|
||||
.getDeclaredMethod("primitives", JAXBElement.class, JAXBElement.class, JAXBElement.class,
|
||||
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class);
|
||||
Type[] types = primitives.getGenericParameterTypes();
|
||||
for (Type type : types) {
|
||||
assertTrue("Jaxb2Marshaller does not support " + type, marshaller.supports(type));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsStandards() throws Exception {
|
||||
Method standards = getClass()
|
||||
.getDeclaredMethod("standards", JAXBElement.class, JAXBElement.class, JAXBElement.class,
|
||||
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
|
||||
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
|
||||
JAXBElement.class);
|
||||
Type[] types = standards.getGenericParameterTypes();
|
||||
for (Type type : types) {
|
||||
assertTrue("Jaxb2Marshaller does not support " + type, marshaller.supports(type));
|
||||
}
|
||||
marshaller.supports(createFlight.getReturnType()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -300,30 +167,4 @@ public class Jaxb2MarshallerTest {
|
||||
verify(mimeContainer);
|
||||
assertTrue("No XML written", writer.toString().length() > 0);
|
||||
}
|
||||
|
||||
private void primitives(JAXBElement<Boolean> bool,
|
||||
JAXBElement<Byte> aByte,
|
||||
JAXBElement<Short> aShort,
|
||||
JAXBElement<Integer> anInteger,
|
||||
JAXBElement<Long> aLong,
|
||||
JAXBElement<Float> aFloat,
|
||||
JAXBElement<Double> aDouble,
|
||||
JAXBElement<byte[]> byteArray) {
|
||||
}
|
||||
|
||||
private void standards(JAXBElement<String> string,
|
||||
JAXBElement<BigInteger> integer,
|
||||
JAXBElement<BigDecimal> decimal,
|
||||
JAXBElement<Calendar> calendar,
|
||||
JAXBElement<Date> date,
|
||||
JAXBElement<QName> qName,
|
||||
JAXBElement<URI> uri,
|
||||
JAXBElement<XMLGregorianCalendar> xmlGregorianCalendar,
|
||||
JAXBElement<Duration> duration,
|
||||
JAXBElement<Object> object,
|
||||
JAXBElement<Image> image,
|
||||
JAXBElement<DataHandler> dataHandler,
|
||||
JAXBElement<Source> source,
|
||||
JAXBElement<UUID> uuid) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,126 +16,40 @@
|
||||
|
||||
package org.springframework.oxm.jaxb;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringReader;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stax.StAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public class Jaxb2UnmarshallerTest {
|
||||
public class Jaxb2UnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
|
||||
private static final String INPUT_STRING = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
|
||||
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
|
||||
|
||||
private Jaxb2Marshaller unmarshaller;
|
||||
|
||||
@Before
|
||||
public void createMarshaller() throws Exception {
|
||||
@Override
|
||||
public Unmarshaller createUnmarshaller() throws Exception {
|
||||
unmarshaller = new Jaxb2Marshaller();
|
||||
unmarshaller.setContextPath("org.springframework.oxm.jaxb");
|
||||
unmarshaller.setSchema(new ClassPathResource("org/springframework/oxm/flight.xsd"));
|
||||
unmarshaller.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalDomSource() throws Exception {
|
||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
|
||||
document.appendChild(flightsElement);
|
||||
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
|
||||
flightsElement.appendChild(flightElement);
|
||||
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
|
||||
flightElement.appendChild(numberElement);
|
||||
Text text = document.createTextNode("42");
|
||||
numberElement.appendChild(text);
|
||||
DOMSource source = new DOMSource(document);
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalStreamSourceReader() throws Exception {
|
||||
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalStreamSourceInputStream() throws Exception {
|
||||
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalSAXSource() throws Exception {
|
||||
XMLReader reader = XMLReaderFactory.createXMLReader();
|
||||
SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING)));
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
|
||||
Source source = StaxUtils.createStaxSource(streamReader);
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalStaxSourceXmlEventReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
|
||||
Source source = StaxUtils.createStaxSource(eventReader);
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalStaxSourceXmlStreamReaderJaxp14() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
|
||||
StAXSource source = new StAXSource(streamReader);
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmarshalStaxSourceXmlEventReaderJaxp14() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
|
||||
StAXSource source = new StAXSource(eventReader);
|
||||
Object flights = unmarshaller.unmarshal(source);
|
||||
testFlights(flights);
|
||||
return unmarshaller;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,20 +89,23 @@ public class Jaxb2UnmarshallerTest {
|
||||
assertNotNull("datahandler property not set", object.getSwaDataHandler());
|
||||
}
|
||||
|
||||
private void testFlights(Object o) {
|
||||
@Override
|
||||
protected void testFlights(Object o) {
|
||||
Flights flights = (Flights) o;
|
||||
assertNotNull("Flights is null", flights);
|
||||
assertEquals("Invalid amount of flight elements", 1, flights.getFlight().size());
|
||||
testFlight(flights.getFlight().get(0));
|
||||
}
|
||||
|
||||
private void testFlight(Object o) {
|
||||
@Override
|
||||
protected void testFlight(Object o) {
|
||||
FlightType flight = (FlightType) o;
|
||||
assertNotNull("Flight is null", flight);
|
||||
assertEquals("Number is invalid", 42L, flight.getNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.oxm.jaxb;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.MarshalException;
|
||||
import javax.xml.bind.UnmarshalException;
|
||||
import javax.xml.bind.ValidationException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JaxbUtilsTest extends TestCase {
|
||||
|
||||
public void testGetJaxbVersion() throws Exception {
|
||||
assertEquals("Invalid JAXB version", JaxbUtils.JAXB_2, JaxbUtils.getJaxbVersion());
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import org.junit.Test;
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
|
||||
@Ignore
|
||||
@Ignore("Code generation not yet support by Spring Build")
|
||||
public class JibxMarshallerTest extends AbstractMarshallerTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Ignore;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
|
||||
@Ignore
|
||||
@Ignore("Code generation not yet support by Spring Build")
|
||||
public class JibxUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.Test;
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
|
||||
@Ignore
|
||||
@Ignore("Code generation not yet support by Spring Build")
|
||||
public class XmlBeansMarshallerTest extends AbstractMarshallerTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
@Ignore
|
||||
@Ignore("Code generation not yet support by Spring Build")
|
||||
public class XmlBeansUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user