Search in sources :

Example 1 with ValidationContext

use of org.springframework.binding.validation.ValidationContext 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 2 with ValidationContext

use of org.springframework.binding.validation.ValidationContext in project head by mifos.

the class FundTransferFormBeanTest method testAmountValidation.

@Test
public void testAmountValidation() {
    FundTransferFormBean formBean = new FundTransferFormBean();
    ValidationContext validationContext = new StubValidationContext();
    formBean.setSourceBalance(new BigDecimal("100"));
    formBean.setTrxnDate(new LocalDate());
    // amount bigger then balance
    formBean.setAmount(new BigDecimal("200"));
    formBean.validateEnterDetailsStep(validationContext);
    assertEquals(validationContext.getMessageContext().getAllMessages().length, 1);
    // proper amount
    formBean.setAmount(new BigDecimal("100"));
    formBean.validateEnterDetailsStep(validationContext);
    validationContext.getMessageContext().clearMessages();
    assertEquals(validationContext.getMessageContext().getAllMessages().length, 0);
}
Also used : StubValidationContext(org.mifos.ui.validation.StubValidationContext) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) ValidationContext(org.springframework.binding.validation.ValidationContext) StubValidationContext(org.mifos.ui.validation.StubValidationContext) Test(org.junit.Test)

Aggregations

LocalDate (org.joda.time.LocalDate)2 Test (org.junit.Test)2 StubValidationContext (org.mifos.ui.validation.StubValidationContext)2 ValidationContext (org.springframework.binding.validation.ValidationContext)2 BigDecimal (java.math.BigDecimal)1 Message (org.springframework.binding.message.Message)1