コード例 #1
0
ファイル: TesterFormTest.java プロジェクト: aiwilliams/sails
  public void testConstructor() throws Exception {
    TesterForm form =
        new TesterForm(
            elementForHtml("<html><form name=\"my form\">stuff</form></html>"), "my form");
    assertEquals("<form name=\"my form\">stuff</form>", form.source());

    form =
        new TesterForm(
            elementForHtml("<html><form name=\"my form\" /></html>"),
            "my form",
            new HtmlForm(null, null, null, null) {
              @Override
              public boolean isValid() {
                return true;
              }
            });
    form.assertValid();

    form =
        new TesterForm(
            elementForHtml("<html><form name=\"my form\" /></html>"),
            "my form",
            new HtmlForm(new ValidationContext(new ModelContext(), null), null, null, null) {
              @Override
              public boolean isValid() {
                return false;
              }
            });
    try {
      form.assertValid();
      throw new RuntimeException("If HtmlForm is invalid, fail");
    } catch (TesterElementError expected) {
    }
  }
コード例 #2
0
ファイル: TesterFormTest.java プロジェクト: aiwilliams/sails
 public void testText() throws Exception {
   TesterForm form =
       new TesterForm(
           elementForHtml(
               "<html><form name=\"my form\"><input type=\"text\" name=\"the.name\"  value=\"valueValue\"    /></form></html>"),
           "my form");
   form.text("the.name");
   try {
     form.text("the.wrong.name");
     throw new RuntimeException("Assertion should fail");
   } catch (NoSuchElementError expected) {
   }
 }
コード例 #3
0
ファイル: TesterFormTest.java プロジェクト: aiwilliams/sails
 /**
  * Looks for submit by name first, then by value. Buttons can exist without a name, which will
  * cause the browser to not submit that button's name and value.
  *
  * @throws Exception
  */
 public void testSubmit() throws Exception {
   TesterForm form =
       new TesterForm(
           elementForHtml(
               "<form name=\"my form\"><input  name=\"the.name\" type=\"submit\"   value=\"valueValue\"    /><input type=\"submit\" value=\"theValue\" /></form>"),
           "my form");
   form.submit("the.name"); // look by name first
   form.submit("theValue"); // then by value, if no name
   try {
     form.submit("someOther");
     throw new RuntimeException("Assertion should fail");
   } catch (NoSuchElementError expected) {
   }
 }