Beispiel #1
0
  @Test
  public void testFormAdd() throws Exception {
    Form form = new Form(request);
    assertEquals(0, form.size());

    Button button = Button.button("OK");
    form.add(button);
    assertEquals(1, form.size());

    TextField field = new TextField("name");
    form.add(field, "Name");
    form.add(null); // ignored
    form.add(null, "Name"); // ignored
    assertEquals(2, form.size());
    assertSame(field, form.get(1));
    assertSame(field, form.get("name"));
    assertNull(form.get("x"));
    assertNull(form.get(null));
    try {
      // cannot add twice
      form.add(field);
      fail();
    } catch (IllegalStateException e) {
    }

    form.setRequired(true);
    assertTrue(field.isRequired());
    form.setReadOnly(true);
    assertTrue(field.isReadOnly());

    assertTrue(form.validate(true));

    form.remove(field);
    assertEquals(1, form.size());
  }
Beispiel #2
0
  @Test
  public void testButton() {
    Form form = new Form(request);
    Button button;

    button = Button.button("OK");
    assertOut(button, "<button>OK</button>");
    assertEquals(null, button.getName());
    form.add(button);
    assertEquals(form.getName() + "_button", button.getName());

    button = Button.reset("Reset");
    button.setDisabled();
    assertOut(button, "<button type='reset' disabled>Reset</button>");

    button = Button.submit("Submit");
    button.setName("submit");
    assertOut(button, "<button type='submit' name='submit' value='Submit'>Submit</button>");
    form.add(button);
    assertEquals("submit", button.getName());
    Button defaultButton = button;
    assertSame(form.getDefaultButton(), button);

    button = Button.inputButton("OK");
    assertOut(button, "<input type='button' value='OK'>");

    button = Button.inputReset("Reset");
    assertOut(button, "<input type='reset' value='Reset'>");

    button = Button.inputSubmit("Submit");
    button.setOnClick("alert()");
    assertOut(button, "<input type='submit' value='Submit' onclick='alert()'>");
    button.end(out);
    out.assertOut("");
    form.add(button);
    assertSame(defaultButton, form.getDefaultButton());

    // misc
    assertTrue(button.read(null));
    assertEquals(Control.Category.BUTTON, button.getCategory());

    assertFalse(defaultButton.isClicked());
    setParam(form.getName(), "");
    assertTrue(defaultButton.isClicked());
    assertFalse(button.isClicked());
    setParam(form.getName(), "reload");
    assertFalse(defaultButton.isClicked());
    setParam(defaultButton.getName(), "x");
    assertFalse(defaultButton.isClicked());
    setParam(defaultButton.getName(), defaultButton.getValue());
    assertTrue(defaultButton.isClicked());

    setParam(defaultButton.getName(), null);
    assertFalse(defaultButton.isDirectlyClicked());
    setParam(defaultButton.getName(), "x");
    assertFalse(defaultButton.isDirectlyClicked());
    setParam(defaultButton.getName(), defaultButton.getValue());
    assertTrue(defaultButton.isDirectlyClicked());
  }