ref #9322 remove invalid designation relationship from cdmlib
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / service / TaxonServiceImplTest.java
index b693b2c552effac2e2fb230c45c018d597668f28..6c85eb3f8d2c4de27e92b45b4281a0b8b91eb50e 100644 (file)
@@ -28,38 +28,47 @@ import org.junit.Test;
 import org.unitils.dbunit.annotation.DataSet;
 import org.unitils.spring.annotation.SpringBeanByType;
 
+import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
 import eu.etaxonomy.cdm.api.service.config.IncludedTaxonConfiguration;
+import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator;
 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
 import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.dto.IncludedTaxaDTO;
 import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
+import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.common.Marker;
 import eu.etaxonomy.cdm.model.common.MarkerType;
-import eu.etaxonomy.cdm.model.common.OriginalSourceType;
 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.description.TextData;
-import eu.etaxonomy.cdm.model.name.BotanicalName;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
+import eu.etaxonomy.cdm.model.name.IBotanicalName;
+import eu.etaxonomy.cdm.model.name.INonViralName;
 import eu.etaxonomy.cdm.model.name.NameRelationship;
 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
-import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 import eu.etaxonomy.cdm.model.name.Rank;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
+import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
+import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
 import eu.etaxonomy.cdm.model.taxon.Classification;
@@ -77,8 +86,6 @@ import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
 /**
  * @author a.mueller
  */
-
-
 public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     private static final Logger logger = Logger.getLogger(TaxonServiceImplTest.class);
 
@@ -149,6 +156,29 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         assertEquals(expectedTaxon, actualTaxon);
     }
 
+    /**
+     * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
+     */
+    @Test
+    public final void testGetTaxonByTitle() {
+        TaxonName name = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Abies", null, "alba", null, null, null, null, null);
+        Taxon expectedTaxon = Taxon.NewInstance(name, null);
+        expectedTaxon.setDoubtful(true);
+        TaxonBase taxon = service.save(expectedTaxon);
+        IdentifiableServiceConfiguratorImpl<TaxonBase> config = new IdentifiableServiceConfiguratorImpl<TaxonBase>();
+        config.setTitleSearchString("Abies alba*");
+        //doubtful taxa should be found
+        Pager<TaxonBase> actualTaxa = service.findByTitle(config);
+        assertEquals(expectedTaxon, actualTaxa.getRecords().get(0));
+
+        //and other taxa as well
+        expectedTaxon.setDoubtful(false);
+        service.saveOrUpdate(expectedTaxon);
+        actualTaxa = service.findByTitle(config);
+        assertEquals(expectedTaxon, actualTaxa.getRecords().get(0));
+    }
+
+
     /**
      * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
      */
@@ -167,19 +197,62 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         TaxonBase<?> actualTaxon = service.find(uuid);
         assertEquals(expectedTaxon, actualTaxon);
 
-        actualTaxon.setName(BotanicalName.NewInstance(Rank.SPECIES()));
+        actualTaxon.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
         try{
             service.saveOrUpdate(actualTaxon);
         }catch(Exception e){
             Assert.fail();
         }
     }
+
+    @Test
+    public final void testSaveOrUpdateTaxonWithMisappliedName() {
+        Taxon expectedTaxon = Taxon.NewInstance(null, null);
+        TaxonName misappliedNameName = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Abies", null, "alba", null, null, null, null, null);
+
+        UUID misappliedNameNameUuid = nameService.save(misappliedNameName).getUuid();
+        misappliedNameName = nameService.find(misappliedNameNameUuid);
+        SpecimenTypeDesignation typedes = SpecimenTypeDesignation.NewInstance();
+        DerivedUnit derivedUnit = DerivedUnit.NewPreservedSpecimenInstance();
+        FieldUnit fieldUnit = FieldUnit.NewInstance();
+        DerivationEvent derivationEvent = DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
+//        derivedUnit.addDerivationEvent(derivationEvent);
+        typedes.setTypeSpecimen(derivedUnit);
+        misappliedNameName.addTypeDesignation(typedes, false);
+        Taxon misappliedName = Taxon.NewInstance(misappliedNameName, null);
+        UUID misappliedNameUuid = service.save(misappliedName).getUuid();
+        misappliedName = (Taxon) service.find(misappliedNameUuid);
+        expectedTaxon.addMisappliedName(misappliedName, null, null);
+        UUID uuid = service.save(expectedTaxon).getUuid();
+        TaxonBase<?> actualTaxon = service.find(uuid);
+        assertEquals(expectedTaxon, actualTaxon);
+        misappliedName.setSec(ReferenceFactory.newArticle());
+
+        try{
+            service.saveOrUpdate(actualTaxon);
+            misappliedName = (Taxon)service.find(misappliedNameUuid);
+            Assert.assertNotNull(misappliedName.getSec());
+        }catch(Exception e){
+            Assert.fail();
+        }
+        commitAndStartNewTransaction(null);
+        actualTaxon = service.find(uuid);
+        ((Taxon)actualTaxon).getTaxonRelations(misappliedName).iterator().next().getFromTaxon().setSec(null);
+        try{
+            service.saveOrUpdate(actualTaxon);
+            misappliedName = (Taxon)service.find(misappliedNameUuid);
+            Assert.assertNull(misappliedName.getSec());
+        }catch(Exception e){
+            Assert.fail();
+        }
+    }
+
     /**
      * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#removeTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
      */
     @Test
     public final void testRemoveTaxon() {
-        Taxon taxon = Taxon.NewInstance(BotanicalName.NewInstance(Rank.UNKNOWN_RANK()), null);
+        Taxon taxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.UNKNOWN_RANK()), null);
         UUID uuid = service.save(taxon).getUuid();
        // try {
                        service.deleteTaxon(taxon.getUuid(), null, null);
@@ -201,20 +274,25 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
                        e.printStackTrace();
                }
 
-        service.swapSynonymAndAcceptedTaxon(synonym, taxWithSyn);
+        UpdateResult result = service.swapSynonymAndAcceptedTaxon(synonym, taxWithSyn, true);
 
         // find forces flush
-        Taxon tax = (Taxon)service.find(uuidTaxWithSyn);
-        tax.removeSynonym(synonym);
-        tax.addHomotypicSynonym(synonym);
-        service.saveOrUpdate(tax);
-        TaxonBase<?> syn = service.find(uuidSyn);
+        Taxon tax = (Taxon)service.find(result.getCdmEntity().getUuid());
+        MatchingTaxonConfigurator configurator = MatchingTaxonConfigurator.NewInstance();
+        configurator.setTaxonNameTitle("Test3");
+        List<TaxonBase> synList = service.findTaxaByName(configurator);
+        HomotypicalGroup groupTest2 = null;
+        if (synList.size() > 0){
+            TaxonBase syn = synList.get(0);
+            groupTest2 = syn.getHomotypicGroup();
+            assertTrue(tax.getSynonyms().contains(syn));
+        }else{
+            Assert.fail("There should be a synonym with name Test3");
+        }
 
         assertTrue(tax.getName().getTitleCache().equals("Test2"));
 
-        HomotypicalGroup groupTest = tax.getHomotypicGroup();
-        HomotypicalGroup groupTest2 = syn.getHomotypicGroup();
-        assertEquals(groupTest, groupTest2);
+
 
     }
 
@@ -229,8 +307,9 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
         Taxon taxon = null;
+        UpdateResult result = new UpdateResult();
         try {
-            taxon = service.changeSynonymToAcceptedTaxon(synonym, taxWithSyn, true);
+            result = service.changeSynonymToAcceptedTaxon(synonym, taxWithSyn, true);
         } catch (HomotypicalGroupChangeException e) {
             Assert.fail("Invocation of change method should not throw an exception");
         }
@@ -238,12 +317,12 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         //test flush (resave deleted object)
         TaxonBase<?> syn = service.find(uuidSyn);
         taxWithSyn = (Taxon)service.find(uuidTaxWithSyn);
-        Taxon taxNew = (Taxon)service.find(taxon.getUuid());
+        Taxon taxNew = (Taxon)service.find(result.getCdmEntity().getUuid());
         assertNull(syn);
         assertNotNull(taxWithSyn);
         assertNotNull(taxNew);
 
-        Assert.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon.getSynonyms().size());
+        Assert.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, ((Taxon)result.getCdmEntity()).getSynonyms().size());
     }
 
 
@@ -259,8 +338,9 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
         Taxon taxon = null;
+        UpdateResult result = new UpdateResult();
         try {
-            taxon = service.changeSynonymToAcceptedTaxon(synonym, taxWithSyn, true);
+            result = service.changeSynonymToAcceptedTaxon(synonym, taxWithSyn, true);
             service.save(taxon);
         } catch (HomotypicalGroupChangeException e) {
             Assert.fail("Invocation of change method should not throw an exception");
@@ -271,7 +351,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         //test flush (resave deleted object)
         TaxonBase<?> syn = service.find(uuidSyn);
         taxWithSyn = (Taxon)service.find(uuidTaxWithSyn);
-        Taxon taxNew = (Taxon)service.find(taxon.getUuid());
+        Taxon taxNew = (Taxon)service.find(((Taxon)result.getCdmEntity()).getUuid());
         assertNull(syn);
         assertNotNull(taxWithSyn);
         assertNotNull(taxNew);
@@ -288,11 +368,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Reference reference = ReferenceFactory.newGeneric();
         String referenceDetail = "test";
 
-        NonViralName<?> t1n = NonViralName.NewInstance(null);
+        INonViralName t1n = TaxonNameFactory.NewNonViralInstance(null);
         Taxon t1 = Taxon.NewInstance(t1n, reference);
-        NonViralName<?> t2n = NonViralName.NewInstance(null);
+        INonViralName t2n = TaxonNameFactory.NewNonViralInstance(null);
         Taxon t2 = Taxon.NewInstance(t2n, reference);
-        NonViralName<?> s1n = NonViralName.NewInstance(null);
+        INonViralName s1n = TaxonNameFactory.NewNonViralInstance(null);
         Synonym s1 = Synonym.NewInstance(s1n, reference);
         t1.addSynonym(s1, heteroTypicSynonymType);
         service.saveOrUpdate(t1);
@@ -445,7 +525,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         oldTaxon = heterotypicSynonym.getAcceptedTaxon();
         Assert.assertEquals("Detail should be ref1", ref1, heterotypicSynonym.getSec());
         Assert.assertEquals("Detail should be 'rel3'", "rel3", heterotypicSynonym.getSecMicroReference());
-        TaxonNameBase<?,?> oldSynName3 = heterotypicSynonym.getName();
+        TaxonName oldSynName3 = heterotypicSynonym.getName();
 
         Synonym heterotypicSynonym4 = (Synonym)service.load(uuidSyn4);
         Assert.assertNotNull("Synonym should exist", heterotypicSynonym4);
@@ -467,7 +547,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Assert.assertNotNull("Synonym should still exist", heterotypicSynonym);
         Assert.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym.getAcceptedTaxon());
         Assert.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon, heterotypicSynonym.getAcceptedTaxon());
-        TaxonNameBase<?,?> synName3 = heterotypicSynonym.getName();
+        TaxonName synName3 = heterotypicSynonym.getName();
 
         heterotypicSynonym = (Synonym)service.load(uuidSyn4);
         Assert.assertNotNull("Synonym should still exist", heterotypicSynonym);
@@ -475,7 +555,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Assert.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon, heterotypicSynonym.getAcceptedTaxon());
         Assert.assertNull("Old citation should be removed", heterotypicSynonym.getSec());
         Assert.assertNull("Old detail should be removed", heterotypicSynonym.getSecMicroReference());
-        TaxonNameBase<?,?> synName4 = heterotypicSynonym.getName();
+        TaxonName synName4 = heterotypicSynonym.getName();
         Assert.assertEquals("Homotypic group of both synonyms should be equal", synName3.getHomotypicalGroup() , synName4.getHomotypicalGroup() );
         Assert.assertSame("Homotypic group of both synonyms should be same", synName3.getHomotypicalGroup() , synName4.getHomotypicalGroup() );
         Assert.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3.getHomotypicalGroup() , synName3.getHomotypicalGroup() );
@@ -522,10 +602,10 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Rank rank = Rank.SPECIES();
         Reference ref1 = ReferenceFactory.newGeneric();
         //HomotypicalGroup group = HomotypicalGroup.NewInstance();
-        Taxon taxon1 = Taxon.NewInstance(BotanicalName.NewInstance(rank, "Test3", null, null, null, null, null, null, null), null);
-        Synonym synonym0 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test2", null, null, null, null, null, null, null), null);
-        Synonym synonym1 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test2", null, null, null, null, null, null, null), null);
-        Synonym synonym2 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test4", null, null, null, null, null, null, null), null);
+        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());
@@ -556,10 +636,10 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Rank rank = Rank.SPECIES();
         Reference ref1 = ReferenceFactory.newGeneric();
         //HomotypicalGroup group = HomotypicalGroup.NewInstance();
-        Taxon taxon1 = Taxon.NewInstance(BotanicalName.NewInstance(rank, "Test3", null, null, null, null, null, null, null), null);
-        Synonym synonym0 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test2", null, null, null, null, null, null, null), null);
-        Synonym synonym1 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test2", null, null, null, null, null, null, null), null);
-        Synonym synonym2 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test4", null, null, null, null, null, null, null), null);
+        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());
@@ -587,15 +667,15 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     //test delete synonym, but the name will not be deleted
     public final void testDeleteSynonymSynonymTaxonDontDeleteName(){
         final String[]tableNames = {
-//                "TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+//                "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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
-        int nRelations = service.countSynonyms(true);
+        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");
@@ -611,7 +691,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        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);
@@ -621,14 +701,14 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonServiceImplTest.testDeleteSynonym.xml")
     //test delete synonym and his name
     public final void testDeleteSynonymSynonymTaxonDeleteName(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
-        int nRelations = service.countSynonyms(true);
+        long nRelations = service.countSynonyms(true);
         Assert.assertEquals("There should be 2 relationship left in the database", 2, nRelations);
 
         UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
@@ -641,7 +721,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
         nRelations = service.countSynonyms(true);
         Assert.assertEquals("There should be 1 relationship left in the database", 1, nRelations);
@@ -653,12 +733,12 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     //test remove synonym from taxon -> synonym and name still in the db and the synonymrelationship to the other taxon
     //test delete synonym -> all relationships are deleted, the name is deleted and the synonym itself
     public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
 
         UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
@@ -671,7 +751,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         List<String> initStrat = new ArrayList<String>();
         initStrat.add("markers");
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1, initStrat);
-        int nRelations = service.countSynonyms(true);
+        long nRelations = service.countSynonyms(true);
         Assert.assertEquals("There should be 2 relationship left in the database", 2, nRelations);
 
         taxon2.removeSynonym(synonym1, false);
@@ -681,7 +761,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
         nRelations = service.countSynonyms(true);
         Assert.assertEquals("There should be 1 relationship left in the database", 1, nRelations);
@@ -708,7 +788,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         commitAndStartNewTransaction(tableNames);
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
         nRelations = service.countSynonyms(true);
         Assert.assertEquals("There should be no relationship left in the database", 1, nRelations);
@@ -723,12 +803,12 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     //test delete synonym, only for a special taxon, but because of other relationships it will not be deleted at all
     public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
         final String[]tableNames = {
-//                "TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+//                "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(TaxonNameBase.class);
+        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");
@@ -738,7 +818,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1);
         taxon2.addSynonym(synonym1, SynonymType.HETEROTYPIC_SYNONYM_OF());
         service.saveOrUpdate(synonym1);
-        int nRelations = service.countSynonyms(true);
+        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());
@@ -748,23 +828,54 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         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(TaxonNameBase.class);
+        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);
     }
 
+    @Test
+    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonServiceImplTest.testDeleteSynonym.xml")
+
+    public final void testDeleteSynonymWithAnnotations(){
+        final String[]tableNames = {
+//                "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
+//                "HomotypicalGroup","HomotypicalGroup_AUD"
+        };
+
+
+        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);
+        taxon2.addSynonym(synonym1, SynonymType.HETEROTYPIC_SYNONYM_OF());
+
+        Annotation annotation = Annotation.NewDefaultLanguageInstance("test");
+        synonym1.addAnnotation(annotation);
+        service.saveOrUpdate(synonym1);
+
+        DeleteResult result = service.deleteSynonym(synonym1, new SynonymDeletionConfigurator());
+        if (result.isError()){
+            Assert.fail();
+        }
+        this.commitAndStartNewTransaction(tableNames);
+
+
+    }
+
+
     @Test
     @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
 
     public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
 
         UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
@@ -774,14 +885,14 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
 
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1);
-        TaxonNameBase<?,?> name2 = nameService.load(uuidSynonymName2);
+        TaxonName name2 = nameService.load(uuidSynonymName2);
         UUID name3Uuid = synonym1.getName().getUuid();
-        TaxonNameBase<?,?> name3 = nameService.load(name3Uuid);
-        name3.addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);
+        TaxonName name3 = nameService.load(name3Uuid);
+        name3.addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
 
         service.saveOrUpdate(synonym1);
 
-        int nRelations = nameService.getAllRelationships(1000, 0).size();
+        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();
@@ -792,11 +903,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         //synonym is deleted, but the name can not be deleted because of a name relationship
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames);
         nRelations = service.countSynonyms(true);
         //may change with better implementation of countAllRelationships (see #2653)
-        nRelations = nameService.getAllRelationships(1000, 0).size();
+        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);
 
@@ -814,12 +925,12 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     @Test
     @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonServiceImplTest.testDeleteSynonym.xml")
     public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
 
         UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
@@ -829,14 +940,14 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
 
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1);
-        TaxonNameBase<?,?> name2 = nameService.load(uuidSynonymName2);
+        TaxonName name2 = nameService.load(uuidSynonymName2);
         UUID name3Uuid = synonym1.getName().getUuid();
-        TaxonNameBase<?,?> name3 = nameService.load(name3Uuid);
-        name3.addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);
+        TaxonName name3 = nameService.load(name3Uuid);
+        name3.addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
 
         service.saveOrUpdate(synonym1);
 
-        int nRelations = nameService.getAllRelationships(1000, 0).size();
+        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();
@@ -850,11 +961,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        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.getAllRelationships(1000, 0).size();
+        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);
     }
@@ -862,12 +973,12 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     @Test
     @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonServiceImplTest.testDeleteSynonym.xml")
     public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameIgnoreIsBasionym(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
 
         UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
@@ -877,14 +988,14 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
 
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1);
-        TaxonNameBase<?,?> synName2 = nameService.load(uuidSynonymName2);
+        TaxonName synName2 = nameService.load(uuidSynonymName2);
         UUID name3Uuid = synonym1.getName().getUuid();
-        TaxonNameBase<?,?> synName1 = nameService.load(name3Uuid);
-        synName1.addRelationshipFromName(synName2, NameRelationshipType.BASIONYM(), null);
+        TaxonName synName1 = nameService.load(name3Uuid);
+        synName1.addRelationshipFromName(synName2, NameRelationshipType.BASIONYM(), null, null);
 
         service.saveOrUpdate(synonym1);
 
-        int nRelations = nameService.getAllRelationships(1000, 0).size();
+        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();
@@ -903,11 +1014,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        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.getAllRelationships(1000, 0).size();
+        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);
     }
@@ -916,14 +1027,14 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     @Test
     @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
     public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
-        int nRelations = service.countSynonyms(true);
+        long nRelations = service.countSynonyms(true);
 
 
         //may change with better implementation of countAllRelationships (see #2653)
@@ -935,8 +1046,8 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
 
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1);
-        TaxonNameBase<?,?> name2 = nameService.load(uuidSynonymName2);
-        synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);
+        TaxonName name2 = nameService.load(uuidSynonymName2);
+        synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
 
         service.deleteSynonym(synonym1, new SynonymDeletionConfigurator());
 
@@ -946,7 +1057,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        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)
@@ -957,14 +1068,15 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     @Test
     @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
     public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
-        final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",
+        @SuppressWarnings("unused")
+        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(TaxonNameBase.class);
+        int nNames = nameService.count(TaxonName.class);
         Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
-        int nRelations = service.countSynonyms(true);
+        long 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 relationships) but no name relationship", 2, nRelations);
 
@@ -972,8 +1084,8 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
 
         Synonym synonym1 = (Synonym)service.load(uuidSynonym1);
-        TaxonNameBase<?,?> name2 = nameService.load(uuidSynonymName2);
-        synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);
+        TaxonName name2 = nameService.load(uuidSynonymName2);
+        synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
 
         service.saveOrUpdate(synonym1);
         nRelations = service.countSynonyms(true);
@@ -990,11 +1102,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nSynonyms = service.count(Synonym.class);
         Assert.assertEquals("There should still be 1 synonyms left in the database. The rollback on name delete should not lead to rollback in synonym delete.", 1, nSynonyms);
-        nNames = nameService.count(TaxonNameBase.class);
+        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 taxon or synonym relationship in the database", 1, nRelations);
-        nRelations = nameService.getAllRelationships(1000,0).size();
+        nRelations = nameService.listNameRelationships(null, 1000, 0, null, null).size();
         Assert.assertEquals("There should be one name relationship in the database", 1, nRelations);
 
     }
@@ -1028,23 +1140,24 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet("BlankDataSet.xml")
+    @DataSet("../../database/ClearDBDataSet.xml")
     public final void testTaxonDeletionConfig(){
-        final String[]tableNames = {
-                "Classification", "Classification_AUD",
-                "TaxonBase","TaxonBase_AUD",
-                "TaxonNode","TaxonNode_AUD",
-                "TaxonNameBase","TaxonNameBase_AUD",
-                "TaxonRelationship", "TaxonRelationship_AUD",
-                "TaxonDescription", "TaxonDescription_AUD",
-                "HomotypicalGroup","HomotypicalGroup_AUD",
-                "PolytomousKey","PolytomousKey_AUD",
-                "PolytomousKeyNode","PolytomousKeyNode_AUD",
-                "Media","Media_AUD",
-                "WorkingSet","WorkingSet_AUD",
-                "DescriptionElementBase","DescriptionElementBase_AUD",
-                       "DeterminationEvent","DeterminationEvent_AUD",
-                       "SpecimenOrObservationBase","SpecimenOrObservationBase_AUD"};
+        final String[]tableNames = {}
+//                "Classification", "Classification_AUD",
+//                "TaxonBase","TaxonBase_AUD",
+//                "TaxonNode","TaxonNode_AUD",
+//                "TaxonName","TaxonName_AUD",
+//                "TaxonRelationship", "TaxonRelationship_AUD",
+//                "TaxonDescription", "TaxonDescription_AUD",
+//                "HomotypicalGroup","HomotypicalGroup_AUD",
+//                "PolytomousKey","PolytomousKey_AUD",
+//                "PolytomousKeyNode","PolytomousKeyNode_AUD",
+//                "Media","Media_AUD",
+//                "DescriptiveDataSet","DescriptiveDataSet_AUD",
+//                "DescriptionElementBase","DescriptionElementBase_AUD",
+//                     "DeterminationEvent","DeterminationEvent_AUD",
+//                     "SpecimenOrObservationBase","SpecimenOrObservationBase_AUD"}
+        ;
 
         UUID uuidParent=UUID.fromString("b5271d4f-e203-4577-941f-00d76fa9f4ca");
         UUID uuidChild1=UUID.fromString("326167f9-0b97-4e7d-b1bf-4ca47b82e21e");
@@ -1062,7 +1175,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Assert.assertNotNull("Child taxon should exist", child1);
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
         config.setDeleteTaxonNodes(false);
-        config.setDeleteMisappliedNamesAndInvalidDesignations(false);
+        config.setDeleteMisappliedNames(false);
         //try {
             //commitAndStartNewTransaction(tableNames);
 
@@ -1080,7 +1193,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         TaxonNode node = child1.getTaxonNodes().iterator().next();
         child1.addSource(IdentifiableSource.NewInstance(OriginalSourceType.Import));
 
-        SpecimenOrObservationBase<IIdentifiableEntityCacheStrategy> identifiedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit);
+        SpecimenOrObservationBase<?> identifiedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit);
         DeterminationEvent.NewInstance(child1, identifiedUnit);
         //UUID eventUUID = eventService.save(determinationEvent);
         UUID identifiedUnitUUID = occurenceService.save(identifiedUnit).getUuid();
@@ -1137,7 +1250,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         nTaxa = service.count(Taxon.class);
         Assert.assertEquals("There should be 2 taxa in the database",2, nTaxa);
-//             nNames = nameService.count(TaxonNameBase.class);
+//             nNames = nameService.count(TaxonName.class);
 //             Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
 //             int nRelations = service.countAllRelationships();
 //             Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
@@ -1145,7 +1258,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testDeleteTaxon(){
 
         //create a small classification
@@ -1163,7 +1276,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
             descrUUID = descr.getUuid();
             descrElementUUID = descr.getElements().iterator().next().getUuid();
         }
-        BotanicalName taxonName = (BotanicalName) nameService.find(SPECIES1_NAME_UUID);
+        IBotanicalName taxonName = nameService.find(SPECIES1_NAME_UUID);
         assertNotNull(taxonName);
 
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
@@ -1179,7 +1292,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         }
         commitAndStartNewTransaction(null);
 
-        taxonName = (BotanicalName) nameService.find(SPECIES1_NAME_UUID);
+        taxonName = nameService.find(SPECIES1_NAME_UUID);
         Taxon taxon = (Taxon)service.find(SPECIES1_UUID);
 
         //descriptionService.find(descrUUID);
@@ -1189,7 +1302,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         assertNotNull(taxonName);
         assertNull(taxon);
         config.setDeleteNameIfPossible(true);
-        Taxon newTaxon = Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null);
+        Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
         service.save(newTaxon);
         result = service.deleteTaxon(newTaxon.getUuid()
                        , config, null);
@@ -1201,7 +1314,64 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
+    public final void testDeleteTaxonWithAnnotations(){
+
+        //create a small classification
+
+        Taxon testTaxon = getTestTaxon();
+
+        service.save(testTaxon).getUuid();
+
+        Taxon speciesTaxon = (Taxon)service.find(SPECIES1_UUID);
+        Iterator<TaxonDescription> descriptionIterator = speciesTaxon.getDescriptions().iterator();
+        UUID descrUUID = null;
+        UUID descrElementUUID = null;
+        if (descriptionIterator.hasNext()){
+            TaxonDescription descr = descriptionIterator.next();
+            descrUUID = descr.getUuid();
+            descrElementUUID = descr.getElements().iterator().next().getUuid();
+        }
+        IBotanicalName taxonName = nameService.find(SPECIES1_NAME_UUID);
+        assertNotNull(taxonName);
+
+        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
+        config.setDeleteNameIfPossible(false);
+        Annotation annotation = Annotation.NewDefaultLanguageInstance("test");
+        speciesTaxon.addAnnotation(annotation);
+
+
+       // try {
+
+        DeleteResult result = service.deleteTaxon(speciesTaxon.getUuid(), config, speciesTaxon.getTaxonNodes().iterator().next().getClassification().getUuid());
+        if (!result.isOk()){
+            Assert.fail();
+        }
+        commitAndStartNewTransaction(null);
+
+        taxonName = nameService.find(SPECIES1_NAME_UUID);
+        Taxon taxon = (Taxon)service.find(SPECIES1_UUID);
+
+        //descriptionService.find(descrUUID);
+        assertNull(descriptionService.find(descrUUID));
+        assertNull(descriptionService.getDescriptionElementByUuid(descrElementUUID));
+        //assertNull(synName);
+        assertNotNull(taxonName);
+        assertNull(taxon);
+        config.setDeleteNameIfPossible(true);
+        Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
+        service.save(newTaxon);
+        result = service.deleteTaxon(newTaxon.getUuid()
+                , config, null);
+        if (!result.isOk()){
+            Assert.fail();
+        }
+
+
+    }
+
+    @Test
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testDeleteTaxonUsedInTaxonRelation(){
 
         //create a small classification
@@ -1213,7 +1383,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Taxon speciesTaxon2 = (Taxon)service.find(SPECIES2_UUID);
         speciesTaxon.addTaxonRelation(speciesTaxon2, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null);
 
-        BotanicalName taxonName = (BotanicalName) nameService.find(SPECIES1_NAME_UUID);
+        IBotanicalName taxonName = nameService.find(SPECIES1_NAME_UUID);
         assertNotNull(taxonName);
 
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
@@ -1229,7 +1399,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         }
         commitAndStartNewTransaction(null);
 
-        taxonName = (BotanicalName) nameService.find(SPECIES1_NAME_UUID);
+        taxonName = nameService.find(SPECIES1_NAME_UUID);
         Taxon taxon = (Taxon)service.find(SPECIES1_UUID);
 
 
@@ -1251,7 +1421,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
         config.setDeleteNameIfPossible(true);
-        Taxon newTaxon = Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null);
+        Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
         service.save(newTaxon);
         result = service.deleteTaxon(newTaxon.getUuid()
                 , config, null);
@@ -1263,14 +1433,14 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="BlankDataSet.xml")
+    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="../../database/ClearDBDataSet.xml")
     public final void testDeleteTaxonDeleteSynonymRelations(){
 
         final String[]tableNames = {
                  "Classification", "Classification_AUD",
                  "TaxonBase","TaxonBase_AUD",
                  "TaxonNode","TaxonNode_AUD",
-                 "TaxonNameBase","TaxonNameBase_AUD"};
+                 "TaxonName","TaxonName_AUD"};
         commitAndStartNewTransaction(tableNames);
         //create a small classification
         Taxon testTaxon = getTestTaxon();
@@ -1303,7 +1473,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testDeleteTaxonNameUsedInOtherContext(){
 
         //create a small classification
@@ -1313,10 +1483,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
         Taxon speciesTaxon = (Taxon)service.find(SPECIES1_UUID);
 
-        BotanicalName taxonName = (BotanicalName) nameService.find(SPECIES1_NAME_UUID);
+        IBotanicalName taxonName = nameService.find(SPECIES1_NAME_UUID);
         assertNotNull(taxonName);
-        BotanicalName fromName = BotanicalName.NewInstance(Rank.SPECIES());
-        taxonName.addRelationshipFromName(fromName, NameRelationshipType.VALIDATED_BY_NAME(), null);
+        TaxonName fromName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
+        taxonName.addRelationshipFromName(fromName, NameRelationshipType.VALIDATED_BY_NAME(), null, null);
+        nameService.save(fromName);
 
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
         config.setDeleteNameIfPossible(true);
@@ -1326,7 +1497,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         }
         commitAndStartNewTransaction(null);
 
-        taxonName = (BotanicalName) nameService.find(SPECIES1_NAME_UUID);
+        taxonName = nameService.find(SPECIES1_NAME_UUID);
         Taxon taxon = (Taxon)service.find(SPECIES1_UUID);
         //because of the namerelationship the name cannot be deleted
         assertNotNull(taxonName);
@@ -1335,7 +1506,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testDeleteTaxonNameUsedInTwoClassificationsDeleteAllNodes(){
         commitAndStartNewTransaction(null);
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
@@ -1372,7 +1543,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testDeleteTaxonNameUsedInTwoClassificationsDoNotDeleteAllNodes(){
         // delete the taxon only in second classification, this should delete only the nodes, not the taxa
         Taxon testTaxon = getTestTaxon();
@@ -1405,18 +1576,19 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         assertNotNull(tax);
         Taxon childTaxon = (Taxon)service.find(childUUID);
         assertNotNull(tax);
+        //when calling delete taxon and the taxon can not be deleted the children should not be deleted as well. If children should be deleted call delete taxonnode
         node = nodeService.find(childNodeUUID);
-        assertNull(node);
+        assertNotNull(node);
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testTaxonNodeDeletionConfiguratorMoveToParent(){
         //test childHandling MOVE_TO_PARENT:
         Taxon testTaxon = getTestTaxon();
         UUID uuid = service.save(testTaxon).getUuid();
 
-        Taxon topMost = Taxon.NewInstance(BotanicalName.NewInstance(Rank.FAMILY()), null);
+        Taxon topMost = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY()), null);
 
         Iterator<TaxonNode> nodes = testTaxon.getTaxonNodes().iterator();
         TaxonNode node =nodes.next();
@@ -1448,13 +1620,13 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testTaxonNodeDeletionConfiguratorDeleteChildren(){
         //test childHandling DELETE:
         Taxon testTaxon = getTestTaxon();
         UUID uuid = service.save(testTaxon).getUuid();
 
-        Taxon topMost = Taxon.NewInstance(BotanicalName.NewInstance(Rank.FAMILY()), null);
+        Taxon topMost = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY()), null);
 
         Iterator<TaxonNode> nodes = testTaxon.getTaxonNodes().iterator();
         TaxonNode node =nodes.next();
@@ -1488,13 +1660,13 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testTaxonDeletionConfiguratorDeleteMarker(){
         //test childHandling DELETE:
         Taxon testTaxon = getTestTaxon();
         UUID uuid = service.save(testTaxon).getUuid();
 
-        Taxon topMost = Taxon.NewInstance(BotanicalName.NewInstance(Rank.FAMILY()), null);
+        Taxon topMost = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY()), null);
 
         Iterator<TaxonNode> nodes = testTaxon.getTaxonNodes().iterator();
         TaxonNode node =nodes.next();
@@ -1527,13 +1699,13 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testTaxonDeletionConfiguratorTaxonWithMisappliedName(){
 
         Taxon testTaxon = getTestTaxon();
         UUID uuid = service.save(testTaxon).getUuid();
 
-        Taxon misappliedName = Taxon.NewInstance(BotanicalName.NewInstance(Rank.GENUS()), null);
+        Taxon misappliedName = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()), null);
 
         Iterator<TaxonNode> nodes = testTaxon.getTaxonNodes().iterator();
         TaxonNode node =nodes.next();
@@ -1541,7 +1713,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID misappliedNameUUID = service.save(misappliedName).getUuid();
 
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator() ;
-        config.setDeleteMisappliedNamesAndInvalidDesignations(true);
+        config.setDeleteMisappliedNames(true);
 
         DeleteResult result  = service.deleteTaxon(testTaxon.getUuid(), config, node.getClassification().getUuid());
         if(!result.isOk()){
@@ -1556,13 +1728,13 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
     }
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testTaxonDeletionConfiguratorTaxonWithMisappliedNameDoNotDelete(){
 
         Taxon testTaxon = getTestTaxon();
         UUID uuid = service.save(testTaxon).getUuid();
 
-        Taxon misappliedName = Taxon.NewInstance(BotanicalName.NewInstance(Rank.GENUS()), null);
+        Taxon misappliedName = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()), null);
 
         Iterator<TaxonNode> nodes = testTaxon.getTaxonNodes().iterator();
         TaxonNode node =nodes.next();
@@ -1570,7 +1742,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         UUID misappliedNameUUID = service.save(misappliedName).getUuid();
 
         TaxonDeletionConfigurator config = new TaxonDeletionConfigurator() ;
-        config.setDeleteMisappliedNamesAndInvalidDesignations(false);
+        config.setDeleteMisappliedNames(false);
 
         DeleteResult result = service.deleteTaxon(testTaxon.getUuid(), config, node.getClassification().getUuid());
         if(!result.isOk()){
@@ -1586,13 +1758,13 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testTaxonDeletionConfiguratorTaxonMisappliedName(){
 
         Taxon testTaxon = getTestTaxon();
         UUID uuid = service.save(testTaxon).getUuid();
 
-        Taxon misappliedNameTaxon = Taxon.NewInstance(BotanicalName.NewInstance(Rank.GENUS()), null);
+        Taxon misappliedNameTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()), null);
 
         Iterator<TaxonNode> nodes = testTaxon.getTaxonNodes().iterator();
         TaxonNode node =nodes.next();
@@ -1615,7 +1787,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         Taxon tax = (Taxon)service.find(uuid);
         assertNotNull(tax);
         tax = (Taxon)service.find(misappliedNameUUID);
-        BotanicalName name = (BotanicalName) nameService.find(misNameUUID);
+        IBotanicalName name = nameService.find(misNameUUID);
 
         assertNull(tax);
         assertNull(name);
@@ -1623,7 +1795,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     }
 
     @Test
-    @DataSet(value="BlankDataSet.xml")
+    @DataSet(value="../../database/ClearDBDataSet.xml")
     public final void testLlistIncludedTaxa(){
        Reference citation = null;
        String microcitation = null;
@@ -1683,6 +1855,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 
        service.saveOrUpdate(c1Species);
                service.saveOrUpdate(c2Species);
+               service.save(c4Species);
 
        //Tests
                //default starting at species 1
@@ -1708,10 +1881,6 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
        //same without doubtful
        dto = service.listIncludedTaxa(c1Species.getUuid(), new IncludedTaxonConfiguration(null, false, true));
        Assert.assertEquals(1, dto.getIncludedTaxa().size());
-
-
-
-
     }
 
     @Test
@@ -1787,11 +1956,11 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
     public void createTestDataSet() throws FileNotFoundException {
        Rank rank = Rank.SPECIES();
 
-        taxWithoutSyn = Taxon.NewInstance(BotanicalName.NewInstance(rank, "Test1", null, null, null, null, null, null, null), null);
-        taxWithSyn = Taxon.NewInstance(BotanicalName.NewInstance(rank, "Test3", null, null, null, null, null, null, null), null);
-        tax2WithSyn = Taxon.NewInstance(BotanicalName.NewInstance(rank, "Test5", null, null, null, null, null, null, null), null);
-        synonym = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test2", null, null, null, null, null, null, null), null);
-        synonym2 = Synonym.NewInstance(BotanicalName.NewInstance(rank, "Test4", null, null, null, null, null, null, null), null);
+        taxWithoutSyn = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test1", null, null, null, null, null, null, null), null);
+        taxWithSyn = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test3", null, null, null, null, null, null, null), null);
+        tax2WithSyn = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test5", null, null, null, null, null, null, null), null);
+        synonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test2", null, null, null, null, null, null, null), null);
+        synonym2 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test4", null, null, null, null, null, null, null), null);
         synonym2.getName().setHomotypicalGroup(synonym.getHomotypicGroup());
 
         taxWithSyn.addSynonym(synonym, SynonymType.HETEROTYPIC_SYNONYM_OF());
@@ -1824,7 +1993,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
             citationRef.setTitleCache("Sp. lunarum", true);
 
             //genus taxon with Name, combinationAuthor,
-            BotanicalName botName = BotanicalName.NewInstance(Rank.GENUS());
+            IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
             botName.setTitleCache("Hieracium L.", true);
             botName.setGenusOrUninomial("Hieracium");
             botName.setCombinationAuthorship(Person.NewInstance());
@@ -1834,15 +2003,15 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
             genusTaxon.setUuid(GENUS_UUID);
             service.save(genusTaxon);
             //a name that is the basionym of genusTaxon's name
-            BotanicalName basionym = BotanicalName.NewInstance(Rank.GENUS());
+            TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
             basionym.setTitleCache("Hieracilla DC.", true);
             basionym.setGenusOrUninomial("Hieracilla");
             basionym.setCombinationAuthorship(deCandolle);
             basionym.setUuid(BASIONYM_UUID);
-            botName.addBasionym(basionym, null, null,"216");
+            botName.addBasionym(basionym, null, null,"216", null);
             nameService.saveOrUpdate(basionym);
             //species taxon that is the child of genus taxon
-            BotanicalName botSpecies = BotanicalName.NewInstance(Rank.SPECIES());
+            IBotanicalName botSpecies = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
             botSpecies.setTitleCache("Hieracium asturianum Pau", true);
             botSpecies.setGenusOrUninomial("Hieracium");
             botSpecies.setSpecificEpithet("asturianum");
@@ -1860,7 +2029,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
 //            childTaxon.setTaxonomicParent(genusTaxon, citationRef, "456");
             classificationService.save(classification);
             //homotypic synonym of childTaxon1
-            BotanicalName botSpecies4= BotanicalName.NewInstance(Rank.SPECIES());
+            IBotanicalName botSpecies4= TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
             botSpecies4.setTitleCache("Hieracium gueri DC.", true);
             botSpecies4.setGenusOrUninomial("Hieracium");
             botSpecies4.setSpecificEpithet("gueri");
@@ -1871,7 +2040,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
             service.saveOrUpdate(childTaxon);
 
             //2nd child species taxon that is the child of genus taxon
-            BotanicalName botSpecies2= BotanicalName.NewInstance(Rank.SPECIES());
+            IBotanicalName botSpecies2= TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
             botSpecies2.setTitleCache("Hieracium wolffii Zahn", true);
             botSpecies2.setGenusOrUninomial("Hieracium");
             botSpecies2.setSpecificEpithet("wolffii");
@@ -1884,7 +2053,7 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
             //childTaxon2.setTaxonomicParent(genusTaxon, citationRef, "499");
             service.saveOrUpdate(childTaxon2);
             //heterotypic synonym of childTaxon2
-            BotanicalName botSpecies3= BotanicalName.NewInstance(Rank.SPECIES());
+            IBotanicalName botSpecies3= TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
             botSpecies3.setTitleCache("Hieracium lupium DC.", true);
             botSpecies3.setGenusOrUninomial("Hieracium");
             botSpecies3.setSpecificEpithet("lupium");
@@ -1894,18 +2063,19 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
             childTaxon2.addSynonym(heteroSynonym, SynonymType.HETEROTYPIC_SYNONYM_OF());
             service.saveOrUpdate(childTaxon2);
             //missaplied Name for childTaxon2
-            BotanicalName missName= BotanicalName.NewInstance(Rank.SPECIES());
+            IBotanicalName missName= TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
             missName.setTitleCache("Hieracium lupium DC.", true);
             missName.setGenusOrUninomial("Hieracium");
             missName.setSpecificEpithet("lupium");
             missName.setCombinationAuthorship(deCandolle);
             missName.setUuid(SPECIES5_NAME_UUID);
-            Taxon misappliedName = Taxon.NewInstance(missName, sec);
-            childTaxon2.addMisappliedName(misappliedName, citationRef, "125");
+            Taxon misappliedNameTaxon = Taxon.NewInstance(missName, sec);
+            childTaxon2.addMisappliedName(misappliedNameTaxon, citationRef, "125");
             taxDesc = getTestDescription(descrIndex++);
            // taxDesc.setUuid(DESCRIPTION2_UUID);
             genusTaxon.addDescription(taxDesc);
             service.saveOrUpdate(genusTaxon);
+            service.save(misappliedNameTaxon);
 
             return genusTaxon;
         }
@@ -1934,11 +2104,4 @@ public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {
         public Classification getTestClassification(String name){
             return Classification.NewInstance(name);
         }
-
-
-
-
 }
-
-
-