Search in sources :

Example 1 with EntityHookDefinitionImpl

use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.

the class HookTest method shouldCreateHookNotSeeNewValueOfReadOnlyField.

@Test
public void shouldCreateHookNotSeeNewValueOfReadOnlyField() 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(), "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) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 2 with EntityHookDefinitionImpl

use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl 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 3 with EntityHookDefinitionImpl

use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.

the class HookTest method shouldCallAllDefinedHooksWhileCreating.

@Test
public void shouldCallAllDefinedHooksWhileCreating() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", null);
    entity.setField("age", null);
    dataDefinition.addCreateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onCreate", PLUGIN_IDENTIFIER, applicationContext));
    dataDefinition.addSaveHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onSave", PLUGIN_IDENTIFIER, applicationContext));
    // when
    entity = dataDefinition.save(entity);
    // then
    assertEquals("create", 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) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 4 with EntityHookDefinitionImpl

use of com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl in project qcadoo by qcadoo.

the class ValidatorTest method shouldHasNoErrorIfCustomEntityValidatorReturnsTrue.

@Test
public void shouldHasNoErrorIfCustomEntityValidatorReturnsTrue() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "Mr T");
    entity.setField("age", "18");
    dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
    // 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) CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) CustomEntityValidator(com.qcadoo.model.internal.validators.CustomEntityValidator) 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 5 with EntityHookDefinitionImpl

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

Aggregations

Entity (com.qcadoo.model.api.Entity)16 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)16 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)16 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)16 Test (org.junit.Test)16 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)9 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)4 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)4