use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldThrownAnExceptionWhileGettingNotExistingField.
@Test(expected = IllegalStateException.class)
public void shouldThrownAnExceptionWhileGettingNotExistingField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "unknown");
// when
entityService.getField(databaseEntity, fieldDefinition);
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldSetNullIfBelongsToFieldIsEmpty.
@Test
public void shouldSetNullIfBelongsToFieldIsEmpty() throws Exception {
// given
SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
parentDatabaseEntity.setName("Mr X");
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(2L);
databaseEntity.setBelongsTo(parentDatabaseEntity);
// when
entityService.setField(databaseEntity, fieldDefinitionBelongsTo, null);
// then
assertNull(databaseEntity.getBelongsTo());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldThrownAnExceptionWhileSettingNotExistingField.
@Test(expected = IllegalStateException.class)
public void shouldThrownAnExceptionWhileSettingNotExistingField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "unknown").withType(new StringType());
// when
entityService.setField(databaseEntity, fieldDefinition, "XXX");
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldConvertGenericEntityIntoDatabaseOneUsingExistingEntity.
@Test
public void shouldConvertGenericEntityIntoDatabaseOneUsingExistingEntity() throws Exception {
// given
Entity genericEntity = new DefaultEntity(dataDefinition, 2L);
genericEntity.setField("name", "Mr T");
genericEntity.setField("age", 12);
genericEntity.setField("belongsTo", 1L);
SampleSimpleDatabaseObject existingDatabaseEntity = new SampleSimpleDatabaseObject(11L);
SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
parentDatabaseEntity.setName("Mr X");
given(session.get(SampleParentDatabaseObject.class, 1L)).willReturn(parentDatabaseEntity);
given(session.load(SampleParentDatabaseObject.class, 1L)).willReturn(parentDatabaseEntity);
validationService.validateGenericEntity(dataDefinition, genericEntity, new DefaultEntity(dataDefinition, 2L));
// when
Object databaseEntity = entityService.convertToDatabaseEntity(dataDefinition, genericEntity, existingDatabaseEntity);
// then
assertNotNull(databaseEntity);
isInstanceOf(SampleSimpleDatabaseObject.class, databaseEntity);
assertEquals(Long.valueOf(11), ((SampleSimpleDatabaseObject) databaseEntity).getId());
assertEquals(Integer.valueOf(12), ((SampleSimpleDatabaseObject) databaseEntity).getAge());
assertEquals("Mr T", ((SampleSimpleDatabaseObject) databaseEntity).getName());
assertNotNull(((SampleSimpleDatabaseObject) databaseEntity).getBelongsTo());
assertEquals("Mr X", ((SampleSimpleDatabaseObject) databaseEntity).getBelongsTo().getName());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldNotThrownAnExceptionWhileGettingFieldWithInvalidType.
@Test
public void shouldNotThrownAnExceptionWhileGettingFieldWithInvalidType() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
databaseEntity.setName("Mr T");
FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "name").withType(new IntegerType());
// when
entityService.getField(databaseEntity, fieldDefinition);
}
Aggregations