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