Search in sources :

Example 11 with DefaultFormattingConversionService

use of org.springframework.format.support.DefaultFormattingConversionService in project spring-framework by spring-projects.

the class RedirectAttributesModelMapTests method setup.

@Before
public void setup() {
    this.conversionService = new DefaultFormattingConversionService();
    DataBinder dataBinder = new DataBinder(null);
    dataBinder.setConversionService(conversionService);
    this.redirectAttributes = new RedirectAttributesModelMap(dataBinder);
}
Also used : DataBinder(org.springframework.validation.DataBinder) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Before(org.junit.Before)

Example 12 with DefaultFormattingConversionService

use of org.springframework.format.support.DefaultFormattingConversionService in project spring-framework by spring-projects.

the class RequestHeaderMethodArgumentResolverTests method instantConversion.

@Test
public void instantConversion() throws Exception {
    String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
    servletRequest.addHeader("name", rfc1123val);
    ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
    bindingInitializer.setConversionService(new DefaultFormattingConversionService());
    Object result = resolver.resolveArgument(paramInstant, null, webRequest, new DefaultDataBinderFactory(bindingInitializer));
    assertTrue(result instanceof Instant);
    assertEquals(Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(rfc1123val)), result);
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) Instant(java.time.Instant) DefaultDataBinderFactory(org.springframework.web.bind.support.DefaultDataBinderFactory) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Test(org.junit.Test)

Example 13 with DefaultFormattingConversionService

use of org.springframework.format.support.DefaultFormattingConversionService in project spring-framework by spring-projects.

the class SessionAttributeMethodArgumentResolverTests method resolveOptional.

@Test
public void resolveOptional() throws Exception {
    MethodParameter param = initMethodParameter(3);
    Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
    assertNotNull(mono.block());
    assertEquals(Optional.class, mono.block().getClass());
    assertFalse(((Optional<?>) mono.block()).isPresent());
    ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
    initializer.setConversionService(new DefaultFormattingConversionService());
    BindingContext bindingContext = new BindingContext(initializer);
    Foo foo = new Foo();
    when(this.session.getAttribute("foo")).thenReturn(Optional.of(foo));
    mono = this.resolver.resolveArgument(param, bindingContext, this.exchange);
    assertNotNull(mono.block());
    assertEquals(Optional.class, mono.block().getClass());
    Optional<?> optional = (Optional<?>) mono.block();
    assertTrue(optional.isPresent());
    assertSame(foo, optional.get());
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) Optional(java.util.Optional) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) BindingContext(org.springframework.web.reactive.BindingContext) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Test(org.junit.Test)

Example 14 with DefaultFormattingConversionService

use of org.springframework.format.support.DefaultFormattingConversionService in project spring-framework by spring-projects.

the class RequestParamMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
    this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, true);
    ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
    initializer.setConversionService(new DefaultFormattingConversionService());
    this.bindContext = new BindingContext(initializer);
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) BindingContext(org.springframework.web.reactive.BindingContext) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Before(org.junit.Before)

Example 15 with DefaultFormattingConversionService

use of org.springframework.format.support.DefaultFormattingConversionService in project spring-mvc-showcase by spring-projects.

the class ConvertControllerTests method setup.

@Before
public void setup() throws Exception {
    FormattingConversionService cs = new DefaultFormattingConversionService();
    cs.addFormatterForFieldAnnotation(new MaskFormatAnnotationFormatterFactory());
    this.mockMvc = standaloneSetup(new ConvertController()).setConversionService(cs).alwaysExpect(status().isOk()).build();
}
Also used : FormattingConversionService(org.springframework.format.support.FormattingConversionService) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Before(org.junit.Before)

Aggregations

DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)16 Test (org.junit.Test)8 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)7 BindingContext (org.springframework.web.reactive.BindingContext)6 Before (org.junit.Before)4 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)3 FormattingConversionService (org.springframework.format.support.FormattingConversionService)3 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 MethodParameter (org.springframework.core.MethodParameter)2 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)2 ConversionService (org.springframework.core.convert.ConversionService)2 WebDataBinder (org.springframework.web.bind.WebDataBinder)2 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)2 Method (java.lang.reflect.Method)1 Instant (java.time.Instant)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 CasConfigurationEmbeddedValueResolver (org.apereo.cas.config.support.CasConfigurationEmbeddedValueResolver)1