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());
}
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);
}
}
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);
}
}
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);
}
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());
}
Aggregations