Search in sources :

Example 6 with InternalFieldDefinition

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

the class ValidationServiceImplTest method shouldCallFieldCustomValidatorWithNonNullOldValueOnUpdate.

@Test
public final void shouldCallFieldCustomValidatorWithNonNullOldValueOnUpdate() {
    // given
    final Long savedEntityId = 1L;
    final String someFieldName = "someField";
    final String someFieldOldValue = "someFieldValue";
    final String someFieldNewValue = "someFieldValueAfterUpdate";
    InternalFieldDefinition someFieldDefinition = mockFieldDefinition(someFieldName, new StringType());
    Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
    fieldsMap.put(someFieldName, someFieldDefinition);
    stubFieldDefinitions(dataDefinition, fieldsMap);
    when(genericEntity.getId()).thenReturn(savedEntityId);
    when(genericEntity.getField(someFieldName)).thenReturn(someFieldNewValue);
    when(genericEntity.isFieldValid(someFieldName)).thenReturn(true);
    when(existingGenericEntity.getField(someFieldName)).thenReturn(someFieldOldValue);
    // when
    validationService.validateGenericEntity(dataDefinition, genericEntity, existingGenericEntity);
    // then
    verify(someFieldDefinition, times(1)).callValidators(genericEntity, someFieldOldValue, someFieldNewValue);
}
Also used : InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) Test(org.junit.Test)

Example 7 with InternalFieldDefinition

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

the class ValidationServiceImplTest method shouldCallFieldCustomValidatorWithNullOldValueOnCreate.

@Test
public final void shouldCallFieldCustomValidatorWithNullOldValueOnCreate() {
    // given
    final Long savedEntityId = null;
    final String someFieldName = "someField";
    final String someFieldNewValue = "someFieldValueAfterUpdate";
    InternalFieldDefinition someFieldDefinition = mockFieldDefinition(someFieldName, new StringType());
    Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
    fieldsMap.put(someFieldName, someFieldDefinition);
    stubFieldDefinitions(dataDefinition, fieldsMap);
    when(genericEntity.getId()).thenReturn(savedEntityId);
    when(genericEntity.getField(someFieldName)).thenReturn(someFieldNewValue);
    when(genericEntity.isFieldValid(someFieldName)).thenReturn(true);
    // when
    validationService.validateGenericEntity(dataDefinition, genericEntity, null);
    // then
    verify(someFieldDefinition, times(1)).callValidators(genericEntity, null, someFieldNewValue);
}
Also used : InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) Test(org.junit.Test)

Example 8 with InternalFieldDefinition

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

the class ValidationServiceImplTest method mockFieldDefinition.

private InternalFieldDefinition mockFieldDefinition(final String name, final FieldType type) {
    InternalFieldDefinition fieldDefinition = mock(InternalFieldDefinition.class);
    when(fieldDefinition.getName()).thenReturn(name);
    when(fieldDefinition.getType()).thenReturn(type);
    when(fieldDefinition.callValidators(Mockito.any(Entity.class), Mockito.any(), Mockito.any())).thenReturn(true);
    return fieldDefinition;
}
Also used : Entity(com.qcadoo.model.api.Entity) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition)

Aggregations

InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)8 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 Entity (com.qcadoo.model.api.Entity)3 StringType (com.qcadoo.model.internal.types.StringType)3 Test (org.junit.Test)3 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)1 ManyToManyType (com.qcadoo.model.api.types.ManyToManyType)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1