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);
}
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);
}
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());
}
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);
}
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();
}
Aggregations