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());
}
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;
}
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());
}
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());
}
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());
}
Aggregations