Search in sources :

Example 6 with WValidationErrors

use of com.github.bordertech.wcomponents.validation.WValidationErrors in project wcomponents by BorderTech.

the class WValidationErrorsRenderer_Test method testDoPaintBasic.

@Test
public void testDoPaintBasic() throws IOException, SAXException, XpathException {
    WValidationErrors errors = new WValidationErrors();
    WTextArea text1 = new WTextArea();
    text1.setText("text1");
    WContainer root = new WContainer();
    root.add(errors);
    root.add(text1);
    root.setLocked(true);
    // Validate Schema with no errors
    assertSchemaMatch(root);
    // Simulate Error Message
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, text1, "Test Error1"));
    root.showErrorIndicators(diags);
    errors.setErrors(diags);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(text1.getId(), "//ui:validationerrors/ui:error/@for", root);
    assertXpathEvaluatesTo("Test Error1", "//ui:validationerrors/ui:error", root);
    String title = "WValidationErrorsTitle";
    errors.setTitleText(title);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(title, "//ui:validationerrors/@title", root);
    // Check for error message with no associated component
    setActiveContext(createUIContext());
    diags.clear();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, null, "Test Error1"));
    errors.setErrors(diags);
    assertSchemaMatch(root);
    assertXpathNotExists("//ui:validationerrors/ui:error/@for", root);
    assertXpathEvaluatesTo("Test Error1", "//ui:validationerrors/ui:error", root);
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Aggregations

WValidationErrors (com.github.bordertech.wcomponents.validation.WValidationErrors)6 Test (org.junit.Test)4 WContainer (com.github.bordertech.wcomponents.WContainer)3 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)3 DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)3 ArrayList (java.util.ArrayList)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 WButton (com.github.bordertech.wcomponents.WButton)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 WTextArea (com.github.bordertech.wcomponents.WTextArea)1 WTextField (com.github.bordertech.wcomponents.WTextField)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)1 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)1 GroupedDiagnositcs (com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs)1