use of com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl in project qcadoo by qcadoo.
the class ValidatorTest method shouldCallFieldValidatorIfSourcePluginIsEnabled.
@Test
public final void shouldCallFieldValidatorIfSourcePluginIsEnabled() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "not equals to qwerty string");
fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
stubPluginIsEnabled(true);
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl in project qcadoo by qcadoo.
the class ValidatorTest method shouldNotCallFieldValidatorIfSourcePluginIsNotEnabled.
@Test
public final void shouldNotCallFieldValidatorIfSourcePluginIsNotEnabled() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "EverythingButNotQWERTY :)");
fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
stubPluginIsEnabled(false);
// when
Entity savedEntity = dataDefinition.save(entity);
// then
assertTrue(savedEntity.isValid());
}
use of com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl 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.hooks.FieldHookDefinitionImpl 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());
}
Aggregations