Search in sources :

Example 1 with CustomEntityValidator

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());
}
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)

Example 2 with CustomEntityValidator

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());
}
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) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 3 with CustomEntityValidator

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());
}
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) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 4 with CustomEntityValidator

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());
}
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)4 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)4 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)4 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)4 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)4 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)4 Test (org.junit.Test)4 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)2