Search in sources :

Example 41 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.

the class FieldTypeFactoryTest method shouldReturnManyToManyType.

@Test
public void shouldReturnManyToManyType() throws Exception {
    // when
    FieldType fieldType = new ManyToManyEntitiesType("parent", "entity", "joinFieldName", ManyToManyType.Cascade.NULLIFY, true, false, dataDefinitionService);
    // then
    assertEquals(Set.class, fieldType.getType());
    assertTrue(fieldType.toObject(fieldDefinition, new DefaultEntity(dataDefinition)).isValid());
}
Also used : DefaultEntity(com.qcadoo.model.internal.DefaultEntity) ManyToManyEntitiesType(com.qcadoo.model.internal.types.ManyToManyEntitiesType) FieldType(com.qcadoo.model.api.types.FieldType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 42 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity 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 43 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity 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 44 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.

the class HookTest method shouldCreateHookCanOverrideValueOfReadOnlyField.

@Test
public void shouldCreateHookCanOverrideValueOfReadOnlyField() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition, null);
    entity.setField("name", null);
    entity.setField("age", null);
    entity.setField("readOnly", "youCanNotSeeMe!");
    dataDefinition.addCreateHook(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) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 45 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity 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)

Aggregations

DefaultEntity (com.qcadoo.model.internal.DefaultEntity)92 Test (org.junit.Test)91 Entity (com.qcadoo.model.api.Entity)90 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)66 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)53 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)16 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)12 DataDefinition (com.qcadoo.model.api.DataDefinition)10 RangeValidator (com.qcadoo.model.internal.validators.RangeValidator)9 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)8 LengthValidator (com.qcadoo.model.internal.validators.LengthValidator)8 UnscaledValueValidator (com.qcadoo.model.internal.validators.UnscaledValueValidator)8 JSONObject (org.json.JSONObject)8 BigDecimal (java.math.BigDecimal)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 ScaleValidator (com.qcadoo.model.internal.validators.ScaleValidator)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FieldHookDefinitionImpl (com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl)4 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)4