Search in sources :

Example 26 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class CreateSavingsAccountFormBeanTest method setUp.

@Before
public void setUp() {
    MifosBeanValidator validator = new MifosBeanValidator();
    LocalValidatorFactoryBean targetValidator = new LocalValidatorFactoryBean();
    targetValidator.afterPropertiesSet();
    validator.setTargetValidator(targetValidator);
    formBean = new CreateSavingsAccountFormBean();
    formBean.setValidator(validator);
    questionnaireServiceFacade = mock(QuestionnaireServiceFacade.class);
    formBean.setQuestionnaireServiceFascade(questionnaireServiceFacade);
    configurationDto = new AccountingConfigurationDto();
    configurationDto.setDigitsBeforeDecimal((short) 14);
    configurationDto.setDigitsAfterDecimal((short) 1);
    configurationServiceFacade = mock(ConfigurationServiceFacade.class);
    when(configurationServiceFacade.getAccountingConfiguration()).thenReturn(configurationDto);
    formBean.setConfigurationServiceFacade(configurationServiceFacade);
    validationContext = new StubValidationContext();
    validationException = new ValidationException("Root");
    validationException.addChildException(new ValidationException("Child"));
}
Also used : LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) ValidationException(org.mifos.platform.validations.ValidationException) MifosBeanValidator(org.mifos.platform.validation.MifosBeanValidator) AccountingConfigurationDto(org.mifos.config.servicefacade.dto.AccountingConfigurationDto) StubValidationContext(org.mifos.ui.validation.StubValidationContext) QuestionnaireServiceFacade(org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade) ConfigurationServiceFacade(org.mifos.config.servicefacade.ConfigurationServiceFacade) Before(org.junit.Before)

Example 27 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class ValidationExceptionMessageExtractorTest method testBadNumericResponseException.

private void testBadNumericResponseException(BadNumericResponseException e, String expectedMessage) {
    ValidationException parent = new ValidationException("Key");
    parent.addChildException(e);
    ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
    MessageContext context = new StubMessageContext();
    extractor.extract(context, parent);
    Message[] messages = context.getAllMessages();
    Assert.assertEquals(1, messages.length);
    Message m = messages[0];
    Assert.assertEquals(expectedMessage, m.getText());
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) Message(org.springframework.binding.message.Message) StubMessageContext(org.mifos.ui.validation.StubMessageContext) StubMessageContext(org.mifos.ui.validation.StubMessageContext) MessageContext(org.springframework.binding.message.MessageContext)

Example 28 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class ValidationExceptionMessageExtractorTest method testValidationException.

@Test
public void testValidationException() {
    ValidationException parent = new ValidationException("Key 1");
    ValidationException child = new ValidationException("Key 2");
    parent.addChildException(child);
    ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
    extractor.extract(context, parent);
    verify(context).addMessage(any(MessageResolver.class));
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) MessageResolver(org.springframework.binding.message.MessageResolver) Test(org.junit.Test)

Example 29 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorTest method shouldNotThrowExceptionWhenANumericQuestionWithNoBoundsHasAnswer.

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldNotThrowExceptionWhenANumericQuestionWithNoBoundsHasAnswer() {
    QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", null, null);
    SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "121");
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client", asList(sectionWithOneQuestion));
    try {
        questionnaireValidator.validateForQuestionGroupResponses(asList(questionGroupDetail));
    } catch (ValidationException e) {
        fail("Should not have thrown the validation exception");
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ValidationException(org.mifos.platform.validations.ValidationException) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 30 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentChoices.

@Test
public void shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentChoices() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    String questionTitle = questionGroupDto.getSections().get(0).getQuestions().get(1).getText();
    List<QuestionChoiceEntity> choices = asList(getChoice("Ch2"), getChoice("Ch3"), getChoice("Ch0"));
    when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.SINGLESELECT, choices)));
    try {
        questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
        fail("Should have thrown validationException");
    } catch (ValidationException e) {
        assertThat(e.getKey(), is(GENERIC_VALIDATION));
        assertThat(e.hasChildExceptions(), is(true));
        List<ValidationException> childExceptions = e.getChildExceptions();
        assertThat(childExceptions, is(notNullValue()));
        assertThat(childExceptions.size(), is(1));
        assertThat(childExceptions.get(0).getKey(), is(QUESTION_TITILE_MATCHES_EXISTING_QUESTION));
    }
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Aggregations

ValidationException (org.mifos.platform.validations.ValidationException)58 Test (org.junit.Test)48 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)30 Arrays.asList (java.util.Arrays.asList)27 List (java.util.List)27 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)8 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)7 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)6 MandatoryAnswerNotFoundException (org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException)6 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)5 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 QuestionnaireServiceFacade (org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade)2 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)2 MessageResolver (org.springframework.binding.message.MessageResolver)2 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 Before (org.junit.Before)1