use of eu.etaxonomy.cdm.model.taxon.Synonym in project cdmlib by cybertaxonomy.
the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon.
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testDeleteSynonym.xml")
public final // test delete synonym, only for a special taxon, but because of other relationships it will not be deleted at all
void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon() {
final String[] tableNames = {// "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
// "HomotypicalGroup","HomotypicalGroup_AUD"
};
int nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
int nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 4 names in the database", 4, nNames);
UUID uuidTaxon2 = UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
Taxon taxon2 = (Taxon) service.load(uuidTaxon2);
Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
synonym1.setSec(ReferenceFactory.newArticle());
taxon2.addSynonym(synonym1, SynonymType.HETEROTYPIC_SYNONYM_OF());
service.saveOrUpdate(synonym1);
long nRelations = service.countSynonyms(true);
// this was "3" when we still had synonym relationships
Assert.assertEquals("There should be 2 relationship left in the database", 2, nRelations);
service.deleteSynonym(synonym1, new SynonymDeletionConfigurator());
this.commitAndStartNewTransaction(tableNames);
nSynonyms = service.count(Synonym.class);
// this was "2" when we still had synonym relationships
Assert.assertEquals("There should still be 1 synonym left in the database", 1, nSynonyms);
nNames = nameService.count(TaxonName.class);
// was 3
Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
nRelations = service.countSynonyms(true);
Assert.assertEquals("There should be 1 related synonym left in the database", 1, nRelations);
}
use of eu.etaxonomy.cdm.model.taxon.Synonym in project cdmlib by cybertaxonomy.
the class TaxonServiceImplTest method testGetHeterotypicSynonymyGroups.
@Test
public final void testGetHeterotypicSynonymyGroups() {
Rank rank = Rank.SPECIES();
Reference ref1 = ReferenceFactory.newGeneric();
// HomotypicalGroup group = HomotypicalGroup.NewInstance();
Taxon taxon1 = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test3", null, null, null, null, null, null, null), null);
Synonym synonym0 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test2", null, null, null, null, null, null, null), null);
Synonym synonym1 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test2", null, null, null, null, null, null, null), null);
Synonym synonym2 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test4", null, null, null, null, null, null, null), null);
synonym0.getName().setHomotypicalGroup(taxon1.getHomotypicGroup());
synonym2.getName().setHomotypicalGroup(synonym1.getHomotypicGroup());
// tax2.addHeterotypicSynonymName(synonym.getName());
taxon1.addSynonym(synonym1, SynonymType.HETEROTYPIC_SYNONYM_OF());
taxon1.addSynonym(synonym2, SynonymType.HETEROTYPIC_SYNONYM_OF());
service.save(synonym1);
service.save(synonym2);
service.save(taxon1);
List<List<Synonym>> heteroSyns = service.getHeterotypicSynonymyGroups(taxon1, null);
Assert.assertEquals("There should be 1 heterotypic group", 1, heteroSyns.size());
List<Synonym> synList = heteroSyns.get(0);
Assert.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList.size());
// test sec
synonym2.setSec(ref1);
heteroSyns = service.getHeterotypicSynonymyGroups(taxon1, null);
Assert.assertEquals("There should be 1 heterotypic group", 1, heteroSyns.size());
synList = heteroSyns.get(0);
Assert.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList.size());
}
use of eu.etaxonomy.cdm.model.taxon.Synonym in project cdmlib by cybertaxonomy.
the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations.
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testDeleteSynonym.xml")
public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations() {
final String[] tableNames = { "TaxonBase", "TaxonBase_AUD", "TaxonName", "TaxonName_AUD", "HomotypicalGroup", "HomotypicalGroup_AUD" };
int nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
int nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 4 names in the database", 4, nNames);
UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
UUID uuidSynonymName2 = UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
TaxonName name2 = nameService.load(uuidSynonymName2);
UUID name3Uuid = synonym1.getName().getUuid();
TaxonName name3 = nameService.load(name3Uuid);
name3.addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
service.saveOrUpdate(synonym1);
long nRelations = nameService.listNameRelationships(null, 1000, 0, null, null).size();
logger.info("number of name relations: " + nRelations);
Assert.assertEquals("There should be 1 name relationship left in the database", 1, nRelations);
SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
NameDeletionConfigurator nameDeletionConfig = new NameDeletionConfigurator();
nameDeletionConfig.setRemoveAllNameRelationships(true);
config.setNameDeletionConfig(nameDeletionConfig);
service.deleteSynonym(synonym1, config);
this.commitAndStartNewTransaction(tableNames);
nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms);
nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 3 names left in the database ", 3, nNames);
nRelations = service.countSynonyms(true);
// may change with better implementation of countAllRelationships (see #2653)
nRelations = nameService.listNameRelationships(null, 1000, 0, null, null).size();
logger.info("number of name relations: " + nRelations);
Assert.assertEquals("There should be no name relationship left in the database", 0, nRelations);
}
use of eu.etaxonomy.cdm.model.taxon.Synonym in project cdmlib by cybertaxonomy.
the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonBooleanWithRollback.
@Test
@DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
public final void testDeleteSynonymSynonymTaxonBooleanWithRollback() {
// final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
// "HomotypicalGroup","HomotypicalGroup_AUD"};
int nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
int nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 4 names in the database", 4, nNames);
long nRelations = service.countSynonyms(true);
// may change with better implementation of countAllRelationships (see #2653)
logger.debug("");
Assert.assertEquals("There should be 2 relationships in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);
UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
UUID uuidSynonymName2 = UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
TaxonName name2 = nameService.load(uuidSynonymName2);
synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
service.deleteSynonym(synonym1, new SynonymDeletionConfigurator());
this.rollback();
// printDataSet(System.out, tableNames);
this.startNewTransaction();
nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms);
nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 4 names left in the database", 4, nNames);
nRelations = service.countSynonyms(true);
// may change with better implementation of countAllRelationships (see #2653)
Assert.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);
}
use of eu.etaxonomy.cdm.model.taxon.Synonym in project cdmlib by cybertaxonomy.
the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonDontDeleteName.
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testDeleteSynonym.xml")
public final // test delete synonym, but the name will not be deleted
void testDeleteSynonymSynonymTaxonDontDeleteName() {
final String[] tableNames = {// "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
// "HomotypicalGroup","HomotypicalGroup_AUD"
};
int nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
int nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 4 names in the database", 4, nNames);
long nRelations = service.countSynonyms(true);
Assert.assertEquals("There should be two relationship left in the database", 2, nRelations);
UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
config.setDeleteNameIfPossible(false);
config.setNewHomotypicGroupIfNeeded(true);
service.deleteSynonym(synonym1, config);
this.commitAndStartNewTransaction(tableNames);
nSynonyms = service.count(Synonym.class);
Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);
nNames = nameService.count(TaxonName.class);
Assert.assertEquals("There should be 4 names left in the database", 4, nNames);
nRelations = service.countSynonyms(true);
Assert.assertEquals("There should be no relationship left in the database", 1, nRelations);
}
Aggregations