Search in sources :

Example 46 with Membership

use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.

the class AffiliationsManagerTest method testAddMembershipToUnclaimedRecordPreserveMembershipVisibility.

@Test
public void testAddMembershipToUnclaimedRecordPreserveMembershipVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Membership element = getMembership();
    element = affiliationsManager.createMembershipAffiliation(unclaimedOrcid, element, true);
    element = affiliationsManager.getMembershipAffiliation(unclaimedOrcid, element.getPutCode());
    assertNotNull(element);
    assertEquals(Visibility.PUBLIC, element.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 47 with Membership

use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.

the class AffiliationsManagerTest method getMembership.

private Membership getMembership() {
    Membership element = new Membership();
    fillAffiliation(element);
    return element;
}
Also used : Membership(org.orcid.jaxb.model.v3.dev1.record.Membership)

Example 48 with Membership

use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.

the class ActivityUtilsTest method setPathToMembershipsTest.

@Test
public void setPathToMembershipsTest() {
    Memberships x = getMemberships();
    ActivityUtils.setPathToAffiliations(x, ORCID);
    assertEquals("/" + ORCID + "/membership/123", x.getSummaries().get(0).getPath());
}
Also used : Memberships(org.orcid.jaxb.model.v3.dev1.record.summary.Memberships) Test(org.junit.Test)

Example 49 with Membership

use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method testUpdateMembershipWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdateMembershipWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    Membership membership = (Membership) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/membership-3.0_dev1.xml", Membership.class);
    membership.setPutCode(null);
    membership.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createMembershipXml(this.getUser1OrcidId(), membership, 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() + "/membership/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Membership gotMembership = getResponse.getEntity(Membership.class);
    assertEquals("department-name", gotMembership.getDepartmentName());
    assertEquals("role-title", gotMembership.getRoleTitle());
    gotMembership.setDepartmentName("updated dept. name");
    gotMembership.setRoleTitle("updated role title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotMembership);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Membership gotAfterUpdateMembership = getAfterUpdateResponse.getEntity(Membership.class);
    assertEquals("department-name", gotAfterUpdateMembership.getDepartmentName());
    assertEquals("role-title", gotAfterUpdateMembership.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteMembershipXml(this.getUser1OrcidId(), gotMembership.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Test(org.junit.Test)

Example 50 with Membership

use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method createViewUpdateAndDeleteMembership.

@Test
public void createViewUpdateAndDeleteMembership() throws JSONException, InterruptedException, URISyntaxException {
    Membership membership = (Membership) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/membership-3.0_dev1.xml", Membership.class);
    membership.setPutCode(null);
    membership.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createMembershipXml(this.getUser1OrcidId(), membership, 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() + "/membership/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Membership gotMembership = getResponse.getEntity(Membership.class);
    assertEquals("department-name", gotMembership.getDepartmentName());
    assertEquals("role-title", gotMembership.getRoleTitle());
    // Save the original visibility
    Visibility originalVisibility = gotMembership.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotMembership.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotMembership);
    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
    gotMembership.setVisibility(originalVisibility);
    gotMembership.setDepartmentName("updated dept. name");
    gotMembership.setRoleTitle("updated role title");
    putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotMembership);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Membership gotAfterUpdateMembership = getAfterUpdateResponse.getEntity(Membership.class);
    assertEquals("updated dept. name", gotAfterUpdateMembership.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateMembership.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteMembershipXml(this.getUser1OrcidId(), gotMembership.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Aggregations

Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)41 Test (org.junit.Test)31 DBUnitTest (org.orcid.test.DBUnitTest)18 Response (javax.ws.rs.core.Response)17 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)11 Education (org.orcid.jaxb.model.v3.dev1.record.Education)11 Service (org.orcid.jaxb.model.v3.dev1.record.Service)11 Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)10 InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)10 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)10 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)8 MembershipSummary (org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary)7 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)5 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)5 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Url (org.orcid.jaxb.model.v3.dev1.common.Url)4 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4