use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class FormComponentState method copyFieldMessages.
private void copyFieldMessages(final EntityMessagesHolder messagesHolder) {
for (Map.Entry<String, FieldComponentState> fieldComponentEntry : getFieldComponents().entrySet()) {
ErrorMessage message = messagesHolder.getError(fieldComponentEntry.getKey());
copyMessage(fieldComponentEntry.getValue(), message);
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class FormComponentState method copyEntityToFields.
private void copyEntityToFields(final Entity entity, final boolean requestUpdateState) {
for (Map.Entry<String, FieldComponentState> field : getFieldComponents().entrySet()) {
ErrorMessage message = entity.getError(field.getKey());
copyMessage(field.getValue(), message);
if (fieldIsGridCorrespondingLookup(field.getValue(), field.getKey(), entity)) {
continue;
}
if (fieldIsDetachedEntityTree(field.getValue(), field.getKey(), entity)) {
EntityTree tree = entity.getTreeField(field.getKey());
if (tree != null) {
((TreeComponentState) field.getValue()).setRootNode(tree.getRoot());
}
}
field.getValue().setFieldValue(convertFieldToString(entity.getField(field.getKey()), field.getKey()));
if (requestUpdateState) {
field.getValue().requestComponentUpdateState();
}
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldNotDeleteFormEntity.
@Test
public void shouldNotDeleteFormEntity() throws Exception {
// given
EntityMessagesHolder messagesHolder = mock(EntityMessagesHolder.class);
final String message = "some.message";
ErrorMessage errorMessage = new ErrorMessage(message);
given(messagesHolder.getGlobalErrors()).willReturn(Lists.newArrayList(errorMessage));
Map<String, ErrorMessage> fieldErrors = Maps.newHashMap();
fieldErrors.put("name", errorMessage);
given(messagesHolder.getErrors()).willReturn(fieldErrors);
EntityOpResult result = EntityOpResult.failure(messagesHolder);
given(dataDefinition.delete(13L)).willReturn(result);
name.setFieldValue("text");
form.setFieldValue(13L);
// when
form.performEvent(viewDefinitionState, "delete", new String[0]);
// then
assertNotNull(name.getFieldValue());
verify(dataDefinition).delete(13L);
assertEquals(13L, form.getFieldValue());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class CustomValidatorTest method shouldNotAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToField.
@Test
public final void shouldNotAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToField() {
// given
Map<String, ErrorMessage> errors = Maps.newHashMap();
errors.put(FIELD_NAME, new ErrorMessage(CUSTOM_MSG));
stubFieldHookDef(false, errors);
// when
boolean isValid = customValidator.call(entity, oldValue, newValue);
// then
assertFalse(isValid);
verify(fieldHookDef, times(1)).call(entity, oldValue, newValue);
ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);
verify(entity, times(1)).addError(Mockito.eq(fieldDefinition), argCaptor.capture(), Mockito.<String>anyVararg());
assertEquals(CUSTOM_MSG, argCaptor.getValue());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class CustomValidatorTest method shouldAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToOtherField.
@Test
public final void shouldAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToOtherField() {
// given
Map<String, ErrorMessage> errors = Maps.newHashMap();
errors.put("another" + FIELD_NAME, new ErrorMessage(CUSTOM_MSG));
stubFieldHookDef(false, errors);
// when
boolean isValid = customValidator.call(entity, oldValue, newValue);
// then
assertFalse(isValid);
verify(fieldHookDef, times(1)).call(entity, oldValue, newValue);
ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);
verify(entity, times(1)).addError(Mockito.eq(fieldDefinition), argCaptor.capture(), Mockito.<String>anyVararg());
assertEquals(DEFAULT_MSG, argCaptor.getValue());
}
Aggregations