1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.oxm.jibx;
18
19 import org.custommonkey.xmlunit.XMLUnit;
20
21 import org.springframework.oxm.AbstractMarshallerTestCase;
22 import org.springframework.oxm.Marshaller;
23 import org.springframework.xml.transform.StringResult;
24
25 public class JibxMarshallerTest extends AbstractMarshallerTestCase {
26
27 protected Marshaller createMarshaller() throws Exception {
28 JibxMarshaller marshaller = new JibxMarshaller();
29 marshaller.setTargetClass(Flights.class);
30 marshaller.afterPropertiesSet();
31 return marshaller;
32 }
33
34 protected Object createFlights() {
35 Flights flights = new Flights();
36 FlightType flight = new FlightType();
37 flight.setNumber(42L);
38 flights.addFlight(flight);
39 return flights;
40 }
41
42 public void testAfterPropertiesSetNoContextPath() throws Exception {
43 try {
44 JibxMarshaller marshaller = new JibxMarshaller();
45 marshaller.afterPropertiesSet();
46 fail("Should have thrown an IllegalArgumentException");
47 }
48 catch (IllegalArgumentException e) {
49 }
50 }
51
52 public void testIndentation() throws Exception {
53 ((JibxMarshaller) marshaller).setIndent(4);
54 StringResult result = new StringResult();
55 marshaller.marshal(flights, result);
56 XMLUnit.setIgnoreWhitespace(false);
57 String expected = "<?xml version=\"1.0\"?>\n" +
58 "<flights xmlns=\"http://samples.springframework.org/flight\">\n" + " <flight>\n" +
59 " <number>42</number>\n" + " </flight>\n" + "</flights>";
60 assertXMLEqual(expected, result.toString());
61 }
62
63 public void testEncodingAndStandalone() throws Exception {
64 ((JibxMarshaller) marshaller).setEncoding("ISO-8859-1");
65 ((JibxMarshaller) marshaller).setStandalone(Boolean.TRUE);
66 StringResult result = new StringResult();
67 marshaller.marshal(flights, result);
68 assertTrue("Encoding and standalone not set",
69 result.toString().startsWith("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"));
70 }
71
72 public void testSupports() throws Exception {
73 assertTrue("JibxMarshaller does not support Flights", marshaller.supports(Flights.class));
74 assertTrue("JibxMarshaller does not support FlightType", marshaller.supports(FlightType.class));
75 assertFalse("JibxMarshaller supports illegal type", marshaller.supports(getClass()));
76 }
77
78
79 }