Search in sources :

Example 61 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class ConvertVrc4ToV2Test method upgradeEmploymentsToVrc3Test.

@Test
public void upgradeEmploymentsToVrc3Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(Employments.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_v2.Employments.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
    InputStream rc3Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-employments-2.0_rc4.xml");
    InputStream rc4Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-employments-2.0.xml");
    Employments rc4Employments = (Employments) jaxbUnmarshaller.unmarshal(rc3Stream);
    jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
    org.orcid.jaxb.model.record.summary_v2.Employments rc4Employments1 = (org.orcid.jaxb.model.record.summary_v2.Employments) jaxbUnmarshaller.unmarshal(rc4Stream);
    V2Convertible result = versionConverterV2_0_rc4ToV2_0.upgrade(new V2Convertible(rc4Employments, "v2_rc4"));
    org.orcid.jaxb.model.record.summary_v2.Employments rc4Employments2 = (org.orcid.jaxb.model.record.summary_v2.Employments) result.getObjectToConvert();
    assertEquals(rc4Employments1, rc4Employments2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Employments(org.orcid.jaxb.model.record.summary_rc4.Employments) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 62 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class ConvertVrc4ToV2Test method upgradeActivitiesToVrc3Test.

@Test
public void upgradeActivitiesToVrc3Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(ActivitiesSummary.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary.class);
    Unmarshaller jaxbUnmarshaller1 = jaxbContext1.createUnmarshaller();
    Unmarshaller jaxbUnmarshaller2 = jaxbContext2.createUnmarshaller();
    InputStream rc3Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-activities-2.0_rc4.xml");
    InputStream rc4Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-activities-2.0.xml");
    ActivitiesSummary rc3Activities = (ActivitiesSummary) jaxbUnmarshaller1.unmarshal(rc3Stream);
    org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary rc4Activities1 = (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) jaxbUnmarshaller2.unmarshal(rc4Stream);
    V2Convertible result = versionConverterV2_0_rc4ToV2_0.upgrade(new V2Convertible(rc3Activities, "v2_rc4"));
    org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary rc4Activities2 = (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) result.getObjectToConvert();
    assertEquals(rc4Activities1, rc4Activities2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 63 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class ConvertVrc4ToV2Test method upgradeWorksToVrc3Test.

@Test
public void upgradeWorksToVrc3Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(Works.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_v2.Works.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
    InputStream rc3Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-works-2.0_rc4.xml");
    InputStream rc4Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-works-2.0.xml");
    Works rc4Works = (Works) jaxbUnmarshaller.unmarshal(rc3Stream);
    jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
    org.orcid.jaxb.model.record.summary_v2.Works rc4Works1 = (org.orcid.jaxb.model.record.summary_v2.Works) jaxbUnmarshaller.unmarshal(rc4Stream);
    V2Convertible result = versionConverterV2_0_rc4ToV2_0.upgrade(new V2Convertible(rc4Works, "v2_rc4"));
    org.orcid.jaxb.model.record.summary_v2.Works rc4Works2 = (org.orcid.jaxb.model.record.summary_v2.Works) result.getObjectToConvert();
    assertEquals(rc4Works1, rc4Works2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Works(org.orcid.jaxb.model.record.summary_rc4.Works) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 64 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class ConvertVrc4ToV2Test method upgradeGroupIdToVrc3Test.

@Test
public void upgradeGroupIdToVrc3Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(GroupIdRecords.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.groupid_v2.GroupIdRecords.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
    InputStream rc3Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-group-id-2.0_rc4.xml");
    InputStream rc4Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-group-id-2.0.xml");
    GroupIdRecords rc4Group = (GroupIdRecords) jaxbUnmarshaller.unmarshal(rc3Stream);
    jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
    org.orcid.jaxb.model.groupid_v2.GroupIdRecords rc4GroupId1 = (org.orcid.jaxb.model.groupid_v2.GroupIdRecords) jaxbUnmarshaller.unmarshal(rc4Stream);
    V2Convertible result = versionConverterV2_0_rc4ToV2_0.upgrade(new V2Convertible(rc4Group, "v2_rc4"));
    org.orcid.jaxb.model.groupid_v2.GroupIdRecords rc4GroupId2 = (org.orcid.jaxb.model.groupid_v2.GroupIdRecords) result.getObjectToConvert();
    assertEquals(rc4GroupId1, rc4GroupId2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) GroupIdRecords(org.orcid.jaxb.model.groupid_rc4.GroupIdRecords) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 65 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class NotificationsTest method unmarshall.

public NotificationPermission unmarshall(Reader reader) {
    try {
        JAXBContext context = JAXBContext.newInstance(NotificationPermission.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (NotificationPermission) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)1150 Unmarshaller (javax.xml.bind.Unmarshaller)558 Marshaller (javax.xml.bind.Marshaller)371 JAXBException (javax.xml.bind.JAXBException)330 Test (org.junit.Test)226 File (java.io.File)161 InputStream (java.io.InputStream)150 StringWriter (java.io.StringWriter)138 IOException (java.io.IOException)105 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 StringReader (java.io.StringReader)74 StreamSource (javax.xml.transform.stream.StreamSource)73 JAXBElement (javax.xml.bind.JAXBElement)72 ArrayList (java.util.ArrayList)58 URL (java.net.URL)55 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Schema (javax.xml.validation.Schema)48 SchemaFactory (javax.xml.validation.SchemaFactory)48 OutputStream (java.io.OutputStream)42 BaseTest (org.orcid.core.BaseTest)39