Search in sources :

Example 16 with EntityHookDefinitionImpl

use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl 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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) CustomEntityValidator(com.qcadoo.model.internal.validators.CustomEntityValidator) EntityHookDefinitionImpl(com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

Entity (com.qcadoo.model.api.Entity)16 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)16 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)16 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)16 Test (org.junit.Test)16 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)9 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)4 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)4