use of org.orcid.jaxb.model.common_rc3.Title 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_rc1/samples/work-2.0_rc1.xml", Work.class);
work1.setPutCode(null);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc1.WorkTitle title1 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title1.setTitle(new Title("Work # 1"));
work1.setWorkTitle(title1);
WorkExternalIdentifier wExtId1 = new WorkExternalIdentifier();
wExtId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getWorkExternalIdentifier().clear();
work1.getExternalIdentifiers().getWorkExternalIdentifier().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_rc1/samples/funding-2.0_rc1.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
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_rc3.Title 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_rc2/samples/work-2.0_rc2.xml", Work.class);
work1.setPutCode(null);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc2.WorkTitle title1 = new org.orcid.jaxb.model.record_rc2.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_rc2/samples/funding-2.0_rc2.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());
}
Aggregations