Search in sources :

Example 16 with OrgDisambiguatedExternalIdentifierEntity

use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.

the class LoadRinggoldDataTest method test_EmptyDB.

@Test
public void test_EmptyDB() throws URISyntaxException {
    when(mockOrgDisambiguatedDao.findBySourceIdAndSourceType(anyString(), eq("RINGGOLD"))).thenReturn(null);
    when(mockOrgDao.findByNameCityRegionAndCountry(anyString(), anyString(), anyString(), any())).thenReturn(null);
    Path path = Paths.get(getClass().getClassLoader().getResource("ringgold/test_base/").toURI());
    File testDirectory = path.toFile();
    assertTrue(testDirectory.exists());
    loader.setDirectory(testDirectory);
    loader.execute();
    ArgumentCaptor<OrgDisambiguatedEntity> orgDisambiguatedEntityCaptor = ArgumentCaptor.forClass(OrgDisambiguatedEntity.class);
    verify(mockOrgDisambiguatedDao, times(0)).merge(any());
    verify(mockOrgDisambiguatedDao, times(4)).persist(orgDisambiguatedEntityCaptor.capture());
    List<OrgDisambiguatedEntity> newOrgDisambiguatedEntities = orgDisambiguatedEntityCaptor.getAllValues();
    assertEquals(4, newOrgDisambiguatedEntities.size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false;
    for (OrgDisambiguatedEntity entity : newOrgDisambiguatedEntities) {
        assertEquals(IndexingStatus.PENDING, entity.getIndexingStatus());
        assertEquals("RINGGOLD", entity.getSourceType());
        switch(entity.getSourceId()) {
            case "1":
                assertNull(entity.getSourceParentId());
                assertEquals("1. Name", entity.getName());
                assertEquals("City#1", entity.getCity());
                assertEquals("State#1", entity.getRegion());
                assertEquals(Iso3166Country.US, entity.getCountry());
                assertEquals("type/1", entity.getOrgType());
                found1 = true;
                break;
            case "2":
                assertNull(entity.getSourceParentId());
                assertEquals("2. Name", entity.getName());
                assertEquals("City#2", entity.getCity());
                assertNull(entity.getRegion());
                assertEquals(Iso3166Country.CR, entity.getCountry());
                assertEquals("type/2", entity.getOrgType());
                found2 = true;
                break;
            case "3":
                assertNull(entity.getSourceParentId());
                assertEquals("3. Name", entity.getName());
                assertEquals("City#3", entity.getCity());
                assertNull(entity.getRegion());
                assertEquals(Iso3166Country.US, entity.getCountry());
                assertEquals("type/3", entity.getOrgType());
                found3 = true;
                break;
            case "4":
                assertEquals("1", entity.getSourceParentId());
                assertEquals("4. Name", entity.getName());
                assertEquals("City#4", entity.getCity());
                assertEquals("State#4", entity.getRegion());
                assertEquals(Iso3166Country.CR, entity.getCountry());
                assertEquals("type/4", entity.getOrgType());
                found4 = true;
                break;
            default:
                fail("Invalid ringgold id found: " + entity.getSourceId());
                break;
        }
    }
    ;
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    ArgumentCaptor<OrgDisambiguatedExternalIdentifierEntity> orgDisambiguatedExaternalIdentifierEntityCaptor = ArgumentCaptor.forClass(OrgDisambiguatedExternalIdentifierEntity.class);
    verify(mockOrgDisambiguatedExternalIdentifierDao, times(0)).merge(any());
    verify(mockOrgDisambiguatedExternalIdentifierDao, times(0)).remove(anyLong());
    verify(mockOrgDisambiguatedExternalIdentifierDao, times(8)).persist(orgDisambiguatedExaternalIdentifierEntityCaptor.capture());
    List<OrgDisambiguatedExternalIdentifierEntity> extIds = orgDisambiguatedExaternalIdentifierEntityCaptor.getAllValues();
    assertEquals(8, extIds.size());
    found1 = found2 = found3 = found4 = false;
    boolean found5 = false, found6 = false, found7 = false, found8 = false;
    for (OrgDisambiguatedExternalIdentifierEntity entity : extIds) {
        switch(entity.getIdentifier()) {
            case "1":
                assertEquals("1", entity.getOrgDisambiguated().getSourceId());
                assertEquals("ISNI", entity.getIdentifierType());
                assertEquals("1", entity.getIdentifier());
                found1 = true;
                break;
            case "2":
                assertEquals("1", entity.getOrgDisambiguated().getSourceId());
                assertEquals("IPED", entity.getIdentifierType());
                assertEquals("2", entity.getIdentifier());
                found2 = true;
                break;
            case "3":
                assertEquals("2", entity.getOrgDisambiguated().getSourceId());
                assertEquals("NCES", entity.getIdentifierType());
                assertEquals("3", entity.getIdentifier());
                found3 = true;
                break;
            case "4":
                assertEquals("2", entity.getOrgDisambiguated().getSourceId());
                assertEquals("OFR", entity.getIdentifierType());
                assertEquals("4", entity.getIdentifier());
                found4 = true;
                break;
            case "5":
                assertEquals("3", entity.getOrgDisambiguated().getSourceId());
                assertEquals("ISNI", entity.getIdentifierType());
                assertEquals("5", entity.getIdentifier());
                found5 = true;
                break;
            case "6":
                assertEquals("3", entity.getOrgDisambiguated().getSourceId());
                assertEquals("IPED", entity.getIdentifierType());
                assertEquals("6", entity.getIdentifier());
                found6 = true;
                break;
            case "7":
                assertEquals("4", entity.getOrgDisambiguated().getSourceId());
                assertEquals("NCES", entity.getIdentifierType());
                assertEquals("7", entity.getIdentifier());
                found7 = true;
                break;
            case "8":
                assertEquals("4", entity.getOrgDisambiguated().getSourceId());
                assertEquals("OFR", entity.getIdentifierType());
                assertEquals("8", entity.getIdentifier());
                found8 = true;
                break;
            default:
                fail("Invalid ext id found: " + entity.getIdentifier());
                break;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertTrue(found5);
    assertTrue(found6);
    assertTrue(found7);
    assertTrue(found8);
    ArgumentCaptor<OrgEntity> orgEntityCaptor = ArgumentCaptor.forClass(OrgEntity.class);
    verify(mockOrgDao, times(0)).merge(any());
    verify(mockOrgDao, times(2)).persist(orgEntityCaptor.capture());
    List<OrgEntity> orgs = orgEntityCaptor.getAllValues();
    assertEquals(2, orgs.size());
    found1 = found2 = false;
    for (OrgEntity entity : orgs) {
        switch(entity.getName()) {
            case "1. Alt Name":
                assertEquals("1", entity.getOrgDisambiguated().getSourceId());
                assertEquals("AltCity#1", entity.getCity());
                assertEquals(Iso3166Country.MX, entity.getCountry());
                found1 = true;
                break;
            case "2. Alt Name":
                assertEquals("2", entity.getOrgDisambiguated().getSourceId());
                assertEquals("AltCity#2", entity.getCity());
                assertEquals(Iso3166Country.BR, entity.getCountry());
                found2 = true;
                break;
            default:
                fail("Invalid org found: " + entity.getName());
                break;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
}
Also used : Path(java.nio.file.Path) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) File(java.io.File) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Test(org.junit.Test)

Aggregations

OrgDisambiguatedExternalIdentifierEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity)16 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)9 File (java.io.File)8 Path (java.nio.file.Path)8 Test (org.junit.Test)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Date (java.util.Date)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Transactional (javax.transaction.Transactional)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1