Search in sources :

Example 81 with JAXBContext

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

the class Api12MembersTest method testViewBioDetails.

@Test
public void testViewBioDetails() throws Exception {
    JAXBContext context = JAXBContext.newInstance(OrcidMessage.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    OrcidMessage record = (OrcidMessage) unmarshaller.unmarshal(Api12MembersTest.class.getResourceAsStream("/samples/small_orcid_profile.xml"));
    record.getOrcidProfile().setOrcidHistory(null);
    String emailAddress = System.currentTimeMillis() + "_test@test.orcid.org";
    Email email = new Email(emailAddress);
    email.setPrimary(true);
    List<Email> emails = Arrays.asList(email);
    record.getOrcidProfile().getOrcidBio().getContactDetails().setEmail(emails);
    String accessToken = getClientCredentialsAccessToken(ScopePathType.ORCID_PROFILE_CREATE, this.getClient1ClientId(), this.getClient1ClientSecret(), APIRequestType.MEMBER);
    String orcid = Api12Helper.createRecord(accessToken, record, t2OAuthClient_1_2);
    assertClientResponse401Details(t2OAuthClient_1_2.viewBioDetailsXml(orcid, null));
    ClientResponse clientResponse = t2OAuthClient_1_2.viewBioDetailsXml(orcid, accessToken);
    assertNotNull(clientResponse);
    assertEquals(200, clientResponse.getStatus());
    assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", clientResponse.getType().toString());
    OrcidMessage orcidMessage = clientResponse.getEntity(OrcidMessage.class);
    assertNotNull(orcidMessage);
    assertEquals(orcid, orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath());
    assertNotNull(orcidMessage.getOrcidProfile().getOrcidBio());
    assertEquals(1, orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().size());
    assertEquals(emailAddress, orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().get(0).getValue());
    assertEquals(Iso3166Country.CR, orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
    assertEquals("credit", orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getContent());
    assertEquals("family", orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().getContent());
    assertEquals("given", orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().getContent());
    assertEquals(1, orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
    assertEquals("other", orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
    assertEquals("biography", orcidMessage.getOrcidProfile().getOrcidBio().getBiography().getContent());
    assertEquals(1, orcidMessage.getOrcidProfile().getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://www.site.com", orcidMessage.getOrcidProfile().getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
    assertEquals("The site", orcidMessage.getOrcidProfile().getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
    assertEquals(1, orcidMessage.getOrcidProfile().getOrcidBio().getKeywords().getKeyword().size());
    assertEquals("K1", orcidMessage.getOrcidProfile().getOrcidBio().getKeywords().getKeyword().get(0).getContent());
    assertEquals(1, orcidMessage.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals("extId#1", orcidMessage.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("extId#1", orcidMessage.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
    assertEquals("http://orcid.org/extId#1", orcidMessage.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Email(org.orcid.jaxb.model.message.Email) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 82 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_v2.NotificationPermission) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 83 with JAXBContext

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

the class ValidateV2IdentifiersTest method unmarshall.

private Object unmarshall(Reader reader, Class<?> type) {
    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return 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) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 84 with JAXBContext

use of javax.xml.bind.JAXBContext 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);
}
Also used : InputStream(java.io.InputStream) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 85 with JAXBContext

use of javax.xml.bind.JAXBContext 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());
}
Also used : InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

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