use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateService.
@Test
public void testUpdateService() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
assertEquals("PUBLIC Department", service.getDepartmentName());
assertEquals("PUBLIC", service.getRoleTitle());
Utils.verifyLastModified(service.getLastModifiedDate());
LastModifiedDate before = service.getLastModifiedDate();
service.setDepartmentName("Updated department name");
service.setRoleTitle("The updated role title");
// disambiguated org is required in API v3
DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
disambiguatedOrg.setDisambiguatedOrganizationIdentifier("abc456");
disambiguatedOrg.setDisambiguationSource("WDB");
service.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
response = serviceDelegator.updateService(ORCID, 47L, service);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
service = (Service) response.getEntity();
assertNotNull(service);
Utils.verifyLastModified(service.getLastModifiedDate());
assertTrue(service.getLastModifiedDate().after(before));
assertEquals("Updated department name", service.getDepartmentName());
assertEquals("The updated role title", service.getRoleTitle());
// Rollback changes
service.setDepartmentName("PUBLIC Department");
service.setRoleTitle("PUBLIC");
response = serviceDelegator.updateService(ORCID, 47L, service);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateServiceLeavingVisibilityNullTest.
@Test
public void testUpdateServiceLeavingVisibilityNullTest() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
assertEquals(Visibility.PUBLIC, service.getVisibility());
service.setVisibility(null);
response = serviceDelegator.updateService(ORCID, 47L, service);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
service = (Service) response.getEntity();
assertNotNull(service);
assertEquals(Visibility.PUBLIC, service.getVisibility());
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateServiceChangingVisibilityTest.
@Test(expected = VisibilityMismatchException.class)
public void testUpdateServiceChangingVisibilityTest() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
assertEquals(Visibility.PUBLIC, service.getVisibility());
service.setVisibility(Visibility.PRIVATE);
response = serviceDelegator.updateService(ORCID, 47L, service);
fail();
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testDeleteService.
@Test
public void testDeleteService() {
SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0002", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewService("0000-0000-0000-0002", 1006L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
response = serviceDelegator.deleteAffiliation("0000-0000-0000-0002", 1006L);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
try {
serviceDelegator.viewService("0000-0000-0000-0002", 1006L);
fail();
} catch (NoResultException nre) {
} catch (Exception e) {
fail();
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testAddServicesDuplicateExternalIDs.
@Test(expected = OrcidDuplicatedActivityException.class)
public void testAddServicesDuplicateExternalIDs() {
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);
Service service = (Service) Utils.getAffiliation(AffiliationType.SERVICE);
service.setExternalIDs(externalIDs);
Response response = serviceDelegator.createService(ORCID, service);
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 putCode = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
try {
Service duplicate = (Service) Utils.getAffiliation(AffiliationType.SERVICE);
duplicate.setExternalIDs(externalIDs);
serviceDelegator.createService(ORCID, duplicate);
} finally {
serviceDelegator.deleteAffiliation(ORCID, putCode);
}
}
Aggregations