Package org.springframework.web.bind.support

Examples of org.springframework.web.bind.support.WebDataBinderFactory


  public void missingRequestParamEmptyValueConvertedToNull() throws Exception {

    WebDataBinder binder = new WebRequestDataBinder(null);
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);

    this.request.addParameter("stringNotAnnot", "");

    Object arg = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, binderFactory);
View Full Code Here


  public void missingRequestParamEmptyValueNotRequired() throws Exception {

    WebDataBinder binder = new WebRequestDataBinder(null);
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);

    this.request.addParameter("name", "");

    Object arg = resolver.resolveArgument(paramNotRequired, null, webRequest, binderFactory);
View Full Code Here

  @Test
  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);
View Full Code Here

  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 = HandlerMethodSelector.selectMethods(type, METHOD_FILTER);
    List<InvocableHandlerMethod> modelMethods = new ArrayList<InvocableHandlerMethod>();
    for (Method method : methods) {
View Full Code Here

  private void getAttributeFromModel(String expectedAttributeName, MethodParameter param) throws Exception {
    Object target = new TestBean();
    mavContainer.addAttribute(expectedAttributeName, target);

    WebDataBinder dataBinder = new WebRequestDataBinder(target);
    WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
    given(factory.createBinder(webRequest, target, expectedAttributeName)).willReturn(dataBinder);

    processor.resolveArgument(param, mavContainer, webRequest, factory);
    verify(factory).createBinder(webRequest, target, expectedAttributeName);
  }
View Full Code Here

  @Test
  public void resovleArgumentViaDefaultConstructor() throws Exception {
    WebDataBinder dataBinder = new WebRequestDataBinder(null);

    WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
    given(factory.createBinder((NativeWebRequest) anyObject(), notNull(), eq("attrName"))).willReturn(dataBinder);

    processor.resolveArgument(paramNamedValidModelAttr, mavContainer, webRequest, factory);

    verify(factory).createBinder((NativeWebRequest) anyObject(), notNull(), eq("attrName"));
  }
View Full Code Here

    String name = "attrName";
    Object target = new TestBean();
    mavContainer.addAttribute(name, target);

    StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, target, name)).willReturn(dataBinder);

    processor.resolveArgument(paramNamedValidModelAttr, mavContainer, webRequest, binderFactory);

    assertTrue(dataBinder.isBindInvoked());
    assertTrue(dataBinder.isValidateInvoked());
View Full Code Here

    mavContainer.getModel().addAttribute(target);

    StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
    dataBinder.getBindingResult().reject("error");

    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, target, name)).willReturn(dataBinder);

    processor.resolveArgument(paramNonSimpleType, mavContainer, webRequest, binderFactory);
    verify(binderFactory).createBinder(webRequest, target, name);
  }
View Full Code Here

    Object anotherTestBean = new TestBean();
    mavContainer.addAttribute("anotherTestBean", anotherTestBean);

    StubRequestDataBinder dataBinder = new StubRequestDataBinder(testBean, name);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, testBean, name)).willReturn(dataBinder);

    processor.resolveArgument(paramModelAttr, mavContainer, webRequest, binderFactory);

    assertSame("Resolved attribute should be updated to be last in the order",
        testBean, mavContainer.getModel().values().toArray()[1]);
View Full Code Here

    Object attrValue = new Object();
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    mavContainer.addAttribute(attrName, attrValue);

    WebDataBinder dataBinder = new WebDataBinder(attrValue, attrName);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(webRequest, attrValue, attrName)).willReturn(dataBinder);

    ModelFactory modelFactory = new ModelFactory(null, binderFactory, sessionAttrsHandler);
    modelFactory.updateModel(webRequest, mavContainer);

    assertEquals(attrValue, mavContainer.getModel().remove(attrName));
View Full Code Here

TOP

Related Classes of org.springframework.web.bind.support.WebDataBinderFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.