use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.
the class HookTest method shouldUpdateHookNotSeeNewValueOfReadOnlyField.
@Test
public void shouldUpdateHookNotSeeNewValueOfReadOnlyField() 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(), "rewriteReadOnlyField", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertNull(entity.getField("readOnly"));
assertNull(entity.getField("name"));
}
use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.
the class HookTest method shouldCreateHookCanOverrideValueOfReadOnlyField.
@Test
public void shouldCreateHookCanOverrideValueOfReadOnlyField() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, null);
entity.setField("name", null);
entity.setField("age", null);
entity.setField("readOnly", "youCanNotSeeMe!");
dataDefinition.addCreateHook(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 shouldCallOnSaveHookWhileUpdating.
@Test
public void shouldCallOnSaveHookWhileUpdating() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", null);
entity.setField("age", null);
SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
dataDefinition.addSaveHook(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 shouldSaveHookNotSeeNewValueOfReadOnlyField.
@Test
public void shouldSaveHookNotSeeNewValueOfReadOnlyField() 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.addSaveHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "rewriteReadOnlyField", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertNull(entity.getField("readOnly"));
assertNull(entity.getField("name"));
}
use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.
the class HookTest method shouldCallOnUpdateHook.
@Test
public void shouldCallOnUpdateHook() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", null);
entity.setField("age", null);
SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
dataDefinition.addUpdateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onUpdate", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertEquals("update", entity.getField("name"));
assertEquals(null, entity.getField("age"));
}
Aggregations