Package javango.forms.fields

Examples of javango.forms.fields.Field


    }
   
  }
 
  public void testDefaultWidget() throws Exception {
    Field f = new SelectField(injector.getInstance(WidgetFactory.class));
    assertEquals(SelectWidget.class, f.getWidget().getClass());
  }
View Full Code Here


 
  public void testLongGetByValue() throws Exception {
    Map<Long, String> choices = new HashMap<Long, String>();
    choices.put(1L, "John");
    choices.put(2L, "Paul");
    Field f = (injector.getInstance(LongSelectField.class)).setChoices(choices).setName("choice_field");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    assertEquals(1L, f.clean(new String[]{"1"}, errors));
    assertTrue(errors.isEmpty());

   
    errors = new HashMap<String, String>();
    f.clean(new String[]{"John"}, errors);
    assertEquals("Select a valid choice. That choice is not one of the available choices.", errors.get("choice_field"));   
  }
View Full Code Here

import javango.forms.widgets.WidgetFactory;

public class IntegerFieldTest extends InjectedTestCaseBase {

  public void testRequired() throws Exception {
    Field field = new IntegerField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    Long value = (Long)field.clean(new String[]{""}, errors);
    assertFalse(errors.isEmpty());
    assertTrue(errors.containsKey(field.getName()));
    assertEquals("Required", errors.get(field.getName()));
    // Integer number not valid
  }
View Full Code Here

    assertEquals("Required", errors.get(field.getName()));
    // Integer number not valid
  }
 
  public void testNotRequired() throws Exception {
    Field field = new IntegerField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
    field.setRequired(false);
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Long value = (Long)field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
  }
View Full Code Here

    Long value = (Long)field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
  }

  public void testInvalid() throws Exception {
    Field field = new IntegerField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Long value = (Long)field.clean(new String[]{"qwert"}, errors);
    assertFalse(errors.isEmpty());
    assertTrue(errors.containsKey("fieldName"));
    assertEquals("Integer number not valid", errors.get("fieldName"));
  }
View Full Code Here

TOP

Related Classes of javango.forms.fields.Field

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.