use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject 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"));
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject 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.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldSetBelongsToField.
@Test
public void shouldSetBelongsToField() throws Exception {
// given
Entity parentEntity = new DefaultEntity(dataDefinition, 1L);
parentEntity.setField("name", "Mr X");
SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
parentDatabaseEntity.setName("Mr X");
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(2L);
given(session.load(SampleParentDatabaseObject.class, 1L)).willReturn(parentDatabaseEntity);
// when
entityService.setField(databaseEntity, fieldDefinitionBelongsTo, parentEntity);
// then
assertNotNull(databaseEntity.getBelongsTo());
assertEquals(parentDatabaseEntity, databaseEntity.getBelongsTo());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldReturnProperValueOfTheBelongsToField.
@Test
public void shouldReturnProperValueOfTheBelongsToField() throws Exception {
// given
SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
parentDatabaseEntity.setName("Mr X");
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(2L);
databaseEntity.setName("Mr T");
databaseEntity.setBelongsTo(parentDatabaseEntity);
// when
Object value = entityService.getField(databaseEntity, fieldDefinitionBelongsTo);
// then
isInstanceOf(Entity.class, value);
assertEquals(Long.valueOf(1), ((Entity) value).getId());
assertEquals("Mr X", ((Entity) value).getField("name"));
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldReturnProperId.
@Test
public void shouldReturnProperId() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(13L);
// when
Long id = entityService.getId(databaseEntity);
// then
assertEquals(Long.valueOf(13), id);
}
Aggregations