use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldReturnProperValueOfTheField.
@Test
public void shouldReturnProperValueOfTheField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
databaseEntity.setName("Mr T");
// when
Object value = entityService.getField(databaseEntity, fieldDefinitionName);
// then
assertEquals("Mr T", value);
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldConvertDatabaseEntityIntoGenericOne.
@Test
public void shouldConvertDatabaseEntityIntoGenericOne() throws Exception {
// given
SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
parentDatabaseEntity.setName("Mr X");
SampleParentDatabaseObject lazyParentDatabaseEntity = mock(SampleParentDatabaseObject.class, RETURNS_DEEP_STUBS);
given(lazyParentDatabaseEntity.getHibernateLazyInitializer().getIdentifier()).willReturn(77L);
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(2L);
databaseEntity.setAge(12);
databaseEntity.setName("Mr T");
databaseEntity.setBelongsTo(parentDatabaseEntity);
databaseEntity.setLazyBelongsTo(lazyParentDatabaseEntity);
// when
Entity genericEntity = entityService.convertToGenericEntity(dataDefinition, databaseEntity);
// then
assertNotNull(genericEntity);
assertEquals(Long.valueOf(2), genericEntity.getId());
assertEquals(12, genericEntity.getField("age"));
assertEquals("Mr T", genericEntity.getField("name"));
isInstanceOf(DefaultEntity.class, genericEntity.getField("belongsTo"));
assertEquals("Mr X", ((Entity) genericEntity.getField("belongsTo")).getField("name"));
isInstanceOf(ProxyEntity.class, genericEntity.getField("lazyBelongsTo"));
assertEquals(Long.valueOf(77), ((Entity) genericEntity.getField("lazyBelongsTo")).getId());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class PriorityTest method shouldNotMoveToOffsetBelowOne.
@Test
public void shouldNotMoveToOffsetBelowOne() throws Exception {
// given
SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
databaseObject.setPriority(11);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
given(criteria.list()).willReturn(Lists.newArrayList());
// when
dataDefinition.move(1L, -20);
// then
SampleSimpleDatabaseObject movedDatabaseObject = new SampleSimpleDatabaseObject(1L);
movedDatabaseObject.setPriority(1);
verify(session).update(movedDatabaseObject);
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class HookTest method shouldSaveHookCanOverrideValueOfReadOnlyField.
@Test
public void shouldSaveHookCanOverrideValueOfReadOnlyField() 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(), "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 ValidatorTest method shouldHasNoErrorsIfUpdatedFieldIsNotDuplicated.
@Test
public void shouldHasNoErrorsIfUpdatedFieldIsNotDuplicated() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", "not existed");
SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
given(session.get(SampleSimpleDatabaseObject.class, 1L)).willReturn(databaseObject);
given(criteria.uniqueResult()).willReturn(0);
fieldDefinitionName.withValidator(new UniqueValidator());
// when
entity = dataDefinition.save(entity);
// then
verify(session).save(any(SampleSimpleDatabaseObject.class));
assertTrue(entity.isValid());
}
Aggregations