Search in sources :

Example 1 with FlightType

use of org.springframework.oxm.jaxb.test.FlightType in project spring-framework by spring-projects.

the class Jaxb2MarshallerTests method testSupports.

private void testSupports() throws Exception {
    assertTrue("Jaxb2Marshaller does not support Flights class", marshaller.supports(Flights.class));
    assertTrue("Jaxb2Marshaller does not support Flights generic type", marshaller.supports((Type) Flights.class));
    assertFalse("Jaxb2Marshaller supports FlightType class", marshaller.supports(FlightType.class));
    assertFalse("Jaxb2Marshaller supports FlightType type", marshaller.supports((Type) FlightType.class));
    Method method = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
    assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>", marshaller.supports(method.getGenericReturnType()));
    marshaller.setSupportJaxbElementClass(true);
    JAXBElement<FlightType> flightTypeJAXBElement = new JAXBElement<>(new QName("http://springframework.org", "flight"), FlightType.class, new FlightType());
    assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>", marshaller.supports(flightTypeJAXBElement.getClass()));
    assertFalse("Jaxb2Marshaller supports class not in context path", marshaller.supports(DummyRootElement.class));
    assertFalse("Jaxb2Marshaller supports type not in context path", marshaller.supports((Type) DummyRootElement.class));
    method = getClass().getDeclaredMethod("createDummyRootElement");
    assertFalse("Jaxb2Marshaller supports JAXBElement not in context path", marshaller.supports(method.getGenericReturnType()));
    assertFalse("Jaxb2Marshaller supports class not in context path", marshaller.supports(DummyType.class));
    assertFalse("Jaxb2Marshaller supports type not in context path", marshaller.supports((Type) DummyType.class));
    method = getClass().getDeclaredMethod("createDummyType");
    assertFalse("Jaxb2Marshaller supports JAXBElement not in context path", marshaller.supports(method.getGenericReturnType()));
    testSupportsPrimitives();
    testSupportsStandardClasses();
}
Also used : Type(java.lang.reflect.Type) FlightType(org.springframework.oxm.jaxb.test.FlightType) XmlType(javax.xml.bind.annotation.XmlType) Flights(org.springframework.oxm.jaxb.test.Flights) QName(javax.xml.namespace.QName) FlightType(org.springframework.oxm.jaxb.test.FlightType) Method(java.lang.reflect.Method) JAXBElement(javax.xml.bind.JAXBElement)

Example 2 with FlightType

use of org.springframework.oxm.jaxb.test.FlightType in project spring-framework by spring-projects.

the class Jaxb2UnmarshallerTests method testFlight.

@Override
protected void testFlight(Object o) {
    FlightType flight = (FlightType) o;
    assertNotNull("Flight is null", flight);
    assertEquals("Number is invalid", 42L, flight.getNumber());
}
Also used : FlightType(org.springframework.oxm.jaxb.test.FlightType)

Example 3 with FlightType

use of org.springframework.oxm.jaxb.test.FlightType in project spring-framework by spring-projects.

the class Jaxb2MarshallerTests method createFlights.

@Override
protected Object createFlights() {
    FlightType flight = new FlightType();
    flight.setNumber(42L);
    flights = new Flights();
    flights.getFlight().add(flight);
    return flights;
}
Also used : Flights(org.springframework.oxm.jaxb.test.Flights) FlightType(org.springframework.oxm.jaxb.test.FlightType)

Example 4 with FlightType

use of org.springframework.oxm.jaxb.test.FlightType in project spring-framework by spring-projects.

the class Jaxb2UnmarshallerTests method unmarshalPartialStaxSourceXmlStreamReader.

@Test
@Override
@SuppressWarnings("unchecked")
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
    // skip to flights
    streamReader.nextTag();
    // skip to flight
    streamReader.nextTag();
    Source source = StaxUtils.createStaxSource(streamReader);
    JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
    FlightType flight = element.getValue();
    testFlight(flight);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) FlightType(org.springframework.oxm.jaxb.test.FlightType) JAXBElement(javax.xml.bind.JAXBElement) XMLInputFactory(javax.xml.stream.XMLInputFactory) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) FileDataSource(javax.activation.FileDataSource) Test(org.junit.Test)

Aggregations

FlightType (org.springframework.oxm.jaxb.test.FlightType)4 JAXBElement (javax.xml.bind.JAXBElement)2 Flights (org.springframework.oxm.jaxb.test.Flights)2 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 FileDataSource (javax.activation.FileDataSource)1 XmlType (javax.xml.bind.annotation.XmlType)1 QName (javax.xml.namespace.QName)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Test (org.junit.Test)1