use of cn.taketoday.core.conversion.support.DefaultConversionService in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBeanFactoryConversionServiceAndConverterBean.
@Test
void loadWhenBeanFactoryConversionServiceAndConverterBean() {
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new AlienConverter());
this.context.getBeanFactory().setConversionService(conversionService);
load(new Class<?>[] { ConverterConfiguration.class, PersonAndAlienProperties.class }, "test.person=John Smith", "test.alien=Alf Tanner");
PersonAndAlienProperties properties = this.context.getBean(PersonAndAlienProperties.class);
assertThat(properties.getPerson().firstName).isEqualTo("John");
assertThat(properties.getPerson().lastName).isEqualTo("Smith");
assertThat(properties.getAlien().firstName).isEqualTo("Alf");
assertThat(properties.getAlien().lastName).isEqualTo("Tanner");
}
use of cn.taketoday.core.conversion.support.DefaultConversionService in project today-infrastructure by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method optionalPropertyWithValue.
@Test
public void optionalPropertyWithValue() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.setConversionService(new DefaultConversionService());
bf.registerBeanDefinition("testBean", genericBeanDefinition(OptionalTestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
MockEnvironment env = new MockEnvironment();
env.setProperty("my.name", "myValue");
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setEnvironment(env);
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(OptionalTestBean.class).getName()).isEqualTo(Optional.of("myValue"));
}
use of cn.taketoday.core.conversion.support.DefaultConversionService in project today-infrastructure by TAKETODAY.
the class AbstractPropertyResolver method getConversionService.
@Override
public ConfigurableConversionService getConversionService() {
// Need to provide an independent DefaultConversionService, not the
// shared DefaultConversionService used by PropertySourcesPropertyResolver.
ConfigurableConversionService cs = this.conversionService;
if (cs == null) {
synchronized (this) {
cs = this.conversionService;
if (cs == null) {
cs = new DefaultConversionService();
this.conversionService = cs;
}
}
}
return cs;
}
use of cn.taketoday.core.conversion.support.DefaultConversionService in project today-infrastructure by TAKETODAY.
the class ObjectToStringHttpMessageConverterTests method defaultCharsetModified.
@Test
public void defaultCharsetModified() throws IOException {
ConversionService cs = new DefaultConversionService();
ObjectToStringHttpMessageConverter converter = new ObjectToStringHttpMessageConverter(cs, StandardCharsets.UTF_16);
converter.write((byte) 31, null, this.response);
assertThat(this.servletResponse.getCharacterEncoding()).isEqualTo("UTF-16");
}
use of cn.taketoday.core.conversion.support.DefaultConversionService in project today-infrastructure by TAKETODAY.
the class MapBinderTests method bindToMapWithCustomConverterAndChildElements.
@Test
void bindToMapWithCustomConverterAndChildElements() {
// gh-11892
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new MapConverter());
Binder binder = new Binder(this.sources, null, conversionService, null);
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "boom");
source.put("foo.a", "a");
source.put("foo.b", "b");
this.sources.add(source);
Map<String, String> map = binder.bind("foo", STRING_STRING_MAP).get();
assertThat(map.get("a")).isEqualTo("a");
assertThat(map.get("b")).isEqualTo("b");
}
Aggregations