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);
}
Aggregations