use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceVersionedDelegatorTest method testViewBulkWorks.
@Test
public void testViewBulkWorks() {
SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,16");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
// private work but matching source
assertTrue(workBulk.getBulk().get(2) instanceof Work);
// private work not matching source
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testUpdateWorkYouAreNotTheSourceOf.
@Test(expected = WrongSourceException.class)
public void testUpdateWorkYouAreNotTheSourceOf() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewWork("4444-4444-4444-4443", 2L);
assertNotNull(response);
Work work = (Work) response.getEntity();
assertNotNull(work);
Utils.verifyLastModified(work.getLastModifiedDate());
assertEquals(Long.valueOf(2), work.getPutCode());
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("Another day in the life", work.getWorkTitle().getTitle().getContent());
assertEquals(WorkType.BOOK, work.getWorkType());
work.setWorkType(WorkType.EDITED_BOOK);
work.getWorkTitle().getTitle().setContent("Updated work title");
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.PART_OF);
extId.setType(WorkExternalIdentifierType.AGR.value());
extId.setValue("ext-id-" + System.currentTimeMillis());
extId.setUrl(new Url("http://thisIsANewUrl.com"));
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
serviceDelegator.updateWork("4444-4444-4444-4443", 2L, work);
fail();
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testViewBulkWorksWithBadPutCode.
@Test
public void testViewBulkWorksWithBadPutCode() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13,bad");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
// private work
assertTrue(workBulk.getBulk().get(2) instanceof Work);
// bad put code
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testCleanEmptyFieldsOnWorks.
@Test
public void testCleanEmptyFieldsOnWorks() {
LastModifiedDate lmd = new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(System.currentTimeMillis()));
Work work = new Work();
work.setLastModifiedDate(lmd);
work.setWorkCitation(new Citation("", CitationType.FORMATTED_UNSPECIFIED));
WorkTitle title = new WorkTitle();
title.setTitle(new Title("My Work"));
title.setSubtitle(new Subtitle("My subtitle"));
title.setTranslatedTitle(new TranslatedTitle("", ""));
work.setWorkTitle(title);
ActivityUtils.cleanEmptyFields(work);
assertNotNull(work);
Utils.verifyLastModified(work.getLastModifiedDate());
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertNotNull(work.getWorkTitle().getSubtitle());
assertEquals("My Work", work.getWorkTitle().getTitle().getContent());
assertEquals("My subtitle", work.getWorkTitle().getSubtitle().getContent());
assertNull(work.getWorkCitation());
assertNull(work.getWorkTitle().getTranslatedTitle());
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testAddWork.
@Test
public void testAddWork() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4445", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewActivities("4444-4444-4444-4445");
assertNotNull(response);
ActivitiesSummary summary = (ActivitiesSummary) response.getEntity();
assertNotNull(summary);
Utils.verifyLastModified(summary.getLastModifiedDate());
// Check works
assertNotNull(summary.getWorks());
assertNotNull(summary.getWorks().getWorkGroup());
assertEquals(1, summary.getWorks().getWorkGroup().size());
Utils.verifyLastModified(summary.getWorks().getLastModifiedDate());
assertNotNull(summary.getWorks().getWorkGroup().get(0));
Utils.verifyLastModified(summary.getWorks().getWorkGroup().get(0).getLastModifiedDate());
assertNotNull(summary.getWorks().getWorkGroup().get(0).getWorkSummary());
assertEquals(1, summary.getWorks().getWorkGroup().get(0).getWorkSummary().size());
String title = "work # 1 " + System.currentTimeMillis();
Work work = Utils.getWork(title);
response = serviceDelegator.createWork("4444-4444-4444-4445", work);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Long putCode = Utils.getPutCode(response);
response = serviceDelegator.viewActivities("4444-4444-4444-4445");
assertNotNull(response);
summary = (ActivitiesSummary) response.getEntity();
assertNotNull(summary);
Utils.verifyLastModified(summary.getLastModifiedDate());
// Check works
assertNotNull(summary.getWorks());
assertNotNull(summary.getWorks().getWorkGroup());
assertEquals(2, summary.getWorks().getWorkGroup().size());
boolean haveOld = false;
boolean haveNew = false;
for (WorkGroup group : summary.getWorks().getWorkGroup()) {
Utils.verifyLastModified(group.getLastModifiedDate());
assertNotNull(group.getWorkSummary());
assertNotNull(group.getWorkSummary().get(0));
WorkSummary workSummary = group.getWorkSummary().get(0);
Utils.verifyLastModified(workSummary.getLastModifiedDate());
assertNotNull(workSummary.getTitle());
assertNotNull(workSummary.getTitle().getTitle());
if ("A Book With Contributors JSON".equals(workSummary.getTitle().getTitle().getContent())) {
haveOld = true;
} else if (title.equals(workSummary.getTitle().getTitle().getContent())) {
haveNew = true;
}
}
assertTrue(haveOld);
assertTrue(haveNew);
// Delete them
serviceDelegator.deleteWork("4444-4444-4444-4445", putCode);
}
Aggregations