use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class VerifyOrcidBeforeFetchElementTest method testFunding.
@Test
public void testFunding() throws InterruptedException, JSONException, URISyntaxException {
long time = System.currentTimeMillis();
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);
String user1AccessToken = getAccessToken();
// Create an funding
ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), funding, user1AccessToken);
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_rc1/" + getUser1OrcidId() + "/funding/\\d+"));
// Fetch it with the owner
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Funding gotFunding = getResponse.getEntity(Funding.class);
assertEquals("common:title", gotFunding.getTitle().getTitle().getContent());
assertEquals("common:translated-title", gotFunding.getTitle().getTranslatedTitle().getContent());
// Try to fetch it with other user orcid
// Using the members API
String user2AccessToken = getAccessToken(getUser2OrcidId(), getUser2Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
ClientResponse user2GetResponse = memberV2ApiClient.viewFundingXml(getUser2OrcidId(), gotFunding.getPutCode(), user2AccessToken);
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
OrcidError error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Using the public API
user2GetResponse = publicV2ApiClient.viewFundingXml(getUser2OrcidId(), String.valueOf(gotFunding.getPutCode()));
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Delete it
ClientResponse deletedResponse = memberV2ApiClient.deleteFundingXml(getUser1OrcidId(), gotFunding.getPutCode(), user1AccessToken);
assertNotNull(deletedResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deletedResponse.getStatus());
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class MemberV2ApiServiceVersionedDelegatorTest method testViewBulkWorksWithBadPutCode.
@Test
public void testViewBulkWorksWithBadPutCode() {
SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,bad");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
// private work
assertTrue(workBulk.getBulk().get(2) instanceof Work);
// bad put code
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class MemberV2ApiServiceVersionedDelegatorTest method testViewBulkWorks.
@Test
public void testViewBulkWorks() {
SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,16");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
// private work but matching source
assertTrue(workBulk.getBulk().get(2) instanceof Work);
// private work not matching source
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testViewBulkWorksWithBadPutCode.
@Test
public void testViewBulkWorksWithBadPutCode() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13,bad");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
// private work
assertTrue(workBulk.getBulk().get(2) instanceof Work);
// bad put code
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.
the class WorksTest method testCantAddMoreThan1000WorksAtATime.
@Test
public void testCantAddMoreThan1000WorksAtATime() throws InterruptedException, JSONException {
String accessToken = getAccessToken();
WorkBulk bulk = createBulk(1001, null);
ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
OrcidError error = postResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9006), error.getErrorCode());
}
Aggregations