use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.
the class HookTest method shouldCallOnSaveHookWhileCreating.
@Test
public void shouldCallOnSaveHookWhileCreating() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", null);
entity.setField("age", null);
dataDefinition.addCreateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onSave", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertEquals(null, entity.getField("name"));
assertEquals(Integer.valueOf(11), entity.getField("age"));
}
use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.
the class HookTest method shouldUpdateHookCanOverrideValueOfReadOnlyField.
@Test
public void shouldUpdateHookCanOverrideValueOfReadOnlyField() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", null);
entity.setField("age", null);
entity.setField("readOnly", "youCanNotSeeMe!");
SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
dataDefinition.addUpdateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "overrideReadOnlyField", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertEquals("overrided", entity.getField("readOnly"));
}
use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.
the class HookTest method shouldCallOnCreateHook.
@Test
public void shouldCallOnCreateHook() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", null);
entity.setField("age", null);
dataDefinition.addCreateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onCreate", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertEquals("create", entity.getField("name"));
assertEquals(null, entity.getField("age"));
}
use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl 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.hooks.EntityHookDefinitionImpl 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());
}
Aggregations