Search in sources :

Example 1 with DataSets

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));
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) UUID(java.util.UUID) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 2 with DataSets

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());
}
Also used : FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 3 with DataSets

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);
}
Also used : SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 4 with DataSets

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());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Classification(eu.etaxonomy.cdm.model.taxon.Classification) URISyntaxException(java.net.URISyntaxException) UUID(java.util.UUID) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 5 with DataSets

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());
}
Also used : DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) Representation(eu.etaxonomy.cdm.model.term.Representation) UUID(java.util.UUID) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) TermType(eu.etaxonomy.cdm.model.term.TermType) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Aggregations

Test (org.junit.Test)50 DataSets (org.unitils.dbunit.annotation.DataSets)50 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)46 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)20 UUID (java.util.UUID)18 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)15 DeleteResult (eu.etaxonomy.cdm.api.service.DeleteResult)14 HashSet (java.util.HashSet)13 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)11 TaxonNodeFilter (eu.etaxonomy.cdm.filter.TaxonNodeFilter)9 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)9 Classification (eu.etaxonomy.cdm.model.taxon.Classification)9 ArrayList (java.util.ArrayList)9 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)8 Distribution (eu.etaxonomy.cdm.model.description.Distribution)8 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)8 Reference (eu.etaxonomy.cdm.model.reference.Reference)8 URISyntaxException (java.net.URISyntaxException)8 ICdmRepository (eu.etaxonomy.cdm.api.application.ICdmRepository)7 URI (eu.etaxonomy.cdm.common.URI)7