01: /*
02: * Copyright 2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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.setContextPath(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(Collections.singletonMap(
51: javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT,
52: Boolean.TRUE));
53: marshaller.afterPropertiesSet();
54: }
55:
56: public void testNoContextPath() throws Exception {
57: try {
58: Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
59: marshaller.afterPropertiesSet();
60: fail("Should have thrown an IllegalArgumentException");
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: } catch (XmlMappingException ex) {
72: }
73: }
74:
75: public void testSupports() throws Exception {
76: assertTrue("Jaxb1Marshaller does not support Flights",
77: marshaller.supports(Flights.class));
78: assertFalse("Jaxb1Marshaller supports FlightsType", marshaller
79: .supports(FlightsType.class));
80: }
81:
82: }
|