/** Test the built-in conversion for those renderers that have it. */
  public void testEmptyStrings() {
    UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
    root.setLocale(Locale.US);
    UIInput text = new UIInput(), hidden = new UIInput(), secret = new UIInput();

    text.setId("text");
    hidden.setId("hidden");
    secret.setId("secret");

    text.setRendererType("Text");
    hidden.setRendererType("Hidden");
    secret.setRendererType("Secret");

    root.getChildren().add(text);
    root.getChildren().add(hidden);
    root.getChildren().add(secret);
    TextRenderer textRenderer = new TextRenderer();
    HiddenRenderer hiddenRenderer = new HiddenRenderer();
    SecretRenderer secretRenderer = new SecretRenderer();

    try {
      textRenderer.decode(getFacesContext(), text);
      hiddenRenderer.decode(getFacesContext(), hidden);
      secretRenderer.decode(getFacesContext(), secret);
    } catch (Throwable e) {
      assertTrue(false);
    }
    assertTrue(text.isValid());
    assertTrue(hidden.isValid());
    assertTrue(secret.isValid());
  }
Beispiel #2
0
  /**
   * Test to verify that a class that registers itself is properly found using the search mechanism.
   * The J2SE classes are used for their inheritance hierarchy to test that converters registered to
   * interfaces and superclasses are properly found.
   *
   * <p>This test is meant for inheritance lookup only.
   */
  public void testConverterInheritance(UIViewRoot root)
      throws ConverterException, InstantiationException, IllegalAccessException,
          ClassNotFoundException {
    System.out.println("Testing ConverterInheritance");

    Converter converter;
    UIInput text = new UIInput();
    text.setId("my_date_converter");
    root.getChildren().add(text);

    // java.lang.Integer extends java.lang.Number.
    // Test to show that the standard converter registered to
    // java.lang.Integer should chosen over the inherited
    // java.lang.Number converter
    application.addConverter(java.lang.Number.class, "javax.faces.convert.NumberConverter");
    converter = application.createConverter(java.lang.Integer.class);
    assertTrue(converter != null);
    assertTrue(converter instanceof javax.faces.convert.IntegerConverter);

    // java.sql.Date extends java.util.Date
    // Test to find converter registered to java.util.Date
    application.addConverter(java.util.Date.class, "javax.faces.convert.DateTimeConverter");
    converter = null;
    converter = application.createConverter(java.sql.Date.class);
    assertTrue(converter != null);

    // java.util.HashSet is a subclass of java.util.AbstractSet which is
    // a subclass of java.util.AbstractCollection
    // Test to find the converter registered to java.util.AbstractCollection
    application.addConverter(
        java.util.AbstractCollection.class, "javax.faces.convert.DateTimeConverter");
    converter = null;
    try {
      converter = application.createConverter(java.util.HashSet.class);
    } catch (javax.faces.FacesException fe) {

    }
    assertTrue(converter != null);

    // java.lang.String implements java.lang.CharSequence
    // Test to find the converter registered to java.lang.CharSequence
    application.addConverter(
        java.text.CharacterIterator.class, "javax.faces.convert.CharacterConverter");
    converter = null;
    converter = application.createConverter(java.text.StringCharacterIterator.class);
    assertTrue(converter != null);

    // java.text.StringCharacterIterator implements
    // java.text.CharacterIterator which has a super-interface
    // java.lang.Cloneable
    // Test to find the converter registered to java.lang.Cloneable
    application.addConverter(java.lang.Cloneable.class, "javax.faces.convert.CharacterConverter");
    converter = null;
    converter = application.createConverter(java.text.StringCharacterIterator.class);
    assertTrue(converter != null);
  }
  /* (non-Javadoc)
   * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
   */
  public void setUp() throws Exception {
    super.setUp();

    form = new HtmlForm();
    form.setId("form");
    form2 = new HtmlForm();
    form2.setId("form2");
    facesContext.getViewRoot().getChildren().add(form);
    facesContext.getViewRoot().getChildren().add(form2);

    stp1 = (UISimpleTogglePanel) application.createComponent("org.richfaces.SimpleTogglePanel");
    stp1.setId("simpleTogglePanel1");
    stp1.setOpened(true);
    stp1.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE);

    openMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    openMarker1.setId("openMarker");
    openMarker1.setValue("open");

    closeMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    closeMarker1.setId("closeMarker");
    closeMarker1.setValue("close");

    stp1.getFacets().put(openMarker1.getId(), openMarker1);
    stp1.getFacets().put(closeMarker1.getId(), closeMarker1);
    form.getChildren().add(stp1);

    stp2 = (UISimpleTogglePanel) application.createComponent("org.richfaces.SimpleTogglePanel");
    stp2.setId("simpleTogglePanel2");
    stp2.setOpened(false);
    stp2.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE);

    openMarker2 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    openMarker2.setId("openMarker");
    openMarker2.setValue("open");

    closeMarker2 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    closeMarker2.setId("closeMarker");
    closeMarker2.setValue("close");

    stp2.getFacets().put(openMarker2.getId(), openMarker2);
    stp2.getFacets().put(closeMarker2.getId(), closeMarker2);
    form2.getChildren().add(stp2);

    input = (UIInput) application.createComponent(UIInput.COMPONENT_TYPE);
    input.setValue("");
    input.setId("opened");
    input.getAttributes().put("onchange", "return true;");
    stp1.getChildren().add(input);

    command = new HtmlCommandLink();
    command.setId("command");
    stp1.getChildren().add(command);
  }
  public void setUp() throws Exception {

    super.setUp();
    ajaxForm = (UIAjaxForm) application.createComponent(UIAjaxForm.COMPONENT_TYPE);
    ajaxForm.setId("form");

    child =
        new UIInput() {
          public void processDecodes(FacesContext context) {
            childInvoked++;
            super.processDecodes(context);
          }
        };
    child.setId("input");
    child.getAttributes().put("onchange", "return true;");
    child.addValidator(new TestAjaxFormValidator());
    childInvoked = 0;
    child.setId("child");
    ajaxForm.getChildren().add(child);
    facesContext.getViewRoot().getChildren().add(ajaxForm);
  }
Beispiel #5
0
  public void testNumberConverter(UIViewRoot root)
      throws ConverterException, InstantiationException, IllegalAccessException,
          ClassNotFoundException {
    System.out.println("Tesing NumberConverter");
    UIInput text = new UIInput();
    text.setId("my_input_number");
    root.getChildren().add(text);

    Converter converter = application.createConverter("javax.faces.Number");

    String stringToConvert = "99.9";
    Object obj = converter.getAsObject(getFacesContext(), text, stringToConvert);
    assertTrue(obj instanceof java.lang.Number);
    String str = converter.getAsString(getFacesContext(), text, obj);
    assertTrue(str.equals(stringToConvert));
  }
Beispiel #6
0
  public void testDateConverter(UIViewRoot root)
      throws ConverterException, InstantiationException, IllegalAccessException,
          ClassNotFoundException {
    System.out.println("Testing DateConverter");
    UIInput text = new UIInput();
    text.setId("my_input_date");
    root.getChildren().add(text);

    Converter converter = null;
    converter = application.createConverter("javax.faces.DateTime");

    // date
    String stringToConvert = "Jan 1, 1967";
    Object obj = converter.getAsObject(getFacesContext(), text, stringToConvert);
    assertTrue(obj instanceof java.util.Date);
    String str = converter.getAsString(getFacesContext(), text, obj);
    // make sure we end up with the same string we started with..
    assertTrue(str.equals(stringToConvert));

    // time
    converter = application.createConverter("javax.faces.DateTime");
    ((DateTimeConverter) converter).setType("time");
    text = new UIInput();
    text.setId("my_input_time");
    stringToConvert = "10:10:10 AM";
    obj = converter.getAsObject(getFacesContext(), text, stringToConvert);
    assertTrue(obj instanceof java.util.Date);
    str = converter.getAsString(getFacesContext(), text, obj);
    // make sure we end up with the same string we started with..
    assertTrue(str.equals(stringToConvert));

    // datetime
    converter = application.createConverter("javax.faces.DateTime");
    ((DateTimeConverter) converter).setType("both");
    text = new UIInput();
    text.setId("my_input_datetime");
    stringToConvert = "Jan 1, 1967 10:10:10 AM";
    obj = converter.getAsObject(getFacesContext(), text, stringToConvert);
    assertTrue(obj instanceof java.util.Date);
    str = converter.getAsString(getFacesContext(), text, obj);
    // make sure we end up with the same string we started with..
    assertTrue(str.equals(stringToConvert));

    // test bogus type....
    boolean exceptionThrown = false;
    try {
      ((DateTimeConverter) converter).setType("foobar");
      obj = converter.getAsObject(getFacesContext(), text, stringToConvert);
    } catch (Exception e) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);

    // test NullPointerException (if either context or component arg is null)
    exceptionThrown = false;
    try {
      obj = converter.getAsObject(null, text, stringToConvert);
    } catch (NullPointerException npe) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
    exceptionThrown = false;
    try {
      obj = converter.getAsObject(getFacesContext(), null, stringToConvert);
    } catch (NullPointerException npe) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);

    exceptionThrown = false;
    try {
      str = converter.getAsString(null, text, obj);
    } catch (NullPointerException npe) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);

    exceptionThrown = false;
    try {
      str = converter.getAsString(getFacesContext(), null, obj);
    } catch (NullPointerException npe) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
  }