use of org.orcid.jaxb.model.record_rc3.Education in project ORCID-Source by ORCID.
the class MemberV2Test method createViewUpdateAndDeleteEducation.
@Test
public void createViewUpdateAndDeleteEducation() throws JSONException, InterruptedException, URISyntaxException {
Education education = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
education.setPutCode(null);
education.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.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(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/education/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Education gotEducation = getResponse.getEntity(Education.class);
assertEquals("education:department-name", gotEducation.getDepartmentName());
assertEquals("education:role-title", gotEducation.getRoleTitle());
gotEducation.setDepartmentName("updated dept. name");
gotEducation.setRoleTitle("updated role title");
// 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 = memberV2ApiClient.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);
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.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 = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), gotEducation.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc3.Education in project ORCID-Source by ORCID.
the class SourceInActivitiesTest method sourceDoesntChange_Affiliation_Test.
@Test
public void sourceDoesntChange_Affiliation_Test() {
when(mockSourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
Education education1 = getEducation(userOrcid);
assertNotNull(education1);
assertEquals(userOrcid, education1.retrieveSourcePath());
when(mockSourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Education education2 = getEducation(userOrcid);
assertNotNull(education2);
assertEquals(CLIENT_1_ID, education2.retrieveSourcePath());
when(mockSourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
Education education3 = getEducation(userOrcid);
assertNotNull(education3);
assertEquals(CLIENT_2_ID, education3.retrieveSourcePath());
when(mockSourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
Education education4 = getEducation(userOrcid);
assertNotNull(education4);
assertEquals(userOrcid, education4.retrieveSourcePath());
Education fromDb1 = affiliationsManager.getEducationAffiliation(userOrcid, education1.getPutCode());
assertNotNull(fromDb1);
assertEquals(userOrcid, fromDb1.retrieveSourcePath());
Education fromDb2 = affiliationsManager.getEducationAffiliation(userOrcid, education2.getPutCode());
assertNotNull(fromDb2);
assertEquals(CLIENT_1_ID, fromDb2.retrieveSourcePath());
Education fromDb3 = affiliationsManager.getEducationAffiliation(userOrcid, education3.getPutCode());
assertNotNull(fromDb3);
assertEquals(CLIENT_2_ID, fromDb3.retrieveSourcePath());
Education fromDb4 = affiliationsManager.getEducationAffiliation(userOrcid, education4.getPutCode());
assertNotNull(fromDb4);
assertEquals(userOrcid, fromDb4.retrieveSourcePath());
}
use of org.orcid.jaxb.model.record_rc3.Education in project ORCID-Source by ORCID.
the class AffiliationsManagerTest method testAddEducationToClaimedRecordPreserveUserDefaultVisibility.
@Test
public void testAddEducationToClaimedRecordPreserveUserDefaultVisibility() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Education education = getEducation();
education = affiliationsManager.createEducationAffiliation(claimedOrcid, education, true);
education = affiliationsManager.getEducationAffiliation(claimedOrcid, education.getPutCode());
assertNotNull(education);
assertEquals(Visibility.LIMITED, education.getVisibility());
}
use of org.orcid.jaxb.model.record_rc3.Education in project ORCID-Source by ORCID.
the class Utils method getEducation.
public static Education getEducation() {
Education education = new Education();
education.setDepartmentName("My department name");
education.setRoleTitle("My Role");
education.setOrganization(getOrganization());
return education;
}
use of org.orcid.jaxb.model.record_rc3.Education in project ORCID-Source by ORCID.
the class MemberV2Test method testUpdateEducationWithProfileCreationTokenWhenClaimedAndNotSource.
@Test
public void testUpdateEducationWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
Education education = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
education.setPutCode(null);
education.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.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(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/education/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Education gotEducation = getResponse.getEntity(Education.class);
assertEquals("education:department-name", gotEducation.getDepartmentName());
assertEquals("education:role-title", gotEducation.getRoleTitle());
gotEducation.setDepartmentName("updated dept. name");
gotEducation.setRoleTitle("updated role title");
String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotEducation);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Education gotAfterUpdateEducation = getAfterUpdateResponse.getEntity(Education.class);
assertEquals("education:department-name", gotAfterUpdateEducation.getDepartmentName());
assertEquals("education:role-title", gotAfterUpdateEducation.getRoleTitle());
ClientResponse deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), gotEducation.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations