use of com.qcadoo.model.internal.validators.CustomEntityValidator in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasNoErrorIfCustomEntityValidatorReturnsTrue.
@Test
public void shouldHasNoErrorIfCustomEntityValidatorReturnsTrue() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Mr T");
entity.setField("age", "18");
dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
use of com.qcadoo.model.internal.validators.CustomEntityValidator 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.validators.CustomEntityValidator 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.validators.CustomEntityValidator in project qcadoo by qcadoo.
the class ValidatorTest method shouldHaveErrorIfCustomEntityValidatorReturnsFalse.
@Test
public void shouldHaveErrorIfCustomEntityValidatorReturnsFalse() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Mr");
entity.setField("age", "18");
dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
Aggregations