use of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean 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());
}
use of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean 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"));
}
use of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean in project irida by phac-nml.
the class IridaApiServicesConfig method validator.
@Bean
public Validator validator() {
ResourceBundleMessageSource validatorMessageSource = new ResourceBundleMessageSource();
validatorMessageSource.setBasename("ValidationMessages");
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setValidationMessageSource(validatorMessageSource);
return validator;
}
use of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method requestMappingHandlerAdapter.
@Test
public void requestMappingHandlerAdapter() {
ApplicationContext context = initContext(WebConfig.class);
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertThat(converters.size()).isEqualTo(12);
converters.stream().filter(converter -> converter instanceof AbstractJackson2HttpMessageConverter).forEach(converter -> {
ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
assertThat(mapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION)).isFalse();
assertThat(mapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION)).isFalse();
assertThat(mapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
assertThat(mapper.getClass()).isEqualTo(XmlMapper.class);
}
});
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
assertThat(initializer).isNotNull();
ConversionService conversionService = initializer.getConversionService();
assertThat(conversionService).isNotNull();
boolean condition1 = conversionService instanceof FormattingConversionService;
assertThat(condition1).isTrue();
Validator validator = initializer.getValidator();
assertThat(validator).isNotNull();
boolean condition = validator instanceof LocalValidatorFactoryBean;
assertThat(condition).isTrue();
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
@SuppressWarnings("unchecked") List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
assertThat(bodyAdvice.size()).isEqualTo(2);
assertThat(bodyAdvice.get(0).getClass()).isEqualTo(JsonViewRequestBodyAdvice.class);
assertThat(bodyAdvice.get(1).getClass()).isEqualTo(JsonViewResponseBodyAdvice.class);
}
use of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean in project spring-framework by spring-projects.
the class DelegatingWebFluxConfigurationTests method requestMappingHandlerAdapter.
@Test
public void requestMappingHandlerAdapter() {
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
ReactiveAdapterRegistry reactiveAdapterRegistry = delegatingConfig.webFluxAdapterRegistry();
ServerCodecConfigurer serverCodecConfigurer = delegatingConfig.serverCodecConfigurer();
FormattingConversionService formattingConversionService = delegatingConfig.webFluxConversionService();
Validator validator = delegatingConfig.webFluxValidator();
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) this.delegatingConfig.requestMappingHandlerAdapter(reactiveAdapterRegistry, serverCodecConfigurer, formattingConversionService, validator).getWebBindingInitializer();
verify(webFluxConfigurer).configureHttpMessageCodecs(codecsConfigurer.capture());
verify(webFluxConfigurer).getValidator();
verify(webFluxConfigurer).getMessageCodesResolver();
verify(webFluxConfigurer).addFormatters(formatterRegistry.capture());
verify(webFluxConfigurer).configureArgumentResolvers(any());
assertThat(initializer).isNotNull();
boolean condition = initializer.getValidator() instanceof LocalValidatorFactoryBean;
assertThat(condition).isTrue();
assertThat(initializer.getConversionService()).isSameAs(formatterRegistry.getValue());
assertThat(codecsConfigurer.getValue().getReaders().size()).isEqualTo(14);
}
Aggregations