use of eu.etaxonomy.cdm.model.validation.EntityValidation in project cdmlib by cybertaxonomy.
the class EntityValidationCrudJdbcImplTest method testSaveAlreadyExistingError.
@Test
@DataSet("EntityValidationCrudJdbcImplTest.testSave.xml")
@ExpectedDataSet("EntityValidationCrudJdbcImplTest.testSaveAlreadyExistingError-result.xml")
public // is an increment of the validation counter.
void testSaveAlreadyExistingError() {
// All same as in @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"));
// 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);
entityValidation.setValidationCount(5);
EntityConstraintViolation error = EntityConstraintViolation.newInstance();
// Actually not same as in @DataSet to force
// EntityConstraintViolation.equals() method to take
// other properties into account (e.g. propertyPath,
// invalidValue, etc.)
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");
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 });
}
use of eu.etaxonomy.cdm.model.validation.EntityValidation in project cdmlib by cybertaxonomy.
the class EntityValidationCrudJdbcImplTest method testSameErrorOtherEntity.
@Test
@DataSet("EntityValidationCrudJdbcImplTest.testSave.xml")
@ExpectedDataSet("EntityValidationCrudJdbcImplTest.testSameErrorOtherEntity-result.xml")
public // having 1 entityconstraintviolation)
void testSameErrorOtherEntity() {
DateTime created = new DateTime(2014, 1, 1, 0, 0);
// Not in @DataSet
Employee emp = new Employee();
emp.setId(200);
emp.setUuid(UUID.fromString("f8de74c6-aa56-4de3-931e-87b61da0218d"));
EntityValidation entityValidation = EntityValidation.newInstance();
entityValidation.setValidatedEntity(emp);
entityValidation.setId(2);
entityValidation.setUuid(UUID.fromString("dae5b090-30e8-45bc-9460-2eb2028d3c19"));
entityValidation.setCreated(created);
entityValidation.setCrudEventType(CRUDEventType.INSERT);
entityValidation.setValidationCount(1);
// equals() error in @DataSet
EntityConstraintViolation error = EntityConstraintViolation.newInstance();
error.setId(2);
error.setCreated(created);
error.setUuid(UUID.fromString("358da71f-b646-4b79-b00e-dcb68b6425bb"));
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");
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 });
}
use of eu.etaxonomy.cdm.model.validation.EntityValidation in project cdmlib by cybertaxonomy.
the class EntityValidationCrudJdbcImplTest method test_DeleteValidationResult.
/**
* Test method for
* {@link eu.etaxonomy.cdm.persistence.dao.jdbc.validation.EntityValidationCrudJdbcImpl#deleteEntityValidation (java.lang.String, int)}
* .
*/
@Test
@DataSet
@ExpectedDataSet
public void test_DeleteValidationResult() {
EntityValidationCrudJdbcImpl dao = new EntityValidationCrudJdbcImpl(dataSource);
dao.deleteEntityValidation(SYNONYM, 200);
EntityValidation result = dao.getEntityValidation(SYNONYM, 200);
assertTrue(result == null);
}
use of eu.etaxonomy.cdm.model.validation.EntityValidation in project cdmlib by cybertaxonomy.
the class BatchValidatorTest method testRun.
/**
* Test method for
* {@link eu.etaxonomy.cdm.api.validation.batch.BatchValidator#run()}.
*
* @throws SQLException
*/
@Test
@Ignore
public void testRun() throws SQLException {
ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("PUBLIC", "sa", "");
app = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.CREATE);
HibernateValidatorConfiguration config = Validation.byProvider(HibernateValidator.class).configure();
ValidatorFactory validatorFactory = config.buildValidatorFactory();
Validator validator = validatorFactory.getValidator();
BatchValidator batchValidator = new BatchValidator();
batchValidator.setAppController(app);
batchValidator.setValidator(validator);
batchValidator.setValidationGroups(BatchValidator.DEFAULT_VALIDATION_GROUPS);
// Create 10 References of type book and 10 of type Journal
IReferenceService refService = app.getReferenceService();
for (int i = 0; i < 10; ++i) {
Reference ref0 = ReferenceFactory.newBook();
ref0.setIsbn("bla bla");
ref0.setIssn("foo foo");
// Each book should violate 3 constraints
if (i == 0) {
Set<?> errors = validator.validate(ref0, BatchValidator.DEFAULT_VALIDATION_GROUPS);
// do a plain java language assert here.
assert (errors.size() == 3);
}
refService.save(ref0);
Reference ref1 = ReferenceFactory.newJournal();
ref1.setIsbn("bar bar");
ref1.setIssn("baz baz");
// Each journal should violate 4 constraints
if (i == 0) {
Set<?> errors = validator.validate(ref1, BatchValidator.DEFAULT_VALIDATION_GROUPS);
assert (errors.size() == 4);
}
refService.save(ref1);
}
batchValidator.run();
// So we should have 20 validation results (10 for books, 10 for
// journals);
IEntityValidationService validationResultService = app.getEntityValidationService();
List<EntityValidation> results = validationResultService.getValidationResults();
Assert.assertEquals("Expected 20 validation results", 20, results.size());
// And we should have a total of 70 (10 * (3+4)) constraint violations
int errors = 0;
for (EntityValidation result : results) {
errors += result.getEntityConstraintViolations().size();
}
Assert.assertEquals("Expected 70 errors", 70, errors);
}
Aggregations