Search in sources :

Example 1 with Flights

use of org.springframework.oxm.jaxb.test.Flights 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 Flights

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

the class Jaxb2UnmarshallerTests method testFlights.

@Override
protected void testFlights(Object o) {
    Flights flights = (Flights) o;
    assertNotNull("Flights is null", flights);
    assertEquals("Invalid amount of flight elements", 1, flights.getFlight().size());
    testFlight(flights.getFlight().get(0));
}
Also used : Flights(org.springframework.oxm.jaxb.test.Flights)

Example 3 with Flights

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

the class Jaxb2UnmarshallerTests method unmarshalFile.

@Test
public void unmarshalFile() throws IOException {
    Resource resource = new ClassPathResource("jaxb2.xml", getClass());
    File file = resource.getFile();
    Flights f = (Flights) unmarshaller.unmarshal(new StreamSource(file));
    testFlights(f);
}
Also used : Flights(org.springframework.oxm.jaxb.test.Flights) StreamSource(javax.xml.transform.stream.StreamSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 4 with Flights

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

the class Jaxb2MarshallerTests method marshalInvalidClass.

@Test(expected = XmlMappingException.class)
public void marshalInvalidClass() throws Exception {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(FlightType.class);
    marshaller.afterPropertiesSet();
    Result result = new StreamResult(new StringWriter());
    Flights flights = new Flights();
    marshaller.marshal(flights, result);
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) Flights(org.springframework.oxm.jaxb.test.Flights) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) SAXResult(javax.xml.transform.sax.SAXResult) Test(org.junit.Test)

Example 5 with Flights

use of org.springframework.oxm.jaxb.test.Flights 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)

Aggregations

Flights (org.springframework.oxm.jaxb.test.Flights)5 Test (org.junit.Test)2 FlightType (org.springframework.oxm.jaxb.test.FlightType)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 JAXBElement (javax.xml.bind.JAXBElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 QName (javax.xml.namespace.QName)1 Result (javax.xml.transform.Result)1 SAXResult (javax.xml.transform.sax.SAXResult)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1