Search in sources :

Example 56 with WorkEntity

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);
}
Also used : WorkDao(org.orcid.persistence.dao.WorkDao) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) WorkEntityCacheManager(org.orcid.core.manager.WorkEntityCacheManager) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 57 with WorkEntity

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)57 Test (org.junit.Test)22 MinimizedWorkEntity (org.orcid.persistence.jpa.entities.MinimizedWorkEntity)20 Date (java.util.Date)15 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 Work (org.orcid.jaxb.model.v3.dev1.record.Work)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Work (org.orcid.jaxb.model.record_v2.Work)9 ArrayList (java.util.ArrayList)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 BaseTest (org.orcid.core.BaseTest)7 ExceedMaxNumberOfElementsException (org.orcid.core.exception.ExceedMaxNumberOfElementsException)6 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)6 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 PublicationDateEntity (org.orcid.persistence.jpa.entities.PublicationDateEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)5 HashMap (java.util.HashMap)4 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)4 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)4