Package net.petrikainulainen.spring.testmvc.todo.dto

Examples of net.petrikainulainen.spring.testmvc.todo.dto.FormValidationErrorDTO


        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_EMPTY_TODO_TITLE);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_TOO_LONG_DESCRIPTION);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();

        assertEquals(2, fieldErrorDTOs.size());

        FieldValidationErrorDTO titleFieldErrorDTO = fieldErrorDTOs.get(0);
        assertEquals(FIELD_TITLE, titleFieldErrorDTO.getPath());
View Full Code Here


        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_CODE_EMPTY_TITLE);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_EMPTY_TODO_TITLE);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();

        assertEquals(1, fieldErrorDTOs.size());

        FieldValidationErrorDTO titleFieldErrorDTO = fieldErrorDTOs.get(0);
        assertEquals(FIELD_TITLE, titleFieldErrorDTO.getPath());
View Full Code Here

        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();

        assertEquals(2, fieldErrorDTOs.size());

        FieldValidationErrorDTO titleFieldErrorDTO = fieldErrorDTOs.get(0);
        assertEquals(FIELD_TITLE, titleFieldErrorDTO.getPath());
View Full Code Here

        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(null);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US)).thenReturn(null);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();

        assertEquals(2, fieldErrorDTOs.size());

        FieldValidationErrorDTO titleFieldErrorDTO = fieldErrorDTOs.get(0);
        assertEquals(FIELD_TITLE, titleFieldErrorDTO.getPath());
View Full Code Here

        Locale current = localeHolderWrapper.getCurrentLocale();

        List<FieldError> fieldErrors = validationError.getFieldErrors();

        FormValidationErrorDTO dto = new FormValidationErrorDTO();

        for (FieldError fieldError: fieldErrors) {
            String[] fieldErrorCodes = fieldError.getCodes();
            for (int index = 0; index < fieldErrorCodes.length; index++) {
                String fieldErrorCode = fieldErrorCodes[index];

                String localizedError = messageSource.getMessage(fieldErrorCode, fieldError.getArguments(), current);
                if (localizedError != null && !localizedError.equals(fieldErrorCode)) {
                    LOGGER.debug("Adding error message: {} to field: {}", localizedError, fieldError.getField());
                    dto.addFieldError(fieldError.getField(), localizedError);
                    break;
                }
                else {
                    if (isLastFieldErrorCode(index, fieldErrorCodes)) {
                        dto.addFieldError(fieldError.getField(), localizedError);
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of net.petrikainulainen.spring.testmvc.todo.dto.FormValidationErrorDTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.