use of org.springframework.web.bind.support.DefaultDataBinderFactory in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolverTests method wrapEmptyWithOptional.
@Test
public void wrapEmptyWithOptional() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
assertEquals(Optional.empty(), resolver.resolveArgument(paramOptional, mavContainer, webRequest, binderFactory));
}
use of org.springframework.web.bind.support.DefaultDataBinderFactory in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolverTests method resolveArgumentWrappedAsOptional.
@Test
public void resolveArgumentWrappedAsOptional() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name", "value");
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
@SuppressWarnings("unchecked") Optional<String> result = (Optional<String>) resolver.resolveArgument(paramOptional, mavContainer, webRequest, binderFactory);
assertEquals("PathVariable not resolved correctly", "value", result.get());
@SuppressWarnings("unchecked") Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(View.PATH_VARIABLES);
assertNotNull(pathVars);
assertEquals(1, pathVars.size());
assertEquals(Optional.of("value"), pathVars.get("name"));
}
use of org.springframework.web.bind.support.DefaultDataBinderFactory in project spring-framework by spring-projects.
the class ModelFactoryOrderingTests method runTest.
private void runTest(Object controller) throws Exception {
HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
resolvers.addResolver(new ModelAttributeMethodProcessor(false));
resolvers.addResolver(new ModelMethodProcessor());
WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);
Class<?> type = controller.getClass();
Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
for (Method method : methods) {
InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
modelMethod.setHandlerMethodArgumentResolvers(resolvers);
modelMethod.setDataBinderFactory(dataBinderFactory);
modelMethods.add(modelMethod);
}
Collections.shuffle(modelMethods);
SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
if (logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
for (String name : getInvokedMethods()) {
sb.append(" >> ").append(name);
}
logger.debug(sb);
}
}
use of org.springframework.web.bind.support.DefaultDataBinderFactory 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.web.bind.support.DefaultDataBinderFactory in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method optionalMultipartFileWithoutMultipartRequest.
@Test
public void optionalMultipartFileWithoutMultipartRequest() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertEquals(Optional.empty(), actual);
}
Aggregations