Search in sources :

Example 36 with SampleSimpleDatabaseObject

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) SampleParentDatabaseObject(com.qcadoo.model.beans.sample.SampleParentDatabaseObject) SampleParentDatabaseObject(com.qcadoo.model.beans.sample.SampleParentDatabaseObject) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 37 with SampleSimpleDatabaseObject

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());
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 38 with SampleSimpleDatabaseObject

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());
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 39 with SampleSimpleDatabaseObject

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());
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 40 with SampleSimpleDatabaseObject

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);
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Aggregations

SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)50 Test (org.junit.Test)49 Entity (com.qcadoo.model.api.Entity)27 SampleParentDatabaseObject (com.qcadoo.model.beans.sample.SampleParentDatabaseObject)13 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)8 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)8 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)7 Criteria (org.hibernate.Criteria)7 UniqueValidator (com.qcadoo.model.internal.validators.UniqueValidator)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)3 FieldHookDefinition (com.qcadoo.model.internal.api.FieldHookDefinition)3 HasManyEntitiesType (com.qcadoo.model.internal.types.HasManyEntitiesType)2 IntegerType (com.qcadoo.model.internal.types.IntegerType)2 List (java.util.List)2 EntityList (com.qcadoo.model.api.EntityList)1 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)1 SearchResult (com.qcadoo.model.api.search.SearchResult)1 EntityHookDefinition (com.qcadoo.model.internal.api.EntityHookDefinition)1 StringType (com.qcadoo.model.internal.types.StringType)1 ArrayList (java.util.ArrayList)1