use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_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.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class PublicV3ApiServiceDelegatorTest method testViewBulkWorks.
@Test
public void testViewBulkWorks() {
Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13");
assertNotNull(response);
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(3, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
assertTrue(workBulk.getBulk().get(2) instanceof OrcidError);
Work work = (Work) workBulk.getBulk().get(0);
assertNotNull(work);
assertNotNull(work.getLastModifiedDate());
assertNotNull(work.getLastModifiedDate().getValue());
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("PUBLIC", work.getWorkTitle().getTitle().getContent());
assertEquals(Long.valueOf(11), work.getPutCode());
assertEquals("/0000-0000-0000-0003/work/11", work.getPath());
assertEquals(WorkType.JOURNAL_ARTICLE, work.getWorkType());
assertEquals("APP-5555555555555555", work.getSource().retrieveSourcePath());
assertNotNull(work.getWorkContributors());
assertNotNull(work.getWorkContributors().getContributor());
assertEquals(1, work.getWorkContributors().getContributor().size());
assertNotNull(work.getWorkContributors().getContributor().get(0).getContributorOrcid());
assertEquals("0000-0000-0000-0000", work.getWorkContributors().getContributor().get(0).getContributorOrcid().getPath());
assertNull(work.getWorkContributors().getContributor().get(0).getCreditName());
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class MemberV3Dev1Test method createViewUpdateAndDeleteEmployment.
@Test
public void createViewUpdateAndDeleteEmployment() throws JSONException, InterruptedException, URISyntaxException {
Employment employment = (Employment) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/employment-3.0_dev1.xml", Employment.class);
employment.setPutCode(null);
employment.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createEmploymentXml(this.getUser1OrcidId(), employment, 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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/employment/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Employment gotEmployment = getResponse.getEntity(Employment.class);
assertEquals("department-name", gotEmployment.getDepartmentName());
assertEquals("role-title", gotEmployment.getRoleTitle());
// Save the original visibility
Visibility originalVisibility = gotEmployment.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotEmployment.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotEmployment);
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
gotEmployment.setVisibility(originalVisibility);
gotEmployment.setDepartmentName("updated dept. name");
gotEmployment.setRoleTitle("updated role title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotEmployment);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Employment gotAfterUpdateEmployment = getAfterUpdateResponse.getEntity(Employment.class);
assertEquals("updated dept. name", gotAfterUpdateEmployment.getDepartmentName());
assertEquals("updated role title", gotAfterUpdateEmployment.getRoleTitle());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteEmploymentXml(this.getUser1OrcidId(), gotEmployment.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class MemberV3Dev1Test method createViewUpdateAndDeleteService.
@Test
public void createViewUpdateAndDeleteService() throws JSONException, InterruptedException, URISyntaxException {
Service service = (Service) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/service-3.0_dev1.xml", Service.class);
service.setPutCode(null);
service.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createServiceXml(this.getUser1OrcidId(), service, 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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/service/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Service gotService = getResponse.getEntity(Service.class);
assertEquals("department-name", gotService.getDepartmentName());
assertEquals("role-title", gotService.getRoleTitle());
// Save the original visibility
Visibility originalVisibility = gotService.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotService.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotService);
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
gotService.setVisibility(originalVisibility);
gotService.setDepartmentName("updated dept. name");
gotService.setRoleTitle("updated role title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotService);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Service gotAfterUpdateService = getAfterUpdateResponse.getEntity(Service.class);
assertEquals("updated dept. name", gotAfterUpdateService.getDepartmentName());
assertEquals("updated role title", gotAfterUpdateService.getRoleTitle());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteServiceXml(this.getUser1OrcidId(), gotService.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class MemberV3Dev1Test method createViewUpdateAndDeletePeerReview.
@Test
public void createViewUpdateAndDeletePeerReview() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/peer-review-3.0_dev1.xml", PeerReview.class);
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType(WorkExternalIdentifierType.AGR.value());
wExtId.setRelationship(Relationship.SELF);
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, 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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
assertEquals("peer-review:url", gotPeerReview.getUrl().getValue());
assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotPeerReview.getGroupId());
// Save the original visibility
Visibility originalVisibility = gotPeerReview.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotPeerReview.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
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
gotPeerReview.setVisibility(originalVisibility);
gotPeerReview.getSubjectName().getTitle().setContent("updated title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
PeerReview gotAfterUpdateWork = getAfterUpdateResponse.getEntity(PeerReview.class);
assertEquals("updated title", gotAfterUpdateWork.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotAfterUpdateWork.getGroupId());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdateWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations