Search in sources :

Example 11 with SampleSimpleDatabaseObject

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

Example 12 with SampleSimpleDatabaseObject

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

Example 13 with SampleSimpleDatabaseObject

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

Example 14 with SampleSimpleDatabaseObject

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());
}
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 15 with SampleSimpleDatabaseObject

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);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) 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