use of org.unitils.dbunit.annotation.DataSets in project cdmlib by cybertaxonomy.
the class AbcdGgbnImportTest method testNoAttachDnaSampleToDerivedUnit.
/**
* Tests importing of DNA unit without attaching it to an existing specimen.
* Creates a FieldUnit with an attached DnaSample.
*/
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"), @DataSet(value = "AbcdGgbnImportTest.testNoAttachDnaSampleToDerivedUnit.xml", loadStrategy = CleanSweepInsertLoadStrategy.class) })
public void testNoAttachDnaSampleToDerivedUnit() {
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
UUID fieldUnit1Uuid = UUID.fromString("b5f58da5-4442-4001-9d13-33f41518b72a");
// DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
// derivedUnit.setAccessionNumber("B 10 0066577");
// derivedUnit.setTitleCache("testUnit1", true);
//
// derivedUnit.setUuid(derivedUnit1Uuid );
//
// occurrenceService.save(derivedUnit);
//
// commitAndStartNewTransaction(null);
//
// setComplete();
// endTransaction();
//
//
// try {
// writeDbUnitDataSetFile(new String[] {
// "SpecimenOrObservationBase",
// }, "testAttachDnaSampleToDerivedUnit");
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_without_association.xml";
URL url = this.getClass().getResource(inputFile);
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
Abcd206ImportConfigurator importConfigurator = null;
try {
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
} catch (URISyntaxException e) {
e.printStackTrace();
Assert.fail();
}
assertNotNull("Configurator could not be created", importConfigurator);
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
assertTrue("Return value for import.invoke should be true", result);
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
assertEquals("Number of field units is incorrect", 2, occurrenceService.count(FieldUnit.class));
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
assertTrue(derivedUnits.contains(derivedUnit));
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
SpecimenOrObservationBase<?> dnaSampleFieldUnit = dnaSample.getDerivedFrom().getOriginals().iterator().next();
assertTrue(!specimenFieldUnit.equals(dnaSampleFieldUnit));
}
use of org.unitils.dbunit.annotation.DataSets in project cdmlib by cybertaxonomy.
the class AbcdGgbnImportTest method testAttachDnaSampleToExistingDerivedUnit_sibling.
/**
* Tests import of DNA unit and attaching it to an existing specimen to which
* it has a sibling UnitAssociation. The derived unit should not be imported because it already exists in the data base.
* The DnaSample should be attached to the existing FieldUnit of the DerivedUnit
*/
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"), @DataSet(value = "AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy = CleanSweepInsertLoadStrategy.class) })
public void testAttachDnaSampleToExistingDerivedUnit_sibling() {
UUID fieldUnit1Uuid = UUID.fromString("0f896630-48d6-4352-9c91-278be28ce19c");
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_parent_child_association.xml";
URL url = this.getClass().getResource(inputFile);
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
Abcd206ImportConfigurator importConfigurator = null;
try {
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
} catch (URISyntaxException e) {
e.printStackTrace();
Assert.fail();
}
assertNotNull("Configurator could not be created", importConfigurator);
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
assertTrue("Return value for import.invoke should be true", result);
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
for (DerivedUnit derivedUnit : derivedUnits) {
System.out.println(derivedUnit.getTitleCache());
}
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
// List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
List<FieldUnit> fieldUnitsTemp = occurrenceService.list(FieldUnit.class, null, null, null, null);
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
assertTrue(derivedUnits.contains(derivedUnit));
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(dnaSample.getUuid(), null);
assertEquals(1, fieldUnits.size());
FieldUnit dnaSampleFieldUnit = fieldUnits.iterator().next();
assertEquals(specimenFieldUnit, dnaSampleFieldUnit);
assertEquals("fieldUnit1", dnaSampleFieldUnit.getTitleCache());
}
use of org.unitils.dbunit.annotation.DataSets in project cdmlib by cybertaxonomy.
the class AbcdGgbnImportTest method testImportGgbnSparseData.
/**
* Tests importing of DNA unit with an ABCD with only few fields filled.
* Should just check that no NPEs occur when some fields are missing.
*/
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testImportGgbnSparseData() {
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_sparse_data.xml";
URL url = this.getClass().getResource(inputFile);
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
Abcd206ImportConfigurator importConfigurator = null;
try {
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
} catch (URISyntaxException e) {
e.printStackTrace();
Assert.fail();
}
assertNotNull("Configurator could not be created", importConfigurator);
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
assertTrue("Return value for import.invoke should be true", result);
}
use of org.unitils.dbunit.annotation.DataSets in project cdmlib by cybertaxonomy.
the class SpecimenImportConfiguratorTest method testImportNewTaxaToDefaultClassification.
/**
* Test imports one unit with an already existing taxon and one with a new taxon.
* The new taxon should be added to a newly created default classification.
*/
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"), @DataSet(value = "SpecimenImportConfiguratorTest.testIgnoreAuthorship.xml", loadStrategy = CleanSweepInsertLoadStrategy.class) })
public void testImportNewTaxaToDefaultClassification() {
UUID taxonUUID = UUID.fromString("26f98a58-09ab-49a0-ab9f-7490757c86d2");
UUID classificationUUID = UUID.fromString("eee32748-5b89-4266-a99a-1edb3781d0eb");
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_B_10_0066577_two_units_almost_same.xml";
URL url = this.getClass().getResource(inputFile);
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
Abcd206ImportConfigurator importConfigurator = null;
try {
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
importConfigurator.setDnaSoure(null);
} catch (URISyntaxException e) {
e.printStackTrace();
Assert.fail();
}
assertNotNull("Configurator could not be created", importConfigurator);
// test initial state
Taxon taxon = (Taxon) taxonService.load(taxonUUID);
assertNotNull(taxon);
Classification classification = classificationService.load(classificationUUID);
assertNotNull(classification);
assertEquals(1, taxon.getTaxonNodes().size());
TaxonNode taxonNode = taxon.getTaxonNodes().iterator().next();
assertEquals(classification, taxonNode.getClassification());
assertEquals(1, classificationService.count(Classification.class));
assertEquals(1, taxonService.count(Taxon.class));
importConfigurator.setClassificationUuid(classificationUUID);
// importConfigurator.setIgnoreAuthorship(true);
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
assertTrue("Return value for import.invoke should be true", result);
// re-load classification to avoid session conflicts
classification = classificationService.load(classificationUUID);
assertEquals(2, occurrenceService.count(DerivedUnit.class));
// assertEquals(2, taxonService.count(Taxon.class));
assertEquals(2, classificationService.count(Classification.class));
// get default classification
List<Classification> list = classificationService.list(Classification.class, null, null, null, null);
Classification defaultClassification = null;
for (Classification c : list) {
if (c.getUuid() != classificationUUID) {
defaultClassification = c;
}
}
assertEquals(1, classification.getAllNodes().size());
assertEquals(2, defaultClassification.getAllNodes().size());
}
use of org.unitils.dbunit.annotation.DataSets in project cdmlib by cybertaxonomy.
the class DefinedTermDaoImplTest method testListByTermType.
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testListByTermType() {
TermType termType = TermType.Modifier;
List<DefinedTermBase> existingList = this.dao.listByTermType(termType, null, null, null, null);
int nExisting = existingList.size();
int nExistingTerms = this.dao.list(DefinedTerm.class, null, null, null, null).size();
// prepare
@SuppressWarnings("unchecked") TermVocabulary<DefinedTerm> newVoc = TermVocabulary.NewInstance(termType);
UUID vocUuid = UUID.fromString("6ced4c45-9c1b-4053-9dc3-6b8c51d286ed");
newVoc.setUuid(vocUuid);
UUID termUuid = UUID.fromString("2ab69720-c06c-4cfc-8928-d2ae6f1e4a48");
DefinedTerm newModifier = DefinedTerm.NewModifierInstance("Test Modifier Description", "English Modifier", "TM");
newModifier.setUuid(termUuid);
newVoc.addTerm(newModifier);
vocabularyDao.save(newVoc);
this.commitAndStartNewTransaction(null);
// assert 1 more
int nNow = this.dao.listByTermType(termType, null, null, null, null).size();
Assert.assertEquals("There should be exactly 1 more term now", nExisting + 1, nNow);
int nTermsNow = this.dao.list(DefinedTerm.class, null, null, null, null).size();
Assert.assertEquals("There should be exactly 1 more term now", nExistingTerms + 1, nTermsNow);
this.commitAndStartNewTransaction(null);
// Add German representation
Representation newRepresentation = Representation.NewInstance("Beschreibung", "Deutscher Modifier", "Abk.", Language.GERMAN());
newModifier.addRepresentation(newRepresentation);
dao.saveOrUpdate(newModifier);
this.commitAndStartNewTransaction(null);
nNow = this.dao.listByTermType(termType, null, null, null, null).size();
Assert.assertEquals("There should still be only one more term (but with 2 representations)", nExisting + 1, nNow);
nTermsNow = this.dao.list(DefinedTerm.class, null, null, null, null).size();
Assert.assertEquals("There should be exactly 1 more term now", nExistingTerms + 1, nTermsNow);
List<DefinedTerm> languages = this.dao.listByTermType(TermType.Language, null, null, null, null);
Assert.assertNotNull(languages);
Assert.assertEquals(485, languages.size());
}
Aggregations