Search in sources :

Example 6 with ExpectedDataSet

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

the class MediaRepresentationPartDaoImplTest method testSave.

@Test
@ExpectedDataSet
public void testSave() {
    try {
        URI uri = new URI("http://www.test3.de");
        MediaRepresentationPart part1 = MediaRepresentationPart.NewInstance(uri, 22);
        // a representation is needed otherwise a not nullable exception is thrown (due to lucene index (?))
        MediaRepresentation representation = MediaRepresentation.NewInstance();
        representation.addRepresentationPart(part1);
        dao.save(part1);
        commit();
    } catch (URISyntaxException e) {
        Assert.fail("URI should be ok");
    }
}
Also used : MediaRepresentationPart(eu.etaxonomy.cdm.model.media.MediaRepresentationPart) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet)

Example 7 with ExpectedDataSet

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

the class EntityValidationCrudJdbcImplTest method testOneOldOneNewError.

@Test
@DataSet("EntityValidationCrudJdbcImplTest.testSave.xml")
@ExpectedDataSet("EntityValidationCrudJdbcImplTest.testOneOldOneNewError-result.xml")
public // having 1 entityconstraintviolation)
void testOneOldOneNewError() {
    DateTime created = new DateTime(2014, 1, 1, 0, 0);
    // Same entity as in @DataSet
    Employee emp = new Employee();
    emp.setId(100);
    emp.setUuid(UUID.fromString("f8de74c6-aa56-4de3-931e-87b61da0218c"));
    // Other properties not relevant for this test
    EntityValidation entityValidation = EntityValidation.newInstance();
    entityValidation.setValidatedEntity(emp);
    entityValidation.setId(1);
    entityValidation.setUuid(UUID.fromString("dae5b090-30e8-45bc-9460-2eb2028d3c18"));
    entityValidation.setCreated(created);
    entityValidation.setCrudEventType(CRUDEventType.INSERT);
    // Old error (in @DataSet)
    EntityConstraintViolation error = EntityConstraintViolation.newInstance();
    error.setId(Integer.MIN_VALUE);
    error.setCreated(created);
    error.setUuid(UUID.fromString("358da71f-b646-4b79-b00e-dcb68b6425ba"));
    error.setSeverity(Severity.ERROR);
    error.setPropertyPath("givenName");
    error.setInvalidValue("Foo");
    error.setMessage("Garbage In Garbage Out");
    error.setValidationGroup("eu.etaxonomy.cdm.validation.Level2");
    error.setValidator("eu.etaxonomy.cdm.persistence.validation.GarbageValidator");
    entityValidation.addEntityConstraintViolation(error);
    // New error (not in @DataSet)
    error = EntityConstraintViolation.newInstance();
    // Don't leave ID generation to chance; we want it to be same as in
    // @ExpectedDataSet
    error.setId(2);
    error.setCreated(created);
    error.setUuid(UUID.fromString("358da71f-b646-4b79-b00e-dcb68b6425bb"));
    error.setSeverity(Severity.ERROR);
    error.setPropertyPath("familyName");
    error.setInvalidValue("Bar");
    error.setMessage("Garbage In Garbage Out");
    error.setValidationGroup("eu.etaxonomy.cdm.validation.Level2");
    error.setValidator("eu.etaxonomy.cdm.persistence.validation.FamilyNameValidator");
    entityValidation.addEntityConstraintViolation(error);
    // EntityValidationCrudJdbcImpl dao = new EntityValidationCrudJdbcImpl(dataSource);
    validationCrudJdbcDao.saveEntityValidation(entityValidation, new Class[] { Level2.class });
}
Also used : Employee(eu.etaxonomy.cdm.persistence.validation.Employee) EntityConstraintViolation(eu.etaxonomy.cdm.model.validation.EntityConstraintViolation) EntityValidation(eu.etaxonomy.cdm.model.validation.EntityValidation) DateTime(org.joda.time.DateTime) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet)

Example 8 with ExpectedDataSet

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

the class EntityValidationCrudJdbcImplTest method testAllErrorsSolved.

@Test
@DataSet("EntityValidationCrudJdbcImplTest.testSave.xml")
@ExpectedDataSet("EntityValidationCrudJdbcImplTest.testAllErrorsSolved-result.xml")
public // increased.
void testAllErrorsSolved() {
    DateTime created = new DateTime(2014, 1, 1, 0, 0);
    Employee emp = new Employee();
    emp.setId(100);
    emp.setUuid(UUID.fromString("f8de74c6-aa56-4de3-931e-87b61da0218c"));
    EntityValidation entityValidation = EntityValidation.newInstance();
    entityValidation.setValidatedEntity(emp);
    entityValidation.setId(1);
    entityValidation.setUuid(UUID.fromString("dae5b090-30e8-45bc-9460-2eb2028d3c18"));
    entityValidation.setCreated(created);
    entityValidation.setCrudEventType(CRUDEventType.INSERT);
    entityValidation.setValidationCount(5);
    EntityValidationCrudJdbcImpl dao = new EntityValidationCrudJdbcImpl(dataSource);
    dao.saveEntityValidation(entityValidation, new Class[] { Level2.class });
}
Also used : Employee(eu.etaxonomy.cdm.persistence.validation.Employee) EntityValidation(eu.etaxonomy.cdm.model.validation.EntityValidation) DateTime(org.joda.time.DateTime) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet)

Example 9 with ExpectedDataSet

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

the class EntityValidationCrudJdbcImplTest method testReplaceError.

@Test
@DataSet("EntityValidationCrudJdbcImplTest.testSave.xml")
@ExpectedDataSet("EntityValidationCrudJdbcImplTest.testReplaceError-result.xml")
public // removed and the new error is inserted.
void testReplaceError() {
    // All identical to @DataSet:
    DateTime created = new DateTime(2014, 1, 1, 0, 0);
    Employee emp = new Employee();
    emp.setId(100);
    emp.setUuid(UUID.fromString("f8de74c6-aa56-4de3-931e-87b61da0218c"));
    EntityValidation entityValidation = EntityValidation.newInstance();
    entityValidation.setValidatedEntity(emp);
    entityValidation.setId(1);
    entityValidation.setUuid(UUID.fromString("dae5b090-30e8-45bc-9460-2eb2028d3c18"));
    entityValidation.setCreated(created);
    entityValidation.setCrudEventType(CRUDEventType.INSERT);
    entityValidation.setValidationCount(5);
    EntityConstraintViolation error = EntityConstraintViolation.newInstance();
    error.setId(38);
    error.setCreated(created);
    error.setUuid(UUID.fromString("358da71f-b646-4b79-b00e-dcb68b6425ba"));
    error.setSeverity(Severity.ERROR);
    error.setPropertyPath("givenName");
    // Except for:
    error.setInvalidValue("Bar");
    error.setMessage("Garbage In Garbage Out");
    error.setValidationGroup("eu.etaxonomy.cdm.validation.Level2");
    error.setValidator("eu.etaxonomy.cdm.persistence.validation.GarbageValidator");
    Set<EntityConstraintViolation> errors = new HashSet<EntityConstraintViolation>(1);
    errors.add(error);
    entityValidation.addEntityConstraintViolation(error);
    EntityValidationCrudJdbcImpl dao = new EntityValidationCrudJdbcImpl(dataSource);
    dao.saveEntityValidation(entityValidation, new Class[] { Level2.class });
}
Also used : Employee(eu.etaxonomy.cdm.persistence.validation.Employee) EntityConstraintViolation(eu.etaxonomy.cdm.model.validation.EntityConstraintViolation) EntityValidation(eu.etaxonomy.cdm.model.validation.EntityValidation) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet)

Example 10 with ExpectedDataSet

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

the class TypeDesignationDaoHibernateImplTest method testSaveTypeDesignationsCascadeToSpecimen.

@Test
@ExpectedDataSet
public void testSaveTypeDesignationsCascadeToSpecimen() {
    TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    name1.setTitleCache("Name1", true);
    name1.setUuid(UUID.fromString("eb41f549-4a70-499b-a9a5-f2314880df07"));
    SpecimenTypeDesignation desig1 = SpecimenTypeDesignation.NewInstance();
    desig1.setUuid(UUID.fromString("6df85e4c-49fe-4eb5-acde-cf6c0c9fc3c5"));
    name1.addTypeDesignation(desig1, true);
    DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
    specimen.setUuid(UUID.fromString("f1a7c3b9-169c-4845-9b21-e77f863a8bce"));
    specimen.setTitleCache("Specimen to cascade", true);
    desig1.setTypeSpecimen(specimen);
    nameDao.saveOrUpdate(name1);
    this.setComplete();
    this.endTransaction();
// printDataSet(System.out, new String[]{"TaxonName","TaxonName_AUD","TypeDesignationBase","TypeDesignationBase_AUD",
// "TaxonName_TypeDesignationBase","TaxonName_TypeDesignationBase_AUD",
// "TaxonName_TypeDesignationBase","SpecimenOrObservationBase","SpecimenOrObservationBase_AUD",
// "HomotypicalGroup","HomotypicalGroup_AUD"});
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet)

Aggregations

Test (org.junit.Test)32 ExpectedDataSet (org.unitils.dbunit.annotation.ExpectedDataSet)32 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)26 DataSet (org.unitils.dbunit.annotation.DataSet)25 Person (eu.etaxonomy.cdm.model.agent.Person)8 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)6 EntityValidation (eu.etaxonomy.cdm.model.validation.EntityValidation)6 CdmIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmIntegrationTest)6 TextData (eu.etaxonomy.cdm.model.description.TextData)5 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)5 Employee (eu.etaxonomy.cdm.persistence.validation.Employee)5 DateTime (org.joda.time.DateTime)5 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)4 EntityConstraintViolation (eu.etaxonomy.cdm.model.validation.EntityConstraintViolation)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 FileNotFoundException (java.io.FileNotFoundException)3 HashSet (java.util.HashSet)3 Language (eu.etaxonomy.cdm.model.common.Language)2 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)2 Media (eu.etaxonomy.cdm.model.media.Media)2