use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class MarshallingTest method testMarshallingV2_0.
@Test
public void testMarshallingV2_0() throws JAXBException, IOException, SAXException {
JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.notification.permission_v2");
Unmarshaller unmarshaller = context.createUnmarshaller();
InputStream inputStream = MarshallingTest.class.getResourceAsStream(SAMPLE_PATH_V2);
org.orcid.jaxb.model.notification.permission_v2.NotificationPermission notification = (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) unmarshaller.unmarshal(inputStream);
assertNotNull(notification);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.PERMISSION, notification.getNotificationType());
assertEquals(2, notification.getItems().getItems().size());
assertEquals("2014-01-01T14:45:32", notification.getSentDate().toXMLFormat());
// Back the other way
String expected = IOUtils.toString(getClass().getResourceAsStream(SAMPLE_PATH_V2), "UTF-8");
Pattern pattern = Pattern.compile("<!--.*?-->\\s*", Pattern.DOTALL);
expected = pattern.matcher(expected).replaceAll("");
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.orcid.org/ns/notification ../notification-permission-2.0.xsd");
StringWriter writer = new StringWriter();
marshaller.marshal(notification, writer);
XMLUnit.setIgnoreWhitespace(true);
Diff diff = new Diff(expected, writer.toString());
assertTrue(diff.identical());
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class MarshallingTest method getOrcidMessage.
private OrcidMessage getOrcidMessage() throws JAXBException {
JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.message");
Unmarshaller unmarshaller = context.createUnmarshaller();
InputStream inputStream = MarshallingTest.class.getResourceAsStream("/orcid-internal-full-message-latest.xml");
return (OrcidMessage) unmarshaller.unmarshal(inputStream);
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class MarshallingTest method testUnMarshallingV2.
@Test
public void testUnMarshallingV2() throws JAXBException {
JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.notification.custom_v2");
Unmarshaller unmarshaller = context.createUnmarshaller();
InputStream inputStream = MarshallingTest.class.getResourceAsStream("/notification_2.0/samples/notification-custom-2.0.xml");
org.orcid.jaxb.model.notification.custom_v2.NotificationCustom notification = (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) unmarshaller.unmarshal(inputStream);
assertNotNull(notification);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.CUSTOM, notification.getNotificationType());
assertEquals("Important Notification from ORCID", notification.getSubject());
assertEquals("This is an email with important info.\n ", notification.getBodyText());
assertEquals("\n <p>\n This is an email with <em>important</em> info.\n </p>\n ", notification.getBodyHtml());
assertEquals("2014-01-01T14:45:32", notification.getSentDate().toXMLFormat());
assertEquals("en-gb", notification.getLang());
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class JpaJaxbEducationAdapterTest method getEducation.
private Education getEducation(boolean full) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(new Class[] { Education.class });
Unmarshaller unmarshaller = context.createUnmarshaller();
String name = "/record_2.0/samples/read_samples/education-2.0.xml";
if (full) {
name = "/record_2.0/samples/read_samples/education-full-2.0.xml";
}
InputStream inputStream = getClass().getResourceAsStream(name);
return (Education) unmarshaller.unmarshal(inputStream);
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class ConvertVrc3ToVrc4Test method upgradeAddressesToVrc3Test.
@Test
public void upgradeAddressesToVrc3Test() throws JAXBException {
JAXBContext jaxbContext1 = JAXBContext.newInstance(Addresses.class);
JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record_rc4.Addresses.class);
Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
InputStream rc3Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-addresses-2.0_rc3.xml");
InputStream rc4Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-addresses-2.0_rc4.xml");
Addresses rc4Element = (Addresses) jaxbUnmarshaller.unmarshal(rc3Stream);
jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
org.orcid.jaxb.model.record_rc4.Addresses rc4Element1 = (org.orcid.jaxb.model.record_rc4.Addresses) jaxbUnmarshaller.unmarshal(rc4Stream);
V2Convertible result = versionConverterV2_0_rc3ToV2_0_rc4.upgrade(new V2Convertible(rc4Element, "v2_rc3"));
org.orcid.jaxb.model.record_rc4.Addresses rc4Element2 = (org.orcid.jaxb.model.record_rc4.Addresses) result.getObjectToConvert();
assertEquals(rc4Element1, rc4Element2);
}
Aggregations