1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.oxm.xmlbeans;
17
18 import java.io.ByteArrayOutputStream;
19 import javax.xml.transform.stream.StreamResult;
20
21 import org.apache.xmlbeans.XmlObject;
22 import org.springframework.oxm.AbstractMarshallerTestCase;
23 import org.springframework.oxm.Marshaller;
24 import org.springframework.samples.flight.FlightType;
25 import org.springframework.samples.flight.FlightsDocument;
26 import org.springframework.samples.flight.FlightsDocument.Flights;
27
28 public class XmlBeansMarshallerTest extends AbstractMarshallerTestCase {
29
30 protected Marshaller createMarshaller() throws Exception {
31 return new XmlBeansMarshaller();
32 }
33
34 public void testMarshalNonXmlObject() throws Exception {
35 try {
36 marshaller.marshal(new Object(), new StreamResult(new ByteArrayOutputStream()));
37 fail("XmlBeansMarshaller did not throw ClassCastException for non-XmlObject");
38 }
39 catch (ClassCastException e) {
40
41 }
42 }
43
44 protected Object createFlights() {
45 FlightsDocument flightsDocument = FlightsDocument.Factory.newInstance();
46 Flights flights = flightsDocument.addNewFlights();
47 FlightType flightType = flights.addNewFlight();
48 flightType.setNumber(42L);
49 return flightsDocument;
50 }
51
52 public void testSupports() throws Exception {
53 assertTrue("XmlBeansMarshaller does not support XmlObject", marshaller.supports(XmlObject.class));
54 assertFalse("XmlBeansMarshaller supports other objects", marshaller.supports(Object.class));
55 assertTrue("XmlBeansMarshaller does not support FlightsDocument", marshaller.supports(FlightsDocument.class));
56 assertTrue("XmlBeansMarshaller does not support Flights", marshaller.supports(Flights.class));
57 assertTrue("XmlBeansMarshaller does not support FlightType", marshaller.supports(FlightType.class));
58 }
59 }