1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.oxm.jaxb;
17
18 import java.util.Collections;
19
20 import org.springframework.oxm.Marshaller;
21 import org.springframework.oxm.XmlMappingException;
22 import org.springframework.oxm.jaxb1.FlightType;
23 import org.springframework.oxm.jaxb1.Flights;
24 import org.springframework.oxm.jaxb1.FlightsType;
25 import org.springframework.oxm.jaxb1.impl.FlightTypeImpl;
26 import org.springframework.oxm.jaxb1.impl.FlightsImpl;
27
28 public class Jaxb1MarshallerTest extends AbstractJaxbMarshallerTestCase {
29
30 private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb1";
31
32 protected final Marshaller createMarshaller() throws Exception {
33 Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
34 marshaller.setContextPaths(new String[]{CONTEXT_PATH});
35 marshaller.afterPropertiesSet();
36 return marshaller;
37 }
38
39 protected Object createFlights() {
40 FlightType flight = new FlightTypeImpl();
41 flight.setNumber(42L);
42 Flights flights = new FlightsImpl();
43 flights.getFlight().add(flight);
44 return flights;
45 }
46
47 public void testProperties() throws Exception {
48 Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
49 marshaller.setContextPath(CONTEXT_PATH);
50 marshaller.setMarshallerProperties(
51 Collections.singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE));
52 marshaller.afterPropertiesSet();
53 }
54
55 public void testNoContextPath() throws Exception {
56 try {
57 Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
58 marshaller.afterPropertiesSet();
59 fail("Should have thrown an IllegalArgumentException");
60 }
61 catch (IllegalArgumentException e) {
62 }
63 }
64
65 public void testInvalidContextPath() throws Exception {
66 try {
67 Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
68 marshaller.setContextPath("ab");
69 marshaller.afterPropertiesSet();
70 fail("Should have thrown an XmlMappingException");
71 }
72 catch (XmlMappingException ex) {
73 }
74 }
75
76 public void testSupports() throws Exception {
77 assertTrue("Jaxb1Marshaller does not support Flights", marshaller.supports(Flights.class));
78 assertFalse("Jaxb1Marshaller supports FlightsType", marshaller.supports(FlightsType.class));
79 }
80
81
82 }