use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_MembershipsTest method testUpdateMembership.
@Test
public void testUpdateMembership() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewMembership(ORCID, 39L);
assertNotNull(response);
Membership membership = (Membership) response.getEntity();
assertNotNull(membership);
assertEquals("PRIVATE Department", membership.getDepartmentName());
assertEquals("PRIVATE", membership.getRoleTitle());
Utils.verifyLastModified(membership.getLastModifiedDate());
LastModifiedDate before = membership.getLastModifiedDate();
membership.setDepartmentName("Updated department name");
membership.setRoleTitle("The updated role title");
// disambiguated org is required in API v3
DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
disambiguatedOrg.setDisambiguatedOrganizationIdentifier("abc456");
disambiguatedOrg.setDisambiguationSource("WDB");
membership.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
response = serviceDelegator.updateMembership(ORCID, 39L, membership);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
response = serviceDelegator.viewMembership(ORCID, 39L);
assertNotNull(response);
membership = (Membership) response.getEntity();
assertNotNull(membership);
Utils.verifyLastModified(membership.getLastModifiedDate());
assertTrue(membership.getLastModifiedDate().after(before));
assertEquals("Updated department name", membership.getDepartmentName());
assertEquals("The updated role title", membership.getRoleTitle());
// Rollback changes
membership.setDepartmentName("PRIVATE Department");
membership.setRoleTitle("PRIVATE");
response = serviceDelegator.updateMembership(ORCID, 39L, membership);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_MembershipsTest method testAddMembership.
@Test
public void testAddMembership() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewActivities(ORCID);
assertNotNull(response);
ActivitiesSummary originalSummary = (ActivitiesSummary) response.getEntity();
assertNotNull(originalSummary);
Utils.verifyLastModified(originalSummary.getLastModifiedDate());
assertNotNull(originalSummary.getMemberships());
Utils.verifyLastModified(originalSummary.getMemberships().getLastModifiedDate());
assertNotNull(originalSummary.getMemberships().getSummaries());
assertNotNull(originalSummary.getMemberships().getSummaries().get(0));
Utils.verifyLastModified(originalSummary.getMemberships().getSummaries().get(0).getLastModifiedDate());
assertEquals(4, originalSummary.getMemberships().getSummaries().size());
response = serviceDelegator.createMembership(ORCID, (Membership) Utils.getAffiliation(AffiliationType.MEMBERSHIP));
assertNotNull(response);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Map<?, ?> map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List<?> resultWithPutCode = (List<?>) map.get("Location");
Long putCode = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
response = serviceDelegator.viewActivities(ORCID);
assertNotNull(response);
ActivitiesSummary summaryWithNewElement = (ActivitiesSummary) response.getEntity();
assertNotNull(summaryWithNewElement);
Utils.verifyLastModified(summaryWithNewElement.getLastModifiedDate());
assertNotNull(summaryWithNewElement.getMemberships());
Utils.verifyLastModified(summaryWithNewElement.getMemberships().getLastModifiedDate());
assertNotNull(summaryWithNewElement.getMemberships().getSummaries());
assertEquals(5, summaryWithNewElement.getMemberships().getSummaries().size());
boolean haveNew = false;
for (MembershipSummary membershipSummary : summaryWithNewElement.getMemberships().getSummaries()) {
assertNotNull(membershipSummary.getPutCode());
Utils.verifyLastModified(membershipSummary.getLastModifiedDate());
if (membershipSummary.getPutCode().equals(putCode)) {
assertEquals("My department name", membershipSummary.getDepartmentName());
haveNew = true;
} else {
assertTrue(originalSummary.getMemberships().getSummaries().contains(membershipSummary));
}
}
assertTrue(haveNew);
// Remove new element
serviceDelegator.deleteAffiliation(ORCID, putCode);
}
use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_MembershipsTest method testUpdateMembershipDuplicateExternalIDs.
@Test(expected = OrcidDuplicatedActivityException.class)
public void testUpdateMembershipDuplicateExternalIDs() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
ExternalID e1 = new ExternalID();
e1.setRelationship(Relationship.SELF);
e1.setType("erm");
e1.setUrl(new Url("https://orcid.org"));
e1.setValue("err");
ExternalID e2 = new ExternalID();
e2.setRelationship(Relationship.SELF);
e2.setType("err");
e2.setUrl(new Url("http://bbc.co.uk"));
e2.setValue("erm");
ExternalIDs externalIDs = new ExternalIDs();
externalIDs.getExternalIdentifier().add(e1);
externalIDs.getExternalIdentifier().add(e2);
Membership membership = (Membership) Utils.getAffiliation(AffiliationType.MEMBERSHIP);
membership.setExternalIDs(externalIDs);
Response response = serviceDelegator.createMembership(ORCID, membership);
assertNotNull(response);
assertEquals(HttpStatus.SC_CREATED, response.getStatus());
Map<?, ?> map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List<?> resultWithPutCode = (List<?>) map.get("Location");
Long putCode1 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
Membership another = (Membership) Utils.getAffiliation(AffiliationType.MEMBERSHIP);
response = serviceDelegator.createMembership(ORCID, another);
map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
resultWithPutCode = (List<?>) map.get("Location");
Long putCode2 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
response = serviceDelegator.viewMembership(ORCID, putCode2);
another = (Membership) response.getEntity();
another.setExternalIDs(externalIDs);
try {
serviceDelegator.updateMembership(ORCID, putCode2, another);
} finally {
serviceDelegator.deleteAffiliation(ORCID, putCode1);
serviceDelegator.deleteAffiliation(ORCID, putCode2);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_MembershipsTest method testViewLimitedMembership.
@Test
public void testViewLimitedMembership() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewMembership(ORCID, 40L);
assertNotNull(response);
Membership membership = (Membership) response.getEntity();
assertNotNull(membership);
Utils.verifyLastModified(membership.getLastModifiedDate());
assertEquals(Long.valueOf(40L), membership.getPutCode());
assertEquals("/0000-0000-0000-0003/membership/40", membership.getPath());
assertEquals("SELF LIMITED Department", membership.getDepartmentName());
assertEquals(Visibility.LIMITED.value(), membership.getVisibility().value());
}
use of org.orcid.jaxb.model.v3.dev1.record.Membership in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_MembershipsTest method testUpdateMembershipLeavingVisibilityNullTest.
@Test
public void testUpdateMembershipLeavingVisibilityNullTest() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewMembership(ORCID, 37L);
assertNotNull(response);
Membership membership = (Membership) response.getEntity();
assertNotNull(membership);
assertEquals(Visibility.PUBLIC, membership.getVisibility());
membership.setVisibility(null);
response = serviceDelegator.updateMembership(ORCID, 37L, membership);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
membership = (Membership) response.getEntity();
assertNotNull(membership);
assertEquals(Visibility.PUBLIC, membership.getVisibility());
}
Aggregations