use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateNewWorkGroup.
@Test
public void testCreateNewWorkGroup() {
WorkDao mockDao = Mockito.mock(WorkDao.class);
WorkEntityCacheManager cacheManager = Mockito.mock(WorkEntityCacheManager.class);
WorkEntityCacheManager oldCacheManager = (WorkEntityCacheManager) ReflectionTestUtils.getField(workManager, "workEntityCacheManager");
ReflectionTestUtils.setField(workManager, "workDao", mockDao);
ReflectionTestUtils.setField(workManager, "workEntityCacheManager", cacheManager);
// no work where user is source
List<MinimizedWorkEntity> works = getMinimizedWorksListForGrouping();
Mockito.when(cacheManager.retrieveMinimizedWorks(Mockito.anyString(), Mockito.anyList(), Mockito.anyLong())).thenReturn(works);
// full work matching user preferred id should be loaded from db (10 is highest display index)
Mockito.when(mockDao.find(Mockito.eq(4l))).thenReturn(getUserPreferredWork());
workManager.createNewWorkGroup(Arrays.asList(1l, 2l, 3l, 4l), "some-orcid");
// as no work with user as source, new work should be created
ArgumentCaptor<WorkEntity> captor = ArgumentCaptor.forClass(WorkEntity.class);
Mockito.verify(mockDao).persist(captor.capture());
WorkEntity entity = captor.getValue();
assertEquals("{\"workExternalIdentifier\":[{\"relationship\":null,\"url\":null,\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"123\"}},{\"relationship\":null,\"url\":null,\"workExternalIdentifierType\":\"DOI\",\"workExternalIdentifierId\":{\"content\":\"doi:10.1/123\"}}]}", entity.getExternalIdentifiersJson());
assertEquals("some title", entity.getTitle());
assertEquals("some subtitle", entity.getSubtitle());
// now test where user is source of one work
works = getMinimizedWorksListForGrouping();
MinimizedWorkEntity userSource = works.get(0);
userSource.setSourceId("some-orcid");
Mockito.when(cacheManager.retrieveMinimizedWorks(Mockito.anyString(), Mockito.anyList(), Mockito.anyLong())).thenReturn(works);
// full work matching user preferred id should be loaded from db (10 is highest display index)
Mockito.when(mockDao.find(Mockito.eq(4l))).thenReturn(getUserPreferredWork());
workManager.createNewWorkGroup(Arrays.asList(1l, 2l, 3l, 4l), "some-orcid");
// no new work should be created
Mockito.verify(mockDao, Mockito.times(1)).persist(Mockito.any(WorkEntity.class));
assertEquals("{\"workExternalIdentifier\":[{\"relationship\":null,\"url\":null,\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"123\"}},{\"relationship\":null,\"url\":null,\"workExternalIdentifierType\":\"DOI\",\"workExternalIdentifierId\":{\"content\":\"doi:10.1/123\"}}]}", userSource.getExternalIdentifiersJson());
// only identifiers should have been updated
assertEquals("work:title", userSource.getTitle());
assertEquals("work:subtitle", userSource.getSubtitle());
// reset dao
ReflectionTestUtils.setField(workManager, "workDao", workDao);
ReflectionTestUtils.setField(workManager, "workEntityCacheManager", oldCacheManager);
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerTest method testAddMultipleModifiesIndexingStatus.
@Test
public void testAddMultipleModifiesIndexingStatus() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Work w1 = getWork("extId1");
w1 = workManager.createWork(claimedOrcid, w1, true);
Work w2 = getWork("extId2");
w2 = workManager.createWork(claimedOrcid, w2, true);
Work w3 = getWork("extId3");
w3 = workManager.createWork(claimedOrcid, w3, true);
WorkEntity entity1 = workDao.find(w1.getPutCode());
WorkEntity entity2 = workDao.find(w2.getPutCode());
WorkEntity entity3 = workDao.find(w3.getPutCode());
assertNotNull(entity1.getDisplayIndex());
assertNotNull(entity2.getDisplayIndex());
assertNotNull(entity3.getDisplayIndex());
assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
// Rollback all changes
workDao.remove(entity1.getId());
workDao.remove(entity2.getId());
workDao.remove(entity3.getId());
}
Aggregations