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