Package org.strecks.converter

Examples of org.strecks.converter.Converter


  @SuppressWarnings("unchecked")
  @Test
  public void testConvertedValueBindInwards() throws ConversionException
  {

    Converter converter = createStrictMock(Converter.class);
    handler.setConverter(converter);

    // make sure converter does not get called for conversion
    converter.setTargetClass(Integer.class);
    replay(converter);

    BindableBean form = new BindableBean();

    TargetBean targetBean = new TargetBean();
    form.setTargetBean(targetBean);

    handler.bindInwards(form, form, 4);
    Assert.assertEquals(targetBean.getIntegerProperty().intValue(), 4);

    verify(converter);
    reset(converter);

    converter.setTargetClass(Integer.class);
    replay(converter);
    handler.bindInwards(form, form, ConversionState.NULL);
    Assert.assertEquals(targetBean.getIntegerProperty(), null);
    verify(converter);
    reset(converter);

    converter.setTargetClass(Integer.class);
    expect(converter.toTargetType(null)).andReturn(null);
    replay(converter);
    handler.bindInwards(form, form, ConversionState.FAILURE);
    Assert.assertEquals(targetBean.getIntegerProperty(), null);
    verify(converter);
  }
View Full Code Here


  {
    Class c = FormWithDateConverter.class;
    Method method = c.getMethod("getStartDate");

    ConverterReader converterReader = new ConverterReader();
    Converter converter = converterReader.readConverter(method);

    assert converter instanceof DatePatternConverter;
  }
View Full Code Here

  {
    Class c = BeanWithReorderedConverters.class;
    Method method = c.getMethod("getDate");

    ConverterReader converterReader = new ConverterReader();
    Converter converter = converterReader.readConverter(method);

    assert converter instanceof DatePatternConverter;
  }
View Full Code Here

    handler.setBeanLookupExpression("lookupMap");
    handler.setBeanPropertyName("domainClass");
    handler.setBeanPropertyClass(Integer.class);
    handler.setConversionHandler(new DefaultConversionHandler());

    Converter converter = new StandardBeanUtilsConverter();
    handler.setConverter(converter);
    converter.setTargetClass(Integer.class);

    // needed for binding outwards
    PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor(new BindableBean(), "selectedId");
    handler.setPropertyDescriptor(propertyDescriptor);
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testConvertedValueBindInwards() throws ConversionException
  {

    Converter converter = createStrictMock(Converter.class);
    handler.setConverter(converter);

    // make sure converter does not get called for conversion
    replay(converter);

    BindableBean form = new BindableBean();

    TargetBean targetBean = new TargetBean();
    form.setTargetBean(targetBean);

    handler.bindInwards(form, form, 4);

    verify(converter);
    reset(converter);

    replay(converter);
    handler.bindInwards(form, form, ConversionState.NULL);
    Assert.assertEquals(targetBean.getIntegerProperty(), null);
    verify(converter);
    reset(converter);

    expect(converter.toTargetType(null)).andReturn(null);
    replay(converter);
    handler.bindInwards(form, form, ConversionState.FAILURE);
    Assert.assertEquals(targetBean.getIntegerProperty(), null);
    verify(converter);
   
View Full Code Here

    Map validators = createStrictMock(Map.class);
    Set keys = createStrictMock(Set.class);
    Iterator iterator = createStrictMock(Iterator.class);
    OrderedProperty op = createStrictMock(OrderedProperty.class);
    MethodValidators methodValidators = createStrictMock(MethodValidators.class);
    Converter converter = createStrictMock(Converter.class);

    Date sqlDate = Date.valueOf("1999-12-12");
    simpleForm.setDateValue("1999-12-12");
    ValidationInfo vi = new ValidationInfo(validators, handler, new DefaultConversionHandler());

    expect(validators.keySet()).andReturn(keys);
    expect(keys.iterator()).andReturn(iterator);
    expect(iterator.hasNext()).andReturn(true);
    expect(iterator.next()).andReturn(op);
    expect(validators.get(op)).andReturn(methodValidators);
    expect(methodValidators.getRequiresConversion()).andReturn(true);
    expect(methodValidators.getConverter()).andReturn(converter);
    expect(op.getPropertyName()).andReturn("dateValue");
    expect(converter.toTargetType("1999-12-12")).andReturn(sqlDate);
    expect(methodValidators.getConverterType()).andReturn(sqlDate.getClass());
    expect(iterator.hasNext()).andReturn(false);

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("dateValue", sqlDate);
View Full Code Here

    Map validators = createStrictMock(Map.class);
    Set keys = createStrictMock(Set.class);
    Iterator iterator = createStrictMock(Iterator.class);
    OrderedProperty op = createStrictMock(OrderedProperty.class);
    MethodValidators methodValidators = createStrictMock(MethodValidators.class);
    Converter converter = createStrictMock(Converter.class);

    Date sqlDate = Date.valueOf("1999-12-12");
    simpleForm.setDateValue("1999-12-12");
    ValidationInfo vi = new ValidationInfo(validators, handler, new DefaultConversionHandler());

    expect(validators.keySet()).andReturn(keys);
    expect(keys.iterator()).andReturn(iterator);
    expect(iterator.hasNext()).andReturn(true);
    expect(iterator.next()).andReturn(op);
    expect(validators.get(op)).andReturn(methodValidators);
    expect(methodValidators.getRequiresConversion()).andReturn(true);
    expect(methodValidators.getConverter()).andReturn(converter);
    expect(op.getPropertyName()).andReturn("dateValue");
    expect(converter.toTargetType("1999-12-12")).andReturn(sqlDate);
    expect(methodValidators.getConverterType()).andReturn(String.class);

    replay(handler);
    replay(validators);
    replay(keys);
View Full Code Here

    Map validators = createStrictMock(Map.class);
    Set keys = createStrictMock(Set.class);
    Iterator iterator = createStrictMock(Iterator.class);
    OrderedProperty op = createStrictMock(OrderedProperty.class);
    MethodValidators methodValidators = createStrictMock(MethodValidators.class);
    Converter converter = createStrictMock(Converter.class);

    ValidationInfo vi = new ValidationInfo(validators, handler, new DefaultConversionHandler());

    expect(validators.keySet()).andReturn(keys);
    expect(keys.iterator()).andReturn(iterator);
    expect(iterator.hasNext()).andReturn(true);
    expect(iterator.next()).andReturn(op);
    expect(validators.get(op)).andReturn(methodValidators);
    expect(methodValidators.getRequiresConversion()).andReturn(true);
    expect(methodValidators.getConverter()).andReturn(converter);
    expect(op.getPropertyName()).andReturn("dateValue");
    expect(converter.toTargetType(null)).andReturn(null);
    expect(iterator.hasNext()).andReturn(false);

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("dateValue", ConversionState.NULL);
View Full Code Here

    Map validators = createStrictMock(Map.class);
    Set keys = createStrictMock(Set.class);
    Iterator iterator = createStrictMock(Iterator.class);
    OrderedProperty op = createStrictMock(OrderedProperty.class);
    MethodValidators methodValidators = createStrictMock(MethodValidators.class);
    Converter converter = createStrictMock(Converter.class);

    ValidationInfo vi = new ValidationInfo(validators, handler, new DefaultConversionHandler());

    expect(validators.keySet()).andReturn(keys);
    expect(keys.iterator()).andReturn(iterator);
    expect(iterator.hasNext()).andReturn(true);
    expect(iterator.next()).andReturn(op);
    expect(validators.get(op)).andReturn(methodValidators);
    expect(methodValidators.getRequiresConversion()).andReturn(true);
    expect(methodValidators.getConverter()).andReturn(converter);
    expect(op.getPropertyName()).andReturn("dateValue");
    expect(converter.toTargetType(null)).andThrow(new ConversionRuntimeException(null));
    expect(iterator.hasNext()).andReturn(false);

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("dateValue", ConversionState.FAILURE);
View Full Code Here

      MethodValidators methodValidators = validators.get(property);
      if (methodValidators.getRequiresConversion())
      {
        if (convertedValues == null)
          convertedValues = new HashMap<String, Object>();
        Converter converter = methodValidators.getConverter();

        Object converted = null;

        // catch the conversion exception, and throw
        String propertyName = property.getPropertyName();
View Full Code Here

TOP

Related Classes of org.strecks.converter.Converter

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.