use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class MemberV3Dev1Test method createViewUpdateAndDeleteEducation.
@Test
public void createViewUpdateAndDeleteEducation() throws JSONException, InterruptedException, URISyntaxException {
Education education = (Education) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/education-3.0_dev1.xml", Education.class);
education.setPutCode(null);
education.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createEducationXml(this.getUser1OrcidId(), education, 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() + "/education/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Education gotEducation = getResponse.getEntity(Education.class);
assertEquals("department-name", gotEducation.getDepartmentName());
assertEquals("role-title", gotEducation.getRoleTitle());
// Save the original visibility
Visibility originalVisibility = gotEducation.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotEducation.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
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
gotEducation.setVisibility(originalVisibility);
gotEducation.setDepartmentName("updated dept. name");
gotEducation.setRoleTitle("updated role title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Education gotAfterUpdateEducation = getAfterUpdateResponse.getEntity(Education.class);
assertEquals("updated dept. name", gotAfterUpdateEducation.getDepartmentName());
assertEquals("updated role title", gotAfterUpdateEducation.getRoleTitle());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteEducationXml(this.getUser1OrcidId(), gotEducation.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 createViewUpdateAndDeleteDistinction.
@Test
public void createViewUpdateAndDeleteDistinction() throws JSONException, InterruptedException, URISyntaxException {
Distinction distinction = (Distinction) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/distinction-3.0_dev1.xml", Distinction.class);
distinction.setPutCode(null);
distinction.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createDistinctionXml(this.getUser1OrcidId(), distinction, 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() + "/distinction/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Distinction gotDistinction = getResponse.getEntity(Distinction.class);
assertEquals("department-name", gotDistinction.getDepartmentName());
assertEquals("role-title", gotDistinction.getRoleTitle());
// Save the original visibility
Visibility originalVisibility = gotDistinction.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotDistinction.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotDistinction);
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
gotDistinction.setVisibility(originalVisibility);
gotDistinction.setDepartmentName("updated dept. name");
gotDistinction.setRoleTitle("updated role title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotDistinction);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Distinction gotAfterUpdateDistinction = getAfterUpdateResponse.getEntity(Distinction.class);
assertEquals("updated dept. name", gotAfterUpdateDistinction.getDepartmentName());
assertEquals("updated role title", gotAfterUpdateDistinction.getRoleTitle());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteDistinctionXml(this.getUser1OrcidId(), gotDistinction.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 createViewUpdateAndDeleteQualification.
@Test
public void createViewUpdateAndDeleteQualification() throws JSONException, InterruptedException, URISyntaxException {
Qualification qualification = (Qualification) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/qualification-3.0_dev1.xml", Qualification.class);
qualification.setPutCode(null);
qualification.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createQualificationXml(this.getUser1OrcidId(), qualification, 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() + "/qualification/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Qualification gotQualification = getResponse.getEntity(Qualification.class);
assertEquals("department-name", gotQualification.getDepartmentName());
assertEquals("role-title", gotQualification.getRoleTitle());
// Save the original visibility
Visibility originalVisibility = gotQualification.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotQualification.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotQualification);
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
gotQualification.setVisibility(originalVisibility);
gotQualification.setDepartmentName("updated dept. name");
gotQualification.setRoleTitle("updated role title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotQualification);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Qualification gotAfterUpdateQualification = getAfterUpdateResponse.getEntity(Qualification.class);
assertEquals("updated dept. name", gotAfterUpdateQualification.getDepartmentName());
assertEquals("updated role title", gotAfterUpdateQualification.getRoleTitle());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteQualificationXml(this.getUser1OrcidId(), gotQualification.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 WorksTest method createViewUpdateAndDeleteWorkWithLegacyUpdateScope.
@Test
public void createViewUpdateAndDeleteWorkWithLegacyUpdateScope() throws JSONException, InterruptedException, URISyntaxException {
showMyOrcidPage();
changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC.name());
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.setSource(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(getScopes(ScopePathType.ORCID_WORKS_UPDATE));
ClientResponse postResponse = memberV3Dev1ApiClient.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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/work/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClient.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", 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 = memberV3Dev1ApiClient.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 = memberV3Dev1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClient.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", gotAfterUpdateWork.getWorkCitation().getCitation());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.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 WorksTest method testCantAddMoreThan1000WorksAtATime.
@Test
public void testCantAddMoreThan1000WorksAtATime() throws InterruptedException, JSONException {
String accessToken = getAccessToken();
WorkBulk bulk = createBulk(1001, null);
ClientResponse postResponse = memberV3Dev1ApiClient.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