Search in sources :

Example 31 with Education

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) Education(org.orcid.jaxb.model.record_rc1.Education) Visibility(org.orcid.jaxb.model.common_rc1.Visibility) Test(org.junit.Test)

Example 32 with Education

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Education(org.orcid.jaxb.model.record_v2.Education) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 33 with Education

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Education(org.orcid.jaxb.model.record_v2.Education) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 34 with Education

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;
}
Also used : Education(org.orcid.jaxb.model.record_v2.Education)

Example 35 with 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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Education(org.orcid.jaxb.model.record_rc1.Education) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)42 Education (org.orcid.jaxb.model.record_v2.Education)42 ClientResponse (com.sun.jersey.api.client.ClientResponse)22 Response (javax.ws.rs.core.Response)13 DBUnitTest (org.orcid.test.DBUnitTest)13 Funding (org.orcid.jaxb.model.record_v2.Funding)8 Work (org.orcid.jaxb.model.record_v2.Work)8 Education (org.orcid.jaxb.model.record_rc1.Education)7 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 ArrayList (java.util.ArrayList)6 OtherName (org.orcid.jaxb.model.record_v2.OtherName)5 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)5 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)4 Education (org.orcid.jaxb.model.record_rc2.Education)4 Education (org.orcid.jaxb.model.record_rc3.Education)4 Education (org.orcid.jaxb.model.record_rc4.Education)4 Employment (org.orcid.jaxb.model.record_v2.Employment)4 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)4