use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class ProgressPerShiftViewSaver method showValidationErrors.
private void showValidationErrors(final ViewDefinitionState view, final Iterable<ErrorMessage> errorMessages) {
FormComponent form = getFormComponent(view);
form.addMessage("qcadooView.message.saveFailedMessage", ComponentState.MessageType.FAILURE);
for (ErrorMessage errorMessage : errorMessages) {
form.addMessage(errorMessage.getMessage(), ComponentState.MessageType.FAILURE, errorMessage.getVars());
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class StateChangeContextTest method shouldMarkExistingDatabaseEntityAsInvalidIfConstructorGetInvalidStateChangeEntity.
@Test
public final void shouldMarkExistingDatabaseEntityAsInvalidIfConstructorGetInvalidStateChangeEntity() {
// given
final Entity existingStateChangeEntity = mock(Entity.class);
given(stateChangeEntity.isValid()).willReturn(false);
given(stateChangeEntity.getId()).willReturn(1L);
given(stateChangeDD.get(Mockito.any(Long.class))).willReturn(existingStateChangeEntity);
given(existingStateChangeEntity.isValid()).willReturn(true);
final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
given(stateChangeEntity.getErrors()).willReturn(fieldErrorsMap);
final List<ErrorMessage> globalErrors = Lists.newArrayList();
final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
globalErrors.add(globalErrorMessage);
given(stateChangeEntity.getGlobalErrors()).willReturn(globalErrors);
// when
new StateChangeContextImpl(stateChangeEntity, describer, messageService);
// then
verify(messageService).addValidationError(Mockito.any(StateChangeContext.class), Mockito.eq(FIELD_1_NAME), Mockito.eq(FIELD_1_MESSAGE_1));
verify(messageService).addValidationError(Mockito.any(StateChangeContext.class), Mockito.eq((String) null), Mockito.eq(GLOBAL_MESSAGE_1));
verify(existingStateChangeEntity).setField(describer.getStatusFieldName(), FAILURE.getStringValue());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class StateChangeContextTest method shouldNotSaveAndSetAlreadyInvalidOwnerEntity.
@Test
public final void shouldNotSaveAndSetAlreadyInvalidOwnerEntity() {
// given
given(owner.isValid()).willReturn(false);
given(ownerDD.save(owner)).willReturn(owner);
final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
given(owner.getErrors()).willReturn(fieldErrorsMap);
final List<ErrorMessage> globalErrors = Lists.newArrayList();
final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
globalErrors.add(globalErrorMessage);
given(owner.getGlobalErrors()).willReturn(globalErrors);
// when
stateChangeContext.setOwner(owner);
// then
verify(ownerDD, never()).save(owner);
verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), owner);
verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), savedOwner);
verify(messageService).addValidationError(stateChangeContext, FIELD_1_NAME, FIELD_1_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(messageService).addValidationError(stateChangeContext, null, GLOBAL_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(stateChangeEntity).setField(describer.getStatusFieldName(), StateChangeStatus.FAILURE.getStringValue());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class StateChangeContextTest method shouldMarkEntityAsInvalidAndSetStateToFailureIfStateChangeEntityIsInvalidAfterSave.
@Test
public final void shouldMarkEntityAsInvalidAndSetStateToFailureIfStateChangeEntityIsInvalidAfterSave() {
// given
final Entity savedStateChangeEntity = mock(Entity.class);
given(stateChangeEntity.isValid()).willReturn(true);
given(savedStateChangeEntity.isValid()).willReturn(true, false);
given(stateChangeDD.save(stateChangeEntity)).willReturn(savedStateChangeEntity);
final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
given(savedStateChangeEntity.getErrors()).willReturn(fieldErrorsMap);
final List<ErrorMessage> globalErrors = Lists.newArrayList();
final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
globalErrors.add(globalErrorMessage);
given(savedStateChangeEntity.getGlobalErrors()).willReturn(globalErrors);
// when
stateChangeContext.save();
// then
verify(messageService).addValidationError(stateChangeContext, FIELD_1_NAME, FIELD_1_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(messageService).addValidationError(stateChangeContext, null, GLOBAL_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(stateChangeEntity).setField(describer.getStatusFieldName(), FAILURE.getStringValue());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class StateChangeContextTest method shouldSaveButNotSetJustInvalidateOwnerEntity.
@Test
public final void shouldSaveButNotSetJustInvalidateOwnerEntity() {
// given
given(owner.isValid()).willReturn(true);
given(ownerDD.save(owner)).willReturn(savedOwner);
given(savedOwner.isValid()).willReturn(false);
final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
given(savedOwner.getErrors()).willReturn(fieldErrorsMap);
final List<ErrorMessage> globalErrors = Lists.newArrayList();
final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
globalErrors.add(globalErrorMessage);
given(savedOwner.getGlobalErrors()).willReturn(globalErrors);
// when
stateChangeContext.setOwner(owner);
// then
verify(ownerDD).save(owner);
verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), owner);
verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), savedOwner);
verify(messageService).addValidationError(stateChangeContext, FIELD_1_NAME, FIELD_1_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(messageService).addValidationError(stateChangeContext, null, GLOBAL_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(stateChangeEntity).setField(describer.getStatusFieldName(), StateChangeStatus.FAILURE.getStringValue());
}
Aggregations