Search in sources :

Example 1 with DataSet

use of org.unitils.dbunit.annotation.DataSet in project cdmlib by cybertaxonomy.

the class EditGeoServiceTest method getDistributionServiceRequestParameterString.

@SuppressWarnings("deprecation")
// @Test
@DataSet(value = "EditGeoServiceTest.getDistributionServiceRequestParameterString.xml")
public // })
void getDistributionServiceRequestParameterString() {
    boolean subAreaPreference = false;
    boolean statusOrderPreference = false;
    Set<MarkerType> hideMarkedAreas = null;
    Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = null;
    List<Language> langs = null;
    List<TaxonDescription> taxonDescriptions = new ArrayList<>();
    TaxonDescription description1 = TaxonDescription.NewInstance();
    taxonDescriptions.add(description1);
    Distribution distribution1 = Distribution.NewInstance(Country.GERMANY(), null);
    description1.addElement(distribution1);
    Distribution distribution2 = Distribution.NewInstance(Country.FRANCE(), null);
    distribution2.setFeature(Feature.COMMON_NAME());
    description1.addElement(distribution2);
    Taxon taxon = (Taxon) taxonService.find(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
    TaxonDescription taxDesc = taxon.getDescriptions().iterator().next();
    for (DescriptionElementBase deb : taxDesc.getElements()) {
        Distribution distribution = CdmBase.deproxy(deb, Distribution.class);
        NamedArea area = distribution.getArea();
        System.out.println(area.getTitleCache());
    }
    taxonDescriptions.addAll(taxon.getDescriptions());
    String distributions = editGeoService.getDistributionServiceRequestParameterString(taxonDescriptions, subAreaPreference, statusOrderPreference, hideMarkedAreas, presenceAbsenceTermColors, langs);
    System.out.println(distributions);
    Assert.assertTrue("Distribution string should contain the non-persited distribution Germany", distributions.contains("DEU"));
    Assert.assertFalse("Distribution string should contain France as it has a non-distribution feature", distributions.contains("FRA"));
// CHE,POL
}
Also used : Color(java.awt.Color) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) Language(eu.etaxonomy.cdm.model.common.Language) Distribution(eu.etaxonomy.cdm.model.description.Distribution) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) PresenceAbsenceTerm(eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 2 with DataSet

use of org.unitils.dbunit.annotation.DataSet 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);
}
Also used : SynonymDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 3 with DataSet

use of org.unitils.dbunit.annotation.DataSet in project cdmlib by cybertaxonomy.

the class TaxonServiceImplTest method testDeleteTaxon.

@Test
@DataSet(value = "../../database/ClearDBDataSet.xml")
public final void testDeleteTaxon() {
    // 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);
    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(descriptionElementService.find(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();
    }
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 4 with DataSet

use of org.unitils.dbunit.annotation.DataSet in project cdmlib by cybertaxonomy.

the class TaxonServiceImplTest method testChangeSynonymToAcceptedTaxonWithSecHandlingWarningSelect.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
public final void testChangeSynonymToAcceptedTaxonWithSecHandlingWarningSelect() {
    Taxon genus = getTestTaxon();
    TaxonNode node = genus.getTaxonNodes().iterator().next();
    UpdateResult result = new UpdateResult();
    TaxonBase<?> syn = service.find(SYNONYM2_UUID);
    Reference sec = ReferenceFactory.newBook();
    sec.setTitleCache("Flora Cuba", true);
    Reference newSec = ReferenceFactory.newBook();
    newSec.setTitleCache("Flora Hawaii", true);
    UUID newSecUuid = referenceService.saveOrUpdate(newSec);
    syn.setSec(sec);
    service.saveOrUpdate(syn);
    try {
        result = service.changeSynonymToAcceptedTaxon(SYNONYM2_UUID, SPECIES2_UUID, node.getUuid(), newSecUuid, "23", SecReferenceHandlingEnum.KeepOrSelect, true);
    } catch (HomotypicalGroupChangeException e) {
        Assert.fail("Invocation of change method should not throw an exception");
    }
    taxWithSyn = null;
    // test flush (resave deleted object)
    syn = service.find(SYNONYM2_UUID);
    taxWithSyn = (Taxon) service.find(SPECIES2_UUID);
    TaxonNode taxNodeNew = nodeService.find(result.getCdmEntity().getUuid());
    Taxon taxNew = taxNodeNew.getTaxon();
    assertNull(syn);
    assertNotNull(taxWithSyn);
    assertNotNull(taxNew);
    assertNotNull(taxNew.getSec());
    assertEquals(newSec, taxNew.getSec());
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) HomotypicalGroupChangeException(eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 5 with DataSet

use of org.unitils.dbunit.annotation.DataSet in project cdmlib by cybertaxonomy.

the class TaxonServiceImplTest method testDeleteTaxonNameUsedInOtherContext.

@Test
@DataSet(value = "../../database/ClearDBDataSet.xml")
public final void testDeleteTaxonNameUsedInOtherContext() {
    // create a small classification
    Taxon testTaxon = getTestTaxon();
    service.save(testTaxon).getUuid();
    Taxon speciesTaxon = (Taxon) service.find(SPECIES1_UUID);
    IBotanicalName taxonName = nameService.find(SPECIES1_NAME_UUID);
    assertNotNull(taxonName);
    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);
    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);
    // because of the namerelationship the name cannot be deleted
    assertNotNull(taxonName);
    assertNull(taxon);
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

DataSet (org.unitils.dbunit.annotation.DataSet)349 Test (org.junit.Test)342 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)275 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)109 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)89 ExpectedDataSet (org.unitils.dbunit.annotation.ExpectedDataSet)89 UUID (java.util.UUID)85 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)75 Classification (eu.etaxonomy.cdm.model.taxon.Classification)51 Reference (eu.etaxonomy.cdm.model.reference.Reference)42 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)40 CdmIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmIntegrationTest)33 ArrayList (java.util.ArrayList)32 SearchResult (eu.etaxonomy.cdm.api.service.search.SearchResult)30 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)30 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)28 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)25 OrderHint (eu.etaxonomy.cdm.persistence.query.OrderHint)23 Person (eu.etaxonomy.cdm.model.agent.Person)22 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)22