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.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(
37: new ByteArrayOutputStream()));
38: fail("XmlBeansMarshaller did not throw ClassCastException for non-XmlObject");
39: } catch (ClassCastException e) {
40: // Expected behavior
41: }
42: }
43:
44: protected Object createFlights() {
45: FlightsDocument flightsDocument = FlightsDocument.Factory
46: .newInstance();
47: Flights flights = flightsDocument.addNewFlights();
48: FlightType flightType = flights.addNewFlight();
49: flightType.setNumber(42L);
50: return flightsDocument;
51: }
52:
53: public void testSupports() throws Exception {
54: assertTrue("XmlBeansMarshaller does not support XmlObject",
55: marshaller.supports(XmlObject.class));
56: assertFalse("XmlBeansMarshaller supports other objects",
57: marshaller.supports(Object.class));
58: assertTrue(
59: "XmlBeansMarshaller does not support FlightsDocument",
60: marshaller.supports(FlightsDocument.class));
61: assertTrue("XmlBeansMarshaller does not support Flights",
62: marshaller.supports(Flights.class));
63: assertTrue("XmlBeansMarshaller does not support FlightType",
64: marshaller.supports(FlightType.class));
65: }
66: }
|