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);
}
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);
}
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;
}
Aggregations