Search in sources :

Example 1 with EntityHookDefinition

use of com.qcadoo.model.internal.api.EntityHookDefinition in project qcadoo by qcadoo.

the class DataAccessServiceSaveTest method shouldNotOmitCreateHooksExceptOnCopy.

@Test
public void shouldNotOmitCreateHooksExceptOnCopy() throws Exception {
    EntityHookDefinition onCreateHook = mock(EntityHookDefinition.class);
    given(onCreateHook.isEnabled()).willReturn(true);
    dataDefinition.addCreateHook(onCreateHook);
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "Mr T");
    entity.setField("age", 66);
    SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject();
    databaseObject.setName("Mr T");
    databaseObject.setAge(66);
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session).save(databaseObject);
    assertTrue(entity.isValid());
    verify(onCreateHook, times(1)).isEnabled();
    verify(onCreateHook, times(1)).call(Mockito.any(Entity.class));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityHookDefinition(com.qcadoo.model.internal.api.EntityHookDefinition) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 2 with EntityHookDefinition

use of com.qcadoo.model.internal.api.EntityHookDefinition in project qcadoo by qcadoo.

the class DataDefinitionImpl method getHook.

@Override
public EntityHookDefinition getHook(final String type, final String className, final String methodName) {
    EntityHookDefinition hook = hooksByMethodPath.get(type.toUpperCase(Locale.ENGLISH) + "." + className + "." + methodName);
    checkNotNull(hook, "Cannot find hook " + type.toUpperCase(Locale.ENGLISH) + "." + className + "." + methodName + " for dataDefinition " + this);
    return hook;
}
Also used : EntityHookDefinition(com.qcadoo.model.internal.api.EntityHookDefinition)

Example 3 with EntityHookDefinition

use of com.qcadoo.model.internal.api.EntityHookDefinition in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterTest method shouldSetEntityValidators.

@Test
public void shouldSetEntityValidators() {
    assertEquals(1, ((DataDefinitionImpl) dataDefinition).getValidators().size());
    EntityHookDefinition validator = ((DataDefinitionImpl) dataDefinition).getValidators().get(0);
    assertThat(validator, instanceOf(CustomEntityValidator.class));
    testHookDefinition(validator, "entityHook", CustomHook.class, "validate");
}
Also used : DataDefinitionImpl(com.qcadoo.model.internal.DataDefinitionImpl) CustomEntityValidator(com.qcadoo.model.internal.validators.CustomEntityValidator) EntityHookDefinition(com.qcadoo.model.internal.api.EntityHookDefinition) TransactionMockAwareTest(com.qcadoo.model.TransactionMockAwareTest) Test(org.junit.Test)

Aggregations

EntityHookDefinition (com.qcadoo.model.internal.api.EntityHookDefinition)3 Test (org.junit.Test)2 TransactionMockAwareTest (com.qcadoo.model.TransactionMockAwareTest)1 Entity (com.qcadoo.model.api.Entity)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 DataDefinitionImpl (com.qcadoo.model.internal.DataDefinitionImpl)1 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)1