使用WicketTester验证Validator是否已添加到TextField?

时间:2012-08-01 19:22:54

标签: java wicket wicket-tester

我在我的wicket应用程序中使用了以下面板,我想编写一个测试来确保调用addPatternValidator(String pattern)将TextValidator添加到TextField。

public class StringTextBoxPanel extends Panel {
  private static final long serialVersionUID = 1L;

  private String stringModel = new String();
  private TextField<String> textfield;
  private Label label;

  public StringTextBoxPanel(String id, String labelText) {
    super(id);
    label = new Label("label", labelText);
    textfield = new TextField<String>("textField", new PropertyModel<String>(this, "stringModel"));
    add(label);
    add(textfield);
  }

  public String getValue() {
    return textfield.getValue();
  }

  public void addPatternValidator(String pattern) {
    this.get(textfield.getId()).add(new PatternValidator(pattern));
  }

  public void setRequired() {
    textfield.setRequired(true);
  }
}

用WicketTester可以做到吗?

1 个答案:

答案 0 :(得分:2)

我在表单提交后检查了错误/信息消息:

wicketTester.assertHasNoErrorMessage();
wicketTester.assertHasNoInfoMessage();
wicketTester.getMessages(FeedbackMessage.FATAL); //or another kind of messages