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);
}
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);
}
Aggregations