use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldConvertGenericEntityIntoDatabaseOne.
@Test
public void shouldConvertGenericEntityIntoDatabaseOne() throws Exception {
// given
Entity genericEntity = new DefaultEntity(dataDefinition, 2L);
genericEntity.setField("name", "Mr T");
genericEntity.setField("age", 12);
genericEntity.setField("belongsTo", 1L);
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, null);
// when
Object databaseEntity = entityService.convertToDatabaseEntity(dataDefinition, genericEntity, null);
// then
assertNotNull(databaseEntity);
isInstanceOf(SampleSimpleDatabaseObject.class, databaseEntity);
assertEquals(Long.valueOf(2), ((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 shouldSetProperId.
@Test
public void shouldSetProperId() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject();
// when
entityService.setId(databaseEntity, 13L);
// then
assertEquals(Long.valueOf(13), databaseEntity.getId());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldSetEmptyField.
@Test
public void shouldSetEmptyField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
databaseEntity.setName("name");
// when
entityService.setField(databaseEntity, fieldDefinitionName, null);
// then
assertNull(databaseEntity.getName());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldSetNotEmptyField.
@Test
public void shouldSetNotEmptyField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
databaseEntity.setName("name");
// when
entityService.setField(databaseEntity, fieldDefinitionName, "XXX");
// then
assertEquals("XXX", databaseEntity.getName());
}
use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.
the class PriorityTest method shouldChangeEntitiesWithPriorityGreaterThatDeleted.
@Test
public void shouldChangeEntitiesWithPriorityGreaterThatDeleted() throws Exception {
// given
SampleSimpleDatabaseObject existingDatabaseObject = new SampleSimpleDatabaseObject(1L);
existingDatabaseObject.setPriority(11);
SampleSimpleDatabaseObject otherDatabaseObject = new SampleSimpleDatabaseObject(2L);
otherDatabaseObject.setPriority(12);
given(session.get(SampleSimpleDatabaseObject.class, 1L)).willReturn(existingDatabaseObject);
given(criteria.list()).willReturn(Lists.newArrayList(otherDatabaseObject));
// when
dataDefinition.delete(1L);
// then
SampleSimpleDatabaseObject updatedDatabaseObject = new SampleSimpleDatabaseObject(2L);
updatedDatabaseObject.setPriority(11);
verify(session).update(updatedDatabaseObject);
SampleSimpleDatabaseObject deletedDatabaseObject = new SampleSimpleDatabaseObject(1L);
deletedDatabaseObject.setPriority(11);
verify(session).delete(deletedDatabaseObject);
}
Aggregations