Search in sources :

Example 41 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-data-commons by spring-projects.

the class DomainClassConverterIntegrationTests method findsRepositoryFactories.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void findsRepositoryFactories() {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory() {

        @Override
        protected BeanWrapper instantiateBean(String beanName, RootBeanDefinition mbd) {
            return beanName.equals("repoFactory") ? new BeanWrapperImpl(factory) : super.instantiateBean(beanName, mbd);
        }
    };
    beanFactory.registerBeanDefinition("postProcessor", new RootBeanDefinition(PredictingProcessor.class));
    beanFactory.registerBeanDefinition("repoFactory", new RootBeanDefinition(RepositoryFactoryBeanSupport.class));
    doReturn(Person.class).when(information).getDomainType();
    doReturn(Serializable.class).when(information).getIdType();
    doReturn(PersonRepository.class).when(factory).getObjectType();
    doReturn(information).when(factory).getRepositoryInformation();
    GenericApplicationContext context = new GenericApplicationContext(beanFactory);
    context.refresh();
    assertThat(context.getBeansOfType(RepositoryFactoryInformation.class).values()).hasSize(1);
    DomainClassConverter converter = new DomainClassConverter(new DefaultConversionService());
    converter.setApplicationContext(context);
    assertThat(converter.matches(TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Person.class))).isTrue();
}
Also used : RepositoryFactoryBeanSupport(org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RepositoryFactoryInformation(org.springframework.data.repository.core.support.RepositoryFactoryInformation) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.Test)

Example 42 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-data-commons by spring-projects.

the class CustomConversionsUnitTests method populatesConversionServiceCorrectly.

// DATACMNS-1035
@Test
public void populatesConversionServiceCorrectly() {
    GenericConversionService conversionService = new DefaultConversionService();
    CustomConversions conversions = new CustomConversions(StoreConversions.NONE, Arrays.asList(StringToFormatConverter.INSTANCE));
    conversions.registerConvertersIn(conversionService);
    assertThat(conversionService.canConvert(String.class, Format.class), is(true));
}
Also used : Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) Test(org.junit.Test)

Example 43 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-data-commons by spring-projects.

the class CustomConversionsUnitTests method customConverterOverridesDefault.

// DATAMONGO-881, DATACMNS-1035
@Test
public void customConverterOverridesDefault() {
    CustomConversions conversions = new CustomConversions(StoreConversions.NONE, Arrays.asList(CustomDateTimeConverter.INSTANCE));
    GenericConversionService conversionService = new DefaultConversionService();
    conversions.registerConvertersIn(conversionService);
    assertThat(conversionService.convert(new DateTime(), Date.class)).isEqualTo(new Date(0));
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) DateTime(org.joda.time.DateTime) LocalDateTime(org.threeten.bp.LocalDateTime) Date(java.util.Date) Test(org.junit.Test)

Example 44 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project molgenis by molgenis.

the class PlatformITConfig method conversionService.

@Bean
public ConversionService conversionService() {
    DefaultConversionService defaultConversionService = new DefaultConversionService();
    defaultConversionService.addConverter(new StringToDateConverter());
    defaultConversionService.addConverter(new StringToDateTimeConverter());
    return defaultConversionService;
}
Also used : StringToDateTimeConverter(org.molgenis.data.convert.StringToDateTimeConverter) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) StringToDateConverter(org.molgenis.data.convert.StringToDateConverter)

Example 45 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project molgenis by molgenis.

the class AclConfig method aclClassIdUtils.

@Bean
public AclClassIdUtils aclClassIdUtils() {
    AclClassIdUtils aclClassIdUtils = new AclClassIdUtils();
    aclClassIdUtils.setConversionService(new DefaultConversionService());
    return aclClassIdUtils;
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)84 Test (org.junit.jupiter.api.Test)37 Test (org.junit.Test)29 ConversionService (org.springframework.core.convert.ConversionService)13 MethodParameter (org.springframework.core.MethodParameter)12 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)12 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)12 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)12 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)11 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 RequestParam (org.springframework.web.bind.annotation.RequestParam)9 Optional (java.util.Optional)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)6 HashMap (java.util.HashMap)5 DefaultDatatypeChannelMessageConverter (org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 Before (org.junit.Before)4 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)3 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3