org.springframework.web.bind.support.DefaultDataBinderFactory Java Examples

The following examples show how to use org.springframework.web.bind.support.DefaultDataBinderFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PathVariableMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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"));
}
 
Example #2
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptional() throws Exception {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());
	WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

	Object result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(Optional.empty(), result);

	this.request.addParameter("name", "123");
	result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(123, ((Optional) result).get());
}
 
Example #3
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolveOptionalMultipartFile() throws Exception {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());
	WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
	request.addFile(expected);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);

	assertTrue(result instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional<?>) result).get());
}
 
Example #4
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamList() 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, List.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	request.addParameter("name", "123", "456");
	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(Arrays.asList("123", "456"), ((Optional) result).get());
}
 
Example #5
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamArray() 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, Integer[].class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	request.addParameter("name", "123", "456");
	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertArrayEquals(new Integer[] {123, 456}, (Integer[]) ((Optional) result).get());
}
 
Example #6
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamValue() 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, Integer.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	request.addParameter("name", "123");
	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(123, ((Optional) result).get());
}
 
Example #7
Source File: PathVariableMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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"));
}
 
Example #8
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolveOptionalMultipartFile() throws Exception {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());
	WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
	request.addFile(expected);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);

	assertTrue(result instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional<?>) result).get());
}
 
Example #9
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamList() 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, List.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	request.addParameter("name", "123", "456");
	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(Arrays.asList("123", "456"), ((Optional) result).get());
}
 
Example #10
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamValue() 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, Integer.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	request.addParameter("name", "123");
	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(123, ((Optional) result).get());
}
 
Example #11
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamArray() 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, Integer[].class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	request.addParameter("name", "123", "456");
	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertArrayEquals(new Integer[] {123, 456}, (Integer[]) ((Optional) result).get());
}
 
Example #12
Source File: PathVariableMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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));
}
 
Example #13
Source File: JseHandlerMethodArgumentResolverTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    MockServletContext sc = new MockServletContext();
    request = new MockHttpServletRequest(sc);
    webRequest = new ServletWebRequest(request);
    RequestContextHolder.setRequestAttributes(webRequest);
    request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    factory = new DefaultDataBinderFactory(new ConfigurableWebBindingInitializer());
}
 
Example #14
Source File: SpringParameterProvider.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T provide(Method method, int parameterIndex) {
    MethodParameter methodParameter = new MethodParameter(method, parameterIndex);
    ModelAndViewContainer modelAndViewContainer = new ModelAndViewContainer();
    NativeWebRequest webRequest = new ServletWebRequest(request);
    DefaultDataBinderFactory binderFactory = new DefaultDataBinderFactory(new ConfigurableWebBindingInitializer());

    try {
        return (T) argumentResolvers.resolveArgument(methodParameter, modelAndViewContainer, webRequest, binderFactory);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #15
Source File: InitBinderDataBinderFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private WebDataBinderFactory createBinderFactory(String methodName, Class<?>... parameterTypes)
		throws Exception {

	Object handler = new InitBinderHandler();
	Method method = handler.getClass().getMethod(methodName, parameterTypes);

	InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
	handlerMethod.setHandlerMethodArgumentResolvers(argumentResolvers);
	handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
	handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new InitBinderDataBinderFactory(Arrays.asList(handlerMethod), bindingInitializer);
}
 
Example #16
Source File: ModelFactoryOrderingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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<InvocableHandlerMethod>();
	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);
	}
}
 
Example #17
Source File: RequestMappingHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private InvocableHandlerMethod createInitBinderMethod(Object bean, Method method) {
	InvocableHandlerMethod binderMethod = new InvocableHandlerMethod(bean, method);
	if (this.initBinderArgumentResolvers != null) {
		binderMethod.setHandlerMethodArgumentResolvers(this.initBinderArgumentResolvers);
	}
	binderMethod.setDataBinderFactory(new DefaultDataBinderFactory(this.webBindingInitializer));
	binderMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
	return binderMethod;
}
 
Example #18
Source File: RequestMappingHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private InvocableHandlerMethod createInitBinderMethod(Object bean, Method method) {
	InvocableHandlerMethod binderMethod = new InvocableHandlerMethod(bean, method);
	binderMethod.setHandlerMethodArgumentResolvers(this.initBinderArgumentResolvers);
	binderMethod.setDataBinderFactory(new DefaultDataBinderFactory(this.webBindingInitializer));
	binderMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
	return binderMethod;
}
 
Example #19
Source File: RequestMappingHandlerAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private InvocableHandlerMethod createInitBinderMethod(Object bean, Method method) {
	InvocableHandlerMethod binderMethod = new InvocableHandlerMethod(bean, method);
	binderMethod.setHandlerMethodArgumentResolvers(this.initBinderArgumentResolvers);
	binderMethod.setDataBinderFactory(new DefaultDataBinderFactory(this.webBindingInitializer));
	binderMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
	return binderMethod;
}
 
Example #20
Source File: InitBinderDataBinderFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private WebDataBinderFactory createFactory(String methodName, Class<?>... parameterTypes)
		throws Exception {

	Object handler = new InitBinderHandler();
	Method method = handler.getClass().getMethod(methodName, parameterTypes);

	InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
	handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
	handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
	handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new InitBinderDataBinderFactory(
			Collections.singletonList(handlerMethod), this.bindingInitializer);
}
 
Example #21
Source File: ModelFactoryOrderingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #22
Source File: RequestHeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #23
Source File: RequestHeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void dateConversion() 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(paramDate, null, webRequest,
			new DefaultDataBinderFactory(bindingInitializer));

	assertTrue(result instanceof Date);
	assertEquals(new Date(rfc1123val), result);
}
 
Example #24
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #25
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void missingOptionalMultipartFile() throws Exception {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());
	WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

	request.setMethod("POST");
	request.setContentType("multipart/form-data");

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
	Object actual = resolver.resolveArgument(param, null, webRequest, binderFactory);

	assertEquals(Optional.empty(), actual);
}
 
Example #26
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #27
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamList() 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, List.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertFalse(((Optional) result).isPresent());
}
 
Example #28
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamList() 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, List.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertFalse(((Optional) result).isPresent());
}
 
Example #29
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamArray() 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, Integer[].class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertFalse(((Optional) result).isPresent());
}
 
Example #30
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamValue() 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, Integer.class);
	Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.empty(), result);

	result = resolver.resolveArgument(param, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertFalse(((Optional) result).isPresent());
}