use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfStringValueIsTooLong.
@Test
public void shouldHasErrorsIfStringValueIsTooLong() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "qwerty");
fieldDefinitionName.withValidator(new LengthValidator(null, null, 5));
// 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 shouldIgnoreLengthValidatorForIntegerValue.
@Test
public void shouldIgnoreLengthValidatorForIntegerValue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", new Integer("123456"));
fieldDefinitionAge.withValidator(new LengthValidator(null, 1, null));
// 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 shouldHasErrorsIfIntegerUnscaledValueIsNotEqual.
@Test
public void shouldHasErrorsIfIntegerUnscaledValueIsNotEqual() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", new Integer("123"));
fieldDefinitionAge.withValidator(new UnscaledValueValidator(null, 4, null));
// 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 shouldHasErrorsIfBigDecimalPresicionAndScaleAreTooLong.
@Test
public void shouldHasErrorsIfBigDecimalPresicionAndScaleAreTooLong() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", new BigDecimal("123.456"));
fieldDefinitionMoney.withValidator(new ScaleValidator(null, null, 2)).withValidator(new UnscaledValueValidator(null, null, 4));
// 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 shouldHasErrorMessage.
@Test
public void shouldHasErrorMessage() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", "");
fieldDefinitionAge.withValidator(new RequiredValidator());
// 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.missing", entity.getError("age").getMessage());
assertEquals(0, entity.getGlobalErrors().size());
}
Aggregations