Search in sources :

Example 26 with SampleSimpleDatabaseObject

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

the class DataAccessServiceGetTest method shouldReturnValidEntity.

@Test
public void shouldReturnValidEntity() throws Exception {
    // given
    SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject();
    simpleDatabaseObject.setId(1L);
    simpleDatabaseObject.setName("Mr T");
    simpleDatabaseObject.setAge(66);
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(simpleDatabaseObject);
    // when
    Entity entity = dataDefinition.get(1L);
    // then
    assertEquals(1L, entity.getId().longValue());
    assertEquals("Mr T", entity.getField("name"));
    assertEquals(66, entity.getField("age"));
}
Also used : Entity(com.qcadoo.model.api.Entity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 27 with SampleSimpleDatabaseObject

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

the class HookTest method shouldCallAllDefinedHooksWhileUpdating.

@Test
public void shouldCallAllDefinedHooksWhileUpdating() 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));
    dataDefinition.addSaveHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onSave", PLUGIN_IDENTIFIER, applicationContext));
    // when
    entity = dataDefinition.save(entity);
    // then
    assertEquals("update", entity.getField("name"));
    assertEquals(Integer.valueOf(11), 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 28 with SampleSimpleDatabaseObject

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

the class HookTest method shouldUpdateHookNotSeeNewValueOfReadOnlyField.

@Test
public void shouldUpdateHookNotSeeNewValueOfReadOnlyField() 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(), "rewriteReadOnlyField", PLUGIN_IDENTIFIER, applicationContext));
    // when
    entity = dataDefinition.save(entity);
    // then
    assertNull(entity.getField("readOnly"));
    assertNull(entity.getField("name"));
}
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 29 with SampleSimpleDatabaseObject

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

the class HookTest method shouldCallOnSaveHookWhileUpdating.

@Test
public void shouldCallOnSaveHookWhileUpdating() 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.addSaveHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onSave", PLUGIN_IDENTIFIER, applicationContext));
    // when
    entity = dataDefinition.save(entity);
    // then
    assertEquals(null, entity.getField("name"));
    assertEquals(Integer.valueOf(11), 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 30 with SampleSimpleDatabaseObject

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

the class HookTest method shouldSaveHookNotSeeNewValueOfReadOnlyField.

@Test
public void shouldSaveHookNotSeeNewValueOfReadOnlyField() 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(), "rewriteReadOnlyField", PLUGIN_IDENTIFIER, applicationContext));
    // when
    entity = dataDefinition.save(entity);
    // then
    assertNull(entity.getField("readOnly"));
    assertNull(entity.getField("name"));
}
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)

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