use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorIfCustomValidatorReturnsTrue.
@Test
public void shouldHasNoErrorIfCustomValidatorReturnsTrue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "qwerty");
fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHaveErrorIfCustomValidatorReturnsFalse.
@Test
public void shouldHaveErrorIfCustomValidatorReturnsFalse() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "qwert");
fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
assertEquals(1, entity.getErrors().size());
assertEquals("qcadooView.validate.field.error.custom", entity.getError("name").getMessage());
assertEquals(0, entity.getGlobalErrors().size());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorsIfStringValueIsInsideTheRange.
@Test
public void shouldHasNoErrorsIfStringValueIsInsideTheRange() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "bbb");
fieldDefinitionName.withValidator(new RangeValidator("a", "c", true));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorIfDateTypeIsWrong.
@Test
public void shouldHasErrorIfDateTypeIsWrong() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", "2010-01-a");
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorIfBigDecimalTypeIsWrong.
@Test
public void shouldHasErrorIfBigDecimalTypeIsWrong() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", "221.2w");
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
Aggregations