use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.
the class WorksTest method createViewUpdateAndDeleteWork.
@Test
public void createViewUpdateAndDeleteWork() throws JSONException, InterruptedException, URISyntaxException {
showMyOrcidPage();
changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType("agr");
wExtId.setRelationship(Relationship.SELF);
wExtId.setUrl(new Url("http://test.orcid.org/" + time));
workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc4/" + this.getUser1OrcidId() + "/work/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Work gotWork = getResponse.getEntity(Work.class);
assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
assertEquals("work:citation-value", gotWork.getWorkCitation().getCitation());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
gotWork.getWorkTitle().getTitle().setContent("updated title");
//Save the original visibility
Visibility originalVisibility = gotWork.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
//Verify you cant update the visibility
gotWork.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
OrcidError error = putResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
//Set the visibility again to the initial one
gotWork.setVisibility(originalVisibility);
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
assertEquals("work:citation-value", gotAfterUpdateWork.getWorkCitation().getCitation());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.
the class MemberV2Test method testTokenWorksOnlyForTheScopeItWasIssued.
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testTokenWorksOnlyForTheScopeItWasIssued() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
List<String> scopes = getScopes(ScopePathType.FUNDING_CREATE, ScopePathType.FUNDING_UPDATE);
String accessToken = getAccessToken(scopes);
Work work1 = (Work) unmarshallFromPath("/record_2.0/samples/read_samples/work-2.0.xml", Work.class);
work1.setPutCode(null);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_v2.WorkTitle title1 = new org.orcid.jaxb.model.record_v2.WorkTitle();
title1.setTitle(new Title("Work # 1"));
work1.setWorkTitle(title1);
ExternalID wExtId1 = new ExternalID();
wExtId1.setValue("Work Id " + time);
wExtId1.setType(WorkExternalIdentifierType.AGR.value());
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getExternalIdentifier().clear();
work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
//Add the work
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), postResponse.getStatus());
Funding funding = (Funding) unmarshallFromPath("/record_2.0/samples/read_samples/funding-2.0.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID fExtId = new ExternalID();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
fExtId.setValue("Funding Id " + time);
fExtId.setRelationship(Relationship.SELF);
funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
//Add the funding
postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
// Delete funding
Map map = postResponse.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List resultWithPutCode = (List) map.get("Location");
String location = resultWithPutCode.get(0).toString();
Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.
the class ValidateV2RC3Identifiers method testActivities.
@Test
public void testActivities() {
ActivitiesSummary as = unmarshallFromPath("/record_2.0_rc3/samples/activities-2.0_rc3.xml", ActivitiesSummary.class);
ExternalIDs fundingIDs = as.getFundings().getFundingGroup().get(0).getFundingSummary().get(0).getExternalIdentifiers();
ExternalIDs fundingIDs2 = as.getFundings().getFundingGroup().get(0).getIdentifiers();
assertEquals("grant_number", fundingIDs.getExternalIdentifier().get(0).getType());
assertEquals("external-id-value", fundingIDs.getExternalIdentifier().get(0).getValue());
assertEquals(new Url("http://tempuri.org"), fundingIDs.getExternalIdentifier().get(0).getUrl());
assertEquals(Relationship.SELF, fundingIDs.getExternalIdentifier().get(0).getRelationship());
assertEquals(fundingIDs.getExternalIdentifier().get(0).getType(), fundingIDs2.getExternalIdentifier().get(0).getType());
assertEquals(fundingIDs.getExternalIdentifier().get(0).getValue(), fundingIDs2.getExternalIdentifier().get(0).getValue());
ExternalIDs peerIDs = as.getPeerReviews().getPeerReviewGroup().get(0).getPeerReviewSummary().get(0).getExternalIdentifiers();
ExternalIDs peerIDs2 = as.getPeerReviews().getPeerReviewGroup().get(0).getIdentifiers();
assertEquals("something", peerIDs.getExternalIdentifier().get(0).getType());
assertEquals("external-id-value", peerIDs.getExternalIdentifier().get(0).getValue());
assertEquals(new Url("http://orcid.org"), peerIDs.getExternalIdentifier().get(0).getUrl());
assertEquals(Relationship.SELF, peerIDs.getExternalIdentifier().get(0).getRelationship());
assertEquals(peerIDs.getExternalIdentifier().get(0).getType(), peerIDs2.getExternalIdentifier().get(0).getType());
assertEquals(peerIDs.getExternalIdentifier().get(0).getValue(), peerIDs2.getExternalIdentifier().get(0).getValue());
ExternalIDs workIDs = as.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getExternalIdentifiers();
ExternalIDs workIDs2 = as.getWorks().getWorkGroup().get(0).getIdentifiers();
assertEquals("agr", workIDs.getExternalIdentifier().get(0).getType());
assertEquals("external-id-value", workIDs.getExternalIdentifier().get(0).getValue());
assertEquals(new Url("http://orcid.org"), workIDs.getExternalIdentifier().get(0).getUrl());
assertEquals(Relationship.SELF, workIDs.getExternalIdentifier().get(0).getRelationship());
assertEquals(workIDs.getExternalIdentifier().get(0).getType(), workIDs2.getExternalIdentifier().get(0).getType());
assertEquals(workIDs.getExternalIdentifier().get(0).getValue(), workIDs2.getExternalIdentifier().get(0).getValue());
}
use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.
the class ValidateV2RC3Identifiers method testFunding.
@Test
public void testFunding() throws SAXException, IOException, JAXBException, ParserConfigurationException {
Funding funding = unmarshallFromPath("/record_2.0_rc3/samples/funding-2.0_rc3.xml", Funding.class);
assertEquals("funding:organization-defined-type", funding.getOrganizationDefinedType().getContent());
assertNotNull(funding.getExternalIdentifiers());
assertNotNull(funding.getExternalIdentifiers().getExternalIdentifier());
Assert.notEmpty(funding.getExternalIdentifiers().getExternalIdentifier());
assertEquals("grant_number", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
assertEquals("funding:external-identifier-value", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
assertEquals(new Url("http://tempuri.org"), funding.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl());
assertEquals(Relationship.SELF, funding.getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
Validator validator = getValidator("funding");
validator.validate(marshall(Funding.class, funding));
validator.validate(marshallToDOM(Funding.class, funding));
}
use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.
the class ValidateV2RC3Identifiers method testPeerReview.
/** Test both types of identifier here
*
* @throws SAXException
* @throws IOException
* @throws JAXBException
* @throws ParserConfigurationException
*/
@Test
public void testPeerReview() throws SAXException, IOException, JAXBException, ParserConfigurationException {
PeerReview peerReview = unmarshallFromPath("/record_2.0_rc3/samples/peer-review-2.0_rc3.xml", PeerReview.class);
ExternalID id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("source-work-id", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
ExternalID subjectid = peerReview.getSubjectExternalIdentifier();
assertEquals("doi", subjectid.getType());
assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
assertEquals(Relationship.SELF, subjectid.getRelationship());
Validator validator = getValidator("peer-review");
validator.validate(marshall(PeerReview.class, peerReview));
validator.validate(marshallToDOM(PeerReview.class, peerReview));
//do the full record too
peerReview = unmarshallFromPath("/record_2.0_rc3/samples/peer-review-full-2.0_rc3.xml", PeerReview.class);
id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("source-work-id", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
subjectid = peerReview.getSubjectExternalIdentifier();
assertEquals("doi", subjectid.getType());
assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
assertEquals(Relationship.SELF, subjectid.getRelationship());
}
Aggregations