use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldIgnoreLengthValidatorForBigDecimalValue.
@Test
public void shouldIgnoreLengthValidatorForBigDecimalValue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", new BigDecimal("123.456"));
fieldDefinitionMoney.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 shouldHasNoCheckRangeOfBoolean.
@Test
public void shouldHasNoCheckRangeOfBoolean() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("retired", "false");
fieldDefinitionRetired.withValidator(new RangeValidator(true, true, 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 shouldHasNoCheckLenghtOfDate.
@Test
public void shouldHasNoCheckLenghtOfDate() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("birthDate", "2010-01-01");
fieldDefinitionBirthDate.withValidator(new LengthValidator(null, null, 0));
// 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 shouldCallEntityValidatorIfSourcePluginIsEnabled.
@Test
public final void shouldCallEntityValidatorIfSourcePluginIsEnabled() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", 24);
entity.setField("name", "Fantomas");
dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
stubPluginIsEnabled(true);
// when
Entity savedEntity = dataDefinition.save(entity);
// then
assertFalse(savedEntity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfBigDecimalUnscaledValueAreTooShort.
@Test
public void shouldHasErrorsIfBigDecimalUnscaledValueAreTooShort() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", new BigDecimal("123.45"));
fieldDefinitionMoney.withValidator(new UnscaledValueValidator(5, null, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
Aggregations