Search in sources :

Example 1 with ApplicationConversionService

use of cn.taketoday.format.support.ApplicationConversionService in project today-framework by TAKETODAY.

the class BeanFactoryTests method beforeEach.

@BeforeEach
public void beforeEach() throws IOException {
    context = new StandardApplicationContext();
    ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
    processor.setPropertiesLocation("info.properties");
    processor.postProcessEnvironment();
    context.scan("cn.taketoday.beans.factory", "test.demo.config");
    context.refresh();
    beanFactory = context.getBeanFactory();
    beanFactory.setConversionService(new ApplicationConversionService());
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ApplicationConversionService

use of cn.taketoday.format.support.ApplicationConversionService in project today-framework by TAKETODAY.

the class ConversionServiceDeducerTests method getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBeanFactoryConversionServiceContainsOnlyBeanFactoryInstance.

@Test
void getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBeanFactoryConversionServiceContainsOnlyBeanFactoryInstance() {
    ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
    ConversionService conversionService = new ApplicationConversionService();
    applicationContext.getBeanFactory().setConversionService(conversionService);
    ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext);
    List<ConversionService> conversionServices = deducer.getConversionServices();
    assertThat(conversionServices).containsOnly(conversionService);
    assertThat(conversionServices.get(0)).isSameAs(conversionService);
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) ConversionService(cn.taketoday.core.conversion.ConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) Test(org.junit.jupiter.api.Test)

Example 3 with ApplicationConversionService

use of cn.taketoday.format.support.ApplicationConversionService in project today-framework by TAKETODAY.

the class ConversionServiceDeducer method getConversionServices.

private List<ConversionService> getConversionServices(ConfigurableApplicationContext applicationContext) {
    List<ConversionService> conversionServices = new ArrayList<>();
    if (applicationContext.getBeanFactory().getConversionService() != null) {
        conversionServices.add(applicationContext.getBeanFactory().getConversionService());
    }
    ConverterBeans converterBeans = new ConverterBeans(applicationContext);
    if (!converterBeans.isEmpty()) {
        ApplicationConversionService beansConverterService = new ApplicationConversionService();
        converterBeans.addTo(beansConverterService);
        conversionServices.add(beansConverterService);
    }
    return conversionServices;
}
Also used : ConversionService(cn.taketoday.core.conversion.ConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) ArrayList(java.util.ArrayList) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService)

Example 4 with ApplicationConversionService

use of cn.taketoday.format.support.ApplicationConversionService in project today-infrastructure by TAKETODAY.

the class ConversionServiceDeducer method getConversionServices.

private List<ConversionService> getConversionServices(ConfigurableApplicationContext applicationContext) {
    List<ConversionService> conversionServices = new ArrayList<>();
    if (applicationContext.getBeanFactory().getConversionService() != null) {
        conversionServices.add(applicationContext.getBeanFactory().getConversionService());
    }
    ConverterBeans converterBeans = new ConverterBeans(applicationContext);
    if (!converterBeans.isEmpty()) {
        ApplicationConversionService beansConverterService = new ApplicationConversionService();
        converterBeans.addTo(beansConverterService);
        conversionServices.add(beansConverterService);
    }
    return conversionServices;
}
Also used : ConversionService(cn.taketoday.core.conversion.ConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) ArrayList(java.util.ArrayList) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService)

Example 5 with ApplicationConversionService

use of cn.taketoday.format.support.ApplicationConversionService in project today-infrastructure by TAKETODAY.

the class ConversionServiceDeducerTests method getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBeanFactoryConversionServiceContainsOnlyBeanFactoryInstance.

@Test
void getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBeanFactoryConversionServiceContainsOnlyBeanFactoryInstance() {
    ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
    ConversionService conversionService = new ApplicationConversionService();
    applicationContext.getBeanFactory().setConversionService(conversionService);
    ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext);
    List<ConversionService> conversionServices = deducer.getConversionServices();
    assertThat(conversionServices).containsOnly(conversionService);
    assertThat(conversionServices.get(0)).isSameAs(conversionService);
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) ConversionService(cn.taketoday.core.conversion.ConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationConversionService (cn.taketoday.format.support.ApplicationConversionService)5 ConversionService (cn.taketoday.core.conversion.ConversionService)4 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 ApplicationPropertySourcesProcessor (cn.taketoday.context.support.ApplicationPropertySourcesProcessor)1 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1