//
// General Methods
//
public void testCheckboxRenderer(UIComponent root) throws IOException {
System.out.println("Testing CheckboxRenderer");
UISelectBoolean selectBoolean = new UISelectBoolean();
selectBoolean.setValue(null);
selectBoolean.setId("myCheckbox");
root.getChildren().add(selectBoolean);
CheckboxRenderer checkboxRenderer = new CheckboxRenderer();
// First test no parameter coming in - (the checkbox
// is not checked)
// test decode method
System.out.println(" Testing decode method - no parameter");
checkboxRenderer.decode(getFacesContext(), selectBoolean);
assertEquals("false", selectBoolean.getSubmittedValue());
Object value = checkboxRenderer.getConvertedValue(getFacesContext(),
selectBoolean,
selectBoolean.getSubmittedValue());
assertEquals(Boolean.FALSE, value);
// Test parameter coming in - (the checkbox has been checked)
// test decode method
System.out.println(" Testing decode method - parameter (on)");
selectBoolean = new UISelectBoolean();
selectBoolean.setId("myCheckboxOn");
selectBoolean.setValue(null);
checkboxRenderer.decode(getFacesContext(), selectBoolean);
assertEquals("true", selectBoolean.getSubmittedValue());
value = checkboxRenderer.getConvertedValue(getFacesContext(),
selectBoolean,
selectBoolean.getSubmittedValue());
assertEquals(Boolean.TRUE, value);
// test decode method
System.out.println(" Testing decode method - parameter (yes)");
selectBoolean = new UISelectBoolean();
selectBoolean.setId("myCheckboxYes");
selectBoolean.setValue(null);
checkboxRenderer.decode(getFacesContext(), selectBoolean);
assertEquals("true", selectBoolean.getSubmittedValue());
value = checkboxRenderer.getConvertedValue(getFacesContext(),
selectBoolean,
selectBoolean.getSubmittedValue());
assertEquals(Boolean.TRUE, value);
// test decode method
System.out.println(" Testing decode method - parameter (true)");
selectBoolean = new UISelectBoolean();
selectBoolean.setId("myCheckboxTrue");
selectBoolean.setValue(null);
checkboxRenderer.decode(getFacesContext(), selectBoolean);
assertEquals("true", selectBoolean.getSubmittedValue());
value = checkboxRenderer.getConvertedValue(getFacesContext(),
selectBoolean,
selectBoolean.getSubmittedValue());
assertEquals(Boolean.TRUE, value);
// test decode method
System.out.println(" Testing decode method - parameter (true)");
selectBoolean = new UISelectBoolean();
selectBoolean.setId("myCheckboxTrue");
selectBoolean.setValue(null);
checkboxRenderer.decode(getFacesContext(), selectBoolean);
assertEquals("true", selectBoolean.getSubmittedValue());
value = checkboxRenderer.getConvertedValue(getFacesContext(),
selectBoolean,
selectBoolean.getSubmittedValue());
assertEquals(Boolean.TRUE, value);
// test decode method with checkbox disabled.
System.out.println(" Testing decode method - parameter (yes)");
selectBoolean = new UISelectBoolean();
selectBoolean.setId("mycheckboxDisabled");
selectBoolean.getAttributes().put("disabled", "true");
selectBoolean.setValue(Boolean.TRUE);
checkboxRenderer.decode(getFacesContext(), selectBoolean);
// make sure the value wasn't set to false. Bug id 4883159
assertTrue(!"false".equals(selectBoolean.getSubmittedValue()));
selectBoolean.getAttributes().remove("disabled");
// test encode method
System.out.println(" Testing encode method - rendering checked");
selectBoolean = new UISelectBoolean();
selectBoolean.setId("myCheckbox");
selectBoolean.setSelected(true);
checkboxRenderer.encodeBegin(getFacesContext(), selectBoolean);
checkboxRenderer.encodeEnd(getFacesContext(), selectBoolean);
getFacesContext().getResponseWriter().writeText("\n", null);
System.out.println(" Testing encode method - rendering unchecked");
selectBoolean.setSelected(false);
checkboxRenderer.encodeBegin(getFacesContext(), selectBoolean);
checkboxRenderer.encodeEnd(getFacesContext(), selectBoolean);
getFacesContext().getResponseWriter().writeText("\n", null);
System.out.println(