@Test public final void shouldCallFieldCustomValidatorWithNullOldValueOnCreate() { 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); validationService.validateGenericEntity(dataDefinition, genericEntity, null); verify(someFieldDefinition, times(1)).callValidators(genericEntity, null, someFieldNewValue); }
@Override public void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity, final Entity existingGenericEntity) { validateEntityAgainstVersion(existingGenericEntity, genericEntity, dataDefinition); copyReadOnlyAndMissingFields(dataDefinition, genericEntity, existingGenericEntity); parseFields(dataDefinition, genericEntity); if (genericEntity.getId() == null) { dataDefinition.callCreateHook(genericEntity); parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); } else { parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); dataDefinition.callUpdateHook(genericEntity); } dataDefinition.callSaveHook(genericEntity); }
ValidationServiceImpl implements ValidationService { @Override public void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity, final Entity existingGenericEntity) { validateEntityAgainstVersion(existingGenericEntity, genericEntity, dataDefinition); copyReadOnlyAndMissingFields(dataDefinition, genericEntity, existingGenericEntity); parseFields(dataDefinition, genericEntity); if (genericEntity.getId() == null) { dataDefinition.callCreateHook(genericEntity); parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); } else { parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); dataDefinition.callUpdateHook(genericEntity); } dataDefinition.callSaveHook(genericEntity); } }
ValidationServiceImpl implements ValidationService { @Override public void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity, final Entity existingGenericEntity) { validateEntityAgainstVersion(existingGenericEntity, genericEntity, dataDefinition); copyReadOnlyAndMissingFields(dataDefinition, genericEntity, existingGenericEntity); parseFields(dataDefinition, genericEntity); if (genericEntity.getId() == null) { dataDefinition.callCreateHook(genericEntity); parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); } else { parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); dataDefinition.callUpdateHook(genericEntity); } dataDefinition.callSaveHook(genericEntity); }  }
ValidationServiceImpl implements ValidationService { @Override public void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity, final Entity existingGenericEntity) { validateEntityAgainstVersion(existingGenericEntity, genericEntity, dataDefinition); copyReadOnlyAndMissingFields(dataDefinition, genericEntity, existingGenericEntity); parseFields(dataDefinition, genericEntity); if (genericEntity.getId() == null) { dataDefinition.callCreateHook(genericEntity); parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); } else { parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); dataDefinition.callUpdateHook(genericEntity); } dataDefinition.callSaveHook(genericEntity); }  @Override void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity,
            final Entity existingGenericEntity); }
ValidationServiceImpl implements ValidationService { @Override public void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity, final Entity existingGenericEntity) { validateEntityAgainstVersion(existingGenericEntity, genericEntity, dataDefinition); copyReadOnlyAndMissingFields(dataDefinition, genericEntity, existingGenericEntity); parseFields(dataDefinition, genericEntity); if (genericEntity.getId() == null) { dataDefinition.callCreateHook(genericEntity); parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); } else { parseAndValidateEntity(dataDefinition, genericEntity, existingGenericEntity); dataDefinition.callUpdateHook(genericEntity); } dataDefinition.callSaveHook(genericEntity); }  @Override void validateGenericEntity(final InternalDataDefinition dataDefinition, final Entity genericEntity,
            final Entity existingGenericEntity);  }