Search in sources :

Example 16 with SampleSimpleDatabaseObject

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);
}
Also used : 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 17 with SampleSimpleDatabaseObject

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

Example 18 with SampleSimpleDatabaseObject

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

Example 19 with SampleSimpleDatabaseObject

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) EntityHookDefinitionImpl(com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 20 with SampleSimpleDatabaseObject

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) UniqueValidator(com.qcadoo.model.internal.validators.UniqueValidator) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) 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