Search in sources :

Example 31 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class HookTest method shouldCallOnUpdateHook.

@Test
public void shouldCallOnUpdateHook() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition, 1L);
    entity.setField("name", null);
    entity.setField("age", null);
    SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
    dataDefinition.addUpdateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onUpdate", PLUGIN_IDENTIFIER, applicationContext));
    // when
    entity = dataDefinition.save(entity);
    // then
    assertEquals("update", entity.getField("name"));
    assertEquals(null, entity.getField("age"));
}
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 32 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class HookTest method shouldUpdateHookCanOverrideValueOfReadOnlyField.

@Test
public void shouldUpdateHookCanOverrideValueOfReadOnlyField() 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.addUpdateHook(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 33 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldSetBelongsToField.

@Test
public void shouldSetBelongsToField() throws Exception {
    // given
    Entity parentEntity = new DefaultEntity(dataDefinition, 1L);
    parentEntity.setField("name", "Mr X");
    SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
    parentDatabaseEntity.setName("Mr X");
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(2L);
    given(session.load(SampleParentDatabaseObject.class, 1L)).willReturn(parentDatabaseEntity);
    // when
    entityService.setField(databaseEntity, fieldDefinitionBelongsTo, parentEntity);
    // then
    assertNotNull(databaseEntity.getBelongsTo());
    assertEquals(parentDatabaseEntity, databaseEntity.getBelongsTo());
}
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 34 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldReturnProperValueOfTheBelongsToField.

@Test
public void shouldReturnProperValueOfTheBelongsToField() throws Exception {
    // given
    SampleParentDatabaseObject parentDatabaseEntity = new SampleParentDatabaseObject(1L);
    parentDatabaseEntity.setName("Mr X");
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(2L);
    databaseEntity.setName("Mr T");
    databaseEntity.setBelongsTo(parentDatabaseEntity);
    // when
    Object value = entityService.getField(databaseEntity, fieldDefinitionBelongsTo);
    // then
    isInstanceOf(Entity.class, value);
    assertEquals(Long.valueOf(1), ((Entity) value).getId());
    assertEquals("Mr X", ((Entity) value).getField("name"));
}
Also used : 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 35 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldReturnProperId.

@Test
public void shouldReturnProperId() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(13L);
    // when
    Long id = entityService.getId(databaseEntity);
    // then
    assertEquals(Long.valueOf(13), id);
}
Also used : Matchers.anyLong(org.mockito.Matchers.anyLong) 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