Search in sources :

Example 1 with StubValidationContext

use of org.mifos.ui.validation.StubValidationContext in project head by mifos.

the class LoanAccountFormBeanTest method setUp.

@Before
public void setUp() {
    MifosBeanValidator validator = new MifosBeanValidator();
    LocalValidatorFactoryBean targetValidator = new LocalValidatorFactoryBean();
    targetValidator.afterPropertiesSet();
    validator.setTargetValidator(targetValidator);
    loanAccountFormBean = new LoanAccountFormBean();
    Integer productId = Integer.valueOf(1);
    Integer customerId = Integer.valueOf(1);
    loanAccountFormBean.setProductId(productId);
    loanAccountFormBean.setCustomerId(customerId);
    loanAccountFormBean.setPurposeOfLoanMandatory(false);
    loanAccountFormBean.setSourceOfFundsMandatory(false);
    loanAccountFormBean.setExternalIdMandatory(false);
    loanAccountFormBean.setCollateralTypeAndNotesHidden(false);
    loanAccountFormBean.setAmount(Double.valueOf("1000.0"));
    loanAccountFormBean.setMinAllowedAmount(Integer.valueOf(400));
    loanAccountFormBean.setMaxAllowedAmount(Integer.valueOf(20000));
    loanAccountFormBean.setInterestRate(Double.valueOf(10.0));
    loanAccountFormBean.setMinAllowedInterestRate(Double.valueOf(1.0));
    loanAccountFormBean.setMaxAllowedInterestRate(Double.valueOf(20.0));
    loanAccountFormBean.setDigitsBeforeDecimalForInterest(10);
    loanAccountFormBean.setDigitsAfterDecimalForInterest(5);
    loanAccountFormBean.setDigitsBeforeDecimalForMonetaryAmounts(14);
    loanAccountFormBean.setDigitsAfterDecimalForMonetaryAmounts(1);
    loanAccountFormBean.setAdditionalFees(createAdditionalFeesMocks());
    loanAccountFormBean.setDisbursementDateDD(24);
    loanAccountFormBean.setDisbursementDateMM(02);
    loanAccountFormBean.setDisbursementDateYY(2011);
    loanAccountFormBean.setNumberOfInstallments(12);
    loanAccountFormBean.setMinNumberOfInstallments(1);
    loanAccountFormBean.setMaxNumberOfInstallments(12);
    loanAccountFormBean.setValidator(validator);
    loanAccountFormBean.setLoanDisbursementDateValidationServiceFacade(loanDisbursementDateValidationServiceFacade);
    context = new StubValidationContext();
    when(loanDisbursementDateValidationServiceFacade.validateLoanDisbursementDate((LocalDate) anyObject(), anyInt(), anyInt())).thenReturn(new Errors());
}
Also used : LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) Errors(org.mifos.platform.validations.Errors) MifosBeanValidator(org.mifos.platform.validation.MifosBeanValidator) StubValidationContext(org.mifos.ui.validation.StubValidationContext) Before(org.junit.Before)

Example 2 with StubValidationContext

use of org.mifos.ui.validation.StubValidationContext 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 3 with StubValidationContext

use of org.mifos.ui.validation.StubValidationContext 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 4 with StubValidationContext

use of org.mifos.ui.validation.StubValidationContext 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

StubValidationContext (org.mifos.ui.validation.StubValidationContext)4 LocalDate (org.joda.time.LocalDate)2 Before (org.junit.Before)2 Test (org.junit.Test)2 MifosBeanValidator (org.mifos.platform.validation.MifosBeanValidator)2 ValidationContext (org.springframework.binding.validation.ValidationContext)2 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)2 BigDecimal (java.math.BigDecimal)1 ConfigurationServiceFacade (org.mifos.config.servicefacade.ConfigurationServiceFacade)1 AccountingConfigurationDto (org.mifos.config.servicefacade.dto.AccountingConfigurationDto)1 QuestionnaireServiceFacade (org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade)1 Errors (org.mifos.platform.validations.Errors)1 ValidationException (org.mifos.platform.validations.ValidationException)1 Message (org.springframework.binding.message.Message)1