public void testWidgetProcessor() throws Exception {

    CssStyleProcessor processor = new CssStyleProcessor();

    // Pass through

    HtmlMetawidget metawidget = new HtmlMetawidget();
    UIComponent component = new HtmlInputText();
    assertEquals(component, processor.processWidget(component, PROPERTY, null, metawidget));
    assertEquals(null, component.getAttributes().get("style"));
    assertEquals(null, component.getAttributes().get("styleClass"));

    // Simple styles and styleClasses

    metawidget.setStyle("foo1");
    metawidget.setStyleClass("bar1");
    assertEquals(component, processor.processWidget(component, PROPERTY, null, metawidget));
    assertEquals("foo1", component.getAttributes().get("style"));
    assertEquals("bar1", component.getAttributes().get("styleClass"));

    // Compound styles and styleClasses

    metawidget.setStyle("foo2");
    metawidget.setStyleClass("bar2");
    assertEquals(component, processor.processWidget(component, PROPERTY, null, metawidget));
    assertEquals("foo1 foo2", component.getAttributes().get("style"));
    assertEquals("bar1 bar2", component.getAttributes().get("styleClass"));
  }
  public void testPrimeFacesWidgetBuilder() throws Exception {

    PrimeFacesWidgetBuilder widgetBuilder = new PrimeFacesWidgetBuilder();

    // Read-only pass throughs

    Map<String, String> attributes = CollectionUtils.newHashMap();
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.put(READ_ONLY, TRUE);
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.put(LOOKUP, TRUE);
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.remove(LOOKUP);
    attributes.put(FACES_LOOKUP, "#{true}");
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.remove(FACES_LOOKUP);
    attributes.put(HIDDEN, TRUE);
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.remove(HIDDEN);
    attributes.put(TYPE, "foo");
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));

    // Active pass throughs

    attributes.remove(READ_ONLY);
    attributes.put(HIDDEN, TRUE);
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.remove(HIDDEN);
    attributes.put(TYPE, "foo");
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
    attributes.remove(HIDDEN);

    // Action

    attributes.put(NAME, "Press Me");
    HtmlMetawidget metawidget = new HtmlMetawidget();
    CommandButton button =
        (CommandButton) widgetBuilder.buildWidget(ACTION, attributes, metawidget);
    assertEquals("Press Me", button.getValue());
    assertTrue(!button.isAjax());
    attributes.remove(ACTION);

    // Faces lookup

    attributes.put(FACES_LOOKUP, "#{foo.bar}");
    assertTrue(widgetBuilder.buildWidget(PROPERTY, attributes, null) instanceof SelectOneMenu);
    attributes.remove(FACES_LOOKUP);

    // Lookup

    attributes.put(TYPE, String.class.getName());
    attributes.put(LOOKUP, "Foo, Bar, Baz");
    metawidget.setInspector(new PropertyTypeInspector());
    assertTrue(
        widgetBuilder.buildWidget(PROPERTY, attributes, metawidget) instanceof SelectOneMenu);
    attributes.remove(LOOKUP);

    // Sliders

    attributes.put(TYPE, int.class.getName());
    attributes.put(MINIMUM_VALUE, "1");
    attributes.put(MAXIMUM_VALUE, "1024");
    UIStub stub = (UIStub) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertTrue(stub.getChildren().get(0) instanceof HtmlInputText);
    Slider slider = (Slider) stub.getChildren().get(1);
    assertEquals(1, slider.getMinValue());
    assertEquals(1024, slider.getMaxValue());

    attributes.put(TYPE, Long.class.getName());
    attributes.put(MINIMUM_VALUE, "2");
    attributes.put(MAXIMUM_VALUE, "1023");
    stub = (UIStub) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertTrue(stub.getChildren().get(0) instanceof HtmlInputText);
    slider = (Slider) stub.getChildren().get(1);
    assertEquals(2, slider.getMinValue());
    assertEquals(1023, slider.getMaxValue());

    // Spinners

    attributes.put(TYPE, int.class.getName());
    attributes.put(MAXIMUM_VALUE, "");
    Spinner spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals(2d, spinner.getMin());
    attributes.put(MAXIMUM_VALUE, "1024");

    attributes.put(MINIMUM_VALUE, "");
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals(1024d, spinner.getMax());

    // (lower bound)

    attributes.put(TYPE, byte.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Byte.MIN_VALUE, spinner.getMin());

    attributes.put(TYPE, short.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Short.MIN_VALUE, spinner.getMin());

    attributes.put(TYPE, int.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Integer.MIN_VALUE, spinner.getMin());

    attributes.put(TYPE, long.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Long.MIN_VALUE, spinner.getMin());

    attributes.put(TYPE, float.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) -Float.MAX_VALUE, spinner.getMin());

    attributes.put(TYPE, double.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals(-Double.MAX_VALUE, spinner.getMin());

    // (upper bound)

    attributes.put(MAXIMUM_VALUE, "");

    attributes.put(TYPE, byte.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Byte.MAX_VALUE, spinner.getMax());

    attributes.put(TYPE, short.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Short.MAX_VALUE, spinner.getMax());

    attributes.put(TYPE, int.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Integer.MAX_VALUE, spinner.getMax());

    attributes.put(TYPE, long.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Long.MAX_VALUE, spinner.getMax());

    attributes.put(TYPE, float.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals((double) Float.MAX_VALUE, spinner.getMax());

    attributes.put(TYPE, double.class.getName());
    spinner = (Spinner) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals(Double.MAX_VALUE, spinner.getMax());

    // Calendars

    attributes.put(TYPE, Date.class.getName());
    attributes.put(DATETIME_PATTERN, "dd-MM-yyyy");
    attributes.put(LOCALE, "en-AU");
    attributes.put(TIME_ZONE, "Australia/Sydney");
    Calendar calendar = (Calendar) widgetBuilder.buildWidget(PROPERTY, attributes, null);
    assertEquals("dd-MM-yyyy", calendar.getPattern());
    assertEquals(new Locale("en-AU"), calendar.getLocale());
    assertEquals(TimeZone.getTimeZone("Australia/Sydney"), calendar.getTimeZone());

    // Suggest

    attributes.put(TYPE, String.class.getName());
    attributes.put(FACES_SUGGEST, "#{foo.bar}");

    AutoComplete autocomplete =
        (AutoComplete) widgetBuilder.buildWidget(PROPERTY, attributes, metawidget);
    assertEquals("#{foo.bar}", autocomplete.getCompleteMethod().getExpressionString());
    assertEquals(
        Object.class, autocomplete.getCompleteMethod().getMethodInfo(null).getReturnType());
    assertEquals(
        String.class, autocomplete.getCompleteMethod().getMethodInfo(null).getParamTypes()[0]);
    assertEquals(1, autocomplete.getCompleteMethod().getMethodInfo(null).getParamTypes().length);

    attributes.remove(FACES_SUGGEST);

    // ColorPickers. Note org.primefaces.component.ColorPickerRenderer does *not* support
    // java.awt.Color (http://forum.primefaces.org/viewtopic.php?t=21593) so it isn't much good
    // to us here

    attributes.put(TYPE, Color.class.getName());
    assertEquals(null, widgetBuilder.buildWidget(PROPERTY, attributes, null));
  }