Search in sources :

Example 1 with Message

use of org.springframework.binding.message.Message in project head by mifos.

the class LoanAccountFormBeanTest method shouldContainValidationMessageOnSourceOfFundsFieldWhenFieldIsMandatoryAndNotSelected.

@Test
public void shouldContainValidationMessageOnSourceOfFundsFieldWhenFieldIsMandatoryAndNotSelected() {
    // setup
    loanAccountFormBean.setSourceOfFundsMandatory(true);
    loanAccountFormBean.setFundId(null);
    // exercise test
    loanAccountFormBean.validateEnterAccountDetailsStep(context);
    // verification
    MessageContext messageContext = context.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    assertThat(messages.length, is(1));
    Message message = messages[0];
    assertThat(message.getSource().toString(), is("fundId"));
    assertThat(message.getText().toString(), containsString("loanAccountFormBean.SourceOfFunds.invalid"));
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 2 with Message

use of org.springframework.binding.message.Message in project head by mifos.

the class CreateSavingsAccountFormBeanTest method validateCustomerSearchStepEmptySearchStringShouldFail.

@Test
public void validateCustomerSearchStepEmptySearchStringShouldFail() {
    formBean.validateCustomerSearchStep(validationContext);
    MessageContext messageContext = validationContext.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    Assert.assertEquals(1, messages.length);
    Message message = messages[0];
    Assert.assertEquals("searchString", message.getSource());
    verifyErrorMessage(NotEmpty.class, message);
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 3 with Message

use of org.springframework.binding.message.Message in project head by mifos.

the class CreateSavingsAccountFormBeanTest method validateAnswerQuestionGroupStepMissingMandatoryResponseShouldFail.

@Test
public void validateAnswerQuestionGroupStepMissingMandatoryResponseShouldFail() {
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    formBean.setQuestionGroups(questionGroups);
    doThrow(validationException).when(questionnaireServiceFacade).validateResponses(formBean.getQuestionGroups());
    formBean.validateAnswerQuestionGroupStep(validationContext);
    MessageContext messageContext = validationContext.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    Assert.assertEquals(1, messages.length);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) Message(org.springframework.binding.message.Message) ArrayList(java.util.ArrayList) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 4 with Message

use of org.springframework.binding.message.Message in project head by mifos.

the class CreateSavingsAccountFormBeanTest method validateSelectProductOfferingStepNonEmptyProductIdShouldPass.

@Test
public void validateSelectProductOfferingStepNonEmptyProductIdShouldPass() {
    formBean.setProductId(1);
    formBean.validateSelectProductOfferingStep(validationContext);
    MessageContext messageContext = validationContext.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    Assert.assertEquals(0, messages.length);
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 5 with Message

use of org.springframework.binding.message.Message in project head by mifos.

the class CreateSavingsAccountFormBeanTest method validateEnterAccountDetailsStepMandatoryDeposit.

private void validateEnterAccountDetailsStepMandatoryDeposit(String amount, @SuppressWarnings("rawtypes") Map<String, Class> expectedViolations, boolean expectingPass) {
    setDepositType(formBean, CreateSavingsAccountFormBean.MANDATORY_DEPOSIT);
    formBean.setMandatoryDepositAmount(amount);
    formBean.validateEnterAccountDetailsStep(validationContext);
    MessageContext messageContext = validationContext.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    if (expectingPass) {
        Assert.assertEquals(0, messages.length);
        return;
    } else {
        Assert.assertEquals(expectedViolations.size(), messages.length);
        for (Message message : messages) {
            Assert.assertEquals("mandatoryDepositAmount", message.getSource());
            String reason = message.getText().substring(0, message.getText().indexOf("."));
            Assert.assertTrue(expectedViolations.containsKey(reason));
            verifyErrorMessage(expectedViolations.get(reason), message);
        }
    }
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext)

Aggregations

Message (org.springframework.binding.message.Message)20 Test (org.junit.Test)16 MessageContext (org.springframework.binding.message.MessageContext)16 ArrayList (java.util.ArrayList)3 LocalDate (org.joda.time.LocalDate)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 BigDecimal (java.math.BigDecimal)1 DateTime (org.joda.time.DateTime)1 VariableInstallmentWithFeeValidationResult (org.mifos.clientportfolio.newloan.applicationservice.VariableInstallmentWithFeeValidationResult)1 ErrorEntry (org.mifos.platform.validations.ErrorEntry)1 ValidationException (org.mifos.platform.validations.ValidationException)1 StubMessageContext (org.mifos.ui.validation.StubMessageContext)1 StubValidationContext (org.mifos.ui.validation.StubValidationContext)1 MessageBuilder (org.springframework.binding.message.MessageBuilder)1 MessageCriteria (org.springframework.binding.message.MessageCriteria)1 ValidationContext (org.springframework.binding.validation.ValidationContext)1 Errors (org.springframework.validation.Errors)1 FieldError (org.springframework.validation.FieldError)1