use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfIntegerValueIsTooLong.
@Test
public void shouldHasErrorsIfIntegerValueIsTooLong() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", 123456);
fieldDefinitionAge.withValidator(new UnscaledValueValidator(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 shouldHasErrorsIfStringNotMatchExpression.
@Test
public void shouldHasErrorsIfStringNotMatchExpression() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Qcadoo Framework RLZ!");
fieldDefinitionName.withValidator(new RegexValidator(".*MES.*"));
// 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 shouldNotCallEntityValidatorIfSourcePluginIsNotEnabled.
@Test
public final void shouldNotCallEntityValidatorIfSourcePluginIsNotEnabled() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
stubPluginIsEnabled(false);
// when
Entity savedEntity = dataDefinition.save(entity);
// then
assertTrue(savedEntity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorsIfIntegerValueIsInsideTheRange.
@Test
public void shouldHasNoErrorsIfIntegerValueIsInsideTheRange() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", 5);
fieldDefinitionAge.withValidator(new RangeValidator(4, null, 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 shouldHaveNoErrorsIfStringMatchExpression.
@Test
public void shouldHaveNoErrorsIfStringMatchExpression() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Qcadoo Framework RLZ!");
fieldDefinitionName.withValidator(new RegexValidator("^Qcadoo.*"));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
Aggregations