Search in sources :

Example 11 with Message

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

the class LoanAccountFormBeanTest method shouldContainValidationMessageOnAmountFieldWhenAmountViolatesAllowedRange.

@Test
public void shouldContainValidationMessageOnAmountFieldWhenAmountViolatesAllowedRange() {
    // setup
    loanAccountFormBean.setAmount(Double.valueOf("0.0"));
    // 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("amount"));
    assertThat(message.getText().toString(), containsString("loanAccountFormBean.Amount.invalid"));
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 12 with Message

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

the class FundTransferFormBeanTest method testDateValidation.

@Test
public void testDateValidation() {
    FundTransferFormBean formBean = new FundTransferFormBean();
    ValidationContext validationContext = new StubValidationContext();
    formBean.setAmount(BigDecimal.ONE);
    formBean.setSourceBalance(BigDecimal.ONE);
    // invalid dates
    formBean.setTrxnDateDD("Invalid");
    formBean.setTrxnDateMM("10");
    formBean.setTrxnDateYY("2012");
    formBean.setReceiptDateDD("");
    formBean.setReceiptDateMM("11");
    formBean.setReceiptDateYY("2011");
    formBean.validateEnterDetailsStep(validationContext);
    assertEquals(validationContext.getMessageContext().getAllMessages().length, 2);
    int i = 0;
    for (Message msg : validationContext.getMessageContext().getAllMessages()) {
        if (i == 0) {
            assertEquals(msg.getSource(), "trxnDateDD");
        } else if (i == 1) {
            assertEquals(msg.getSource(), "receiptDateDD");
        }
        i++;
    }
    formBean.setTrxnDate(new LocalDate());
    formBean.setReceiptDate(null);
    validationContext.getMessageContext().clearMessages();
    formBean.validateEnterDetailsStep(validationContext);
    assertEquals(validationContext.getMessageContext().getAllMessages().length, 0);
}
Also used : Message(org.springframework.binding.message.Message) StubValidationContext(org.mifos.ui.validation.StubValidationContext) LocalDate(org.joda.time.LocalDate) ValidationContext(org.springframework.binding.validation.ValidationContext) StubValidationContext(org.mifos.ui.validation.StubValidationContext) Test(org.junit.Test)

Example 13 with Message

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

the class LoanAccountFormBeanTest method shouldContainValidationMessageOnNumberOfInstallmentsFieldWhenNumberOfInstallmentsViolatesAllowedRange.

@Test
public void shouldContainValidationMessageOnNumberOfInstallmentsFieldWhenNumberOfInstallmentsViolatesAllowedRange() {
    // setup
    loanAccountFormBean.setNumberOfInstallments(100);
    // 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("numberOfInstallments"));
    assertThat(message.getText().toString(), containsString("loanAccountFormBean.NumberOfInstallments.invalid"));
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 14 with Message

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

the class LoanAccountFormBeanTest method shouldContainValidationMessageOnAdditionalInterestFeeWhenDigitsBeforeAreOutOfRange.

@Test
public void shouldContainValidationMessageOnAdditionalInterestFeeWhenDigitsBeforeAreOutOfRange() {
    // setup
    loanAccountFormBean.setSelectedFeeId(new Number[] { 1 });
    loanAccountFormBean.setSelectedFeeAmount(new Number[] { 10000000000L });
    // exercise test
    loanAccountFormBean.validateEnterAccountDetailsStep(context);
    // verification
    Message[] messages = context.getMessageContext().getAllMessages();
    assertThat(messages.length, is(1));
    Message message = messages[0];
    assertThat(message.getSource().toString(), is("selectedFeeId"));
    assertThat(message.getText().toString(), containsString("loanAccountFormBean.additionalfees.amountOrRate.digits.before.decimal.invalid"));
}
Also used : Message(org.springframework.binding.message.Message) Test(org.junit.Test)

Example 15 with Message

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

the class CreateSavingsAccountFormBeanTest method validateAnswerQuestionGroupStepEmptyQuestionGroupShouldPass.

@Test
public void validateAnswerQuestionGroupStepEmptyQuestionGroupShouldPass() {
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    formBean.setQuestionGroups(questionGroups);
    formBean.validateAnswerQuestionGroupStep(validationContext);
    MessageContext messageContext = validationContext.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    Assert.assertEquals(0, 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)

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