Search in sources :

Example 6 with DiagnosticImpl

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

the class AbstractFieldValidator method validate.

/**
 * Validates the input field.
 *
 * @param diags the list of Diagnostics to add validation errors to.
 *
 * @return the updated list of validation errors.
 */
@Override
public List<Diagnostic> validate(final List<Diagnostic> diags) {
    if (!isValid()) {
        List<Serializable> argList = getMessageArguments();
        Serializable[] args = argList.toArray(new Serializable[argList.size()]);
        diags.add(new DiagnosticImpl(Diagnostic.ERROR, input, getErrorMessage(), args));
    }
    return diags;
}
Also used : Serializable(java.io.Serializable) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl)

Example 7 with DiagnosticImpl

use of com.github.bordertech.wcomponents.validation.DiagnosticImpl 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)

Example 8 with DiagnosticImpl

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

the class WFieldErrorIndicatorRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WPanel target = new WPanel();
    WFieldErrorIndicator indicator = new WFieldErrorIndicator(target);
    root.add(target);
    root.add(indicator);
    // Simulate Error Message
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, target, "Test Error"));
    root.showErrorIndicators(diags);
    // Validate Schema
    assertSchemaMatch(root);
    // Check Attributes
    assertXpathEvaluatesTo(indicator.getId(), "//ui:fieldindicator/@id", root);
    assertXpathEvaluatesTo("error", "//ui:fieldindicator/@type", root);
    assertXpathEvaluatesTo(target.getId(), "//ui:fieldindicator/@for", root);
    // Check Message
    assertXpathEvaluatesTo("Test Error", "//ui:fieldindicator/ui:message", root);
}
Also used : WFieldErrorIndicator(com.github.bordertech.wcomponents.validation.WFieldErrorIndicator) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Example 9 with DiagnosticImpl

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

the class WFieldRenderer_Test method testWithValidationMessages.

@Test
public void testWithValidationMessages() throws IOException, SAXException, XpathException {
    WTextField text = new WTextField();
    text.setText("text1");
    WFieldLayout test = new WFieldLayout();
    WField field = test.addField("label1", text);
    setActiveContext(createUIContext());
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield/text()", field);
    // Simulate Error Message
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, text, "Test Error"));
    diags.add(new DiagnosticImpl(Diagnostic.WARNING, text, "Test Warning"));
    field.showErrorIndicators(diags);
    field.showWarningIndicators(diags);
    // Validate Schema
    assertSchemaMatch(test);
    // Check Attributes
    assertXpathEvaluatesTo(field.getId(), "//ui:field/@id", field);
    // Check Label
    assertXpathEvaluatesTo("label1", "//ui:field/ui:label", field);
    // Check Input
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield/text()", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='error']", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='warn']", field);
    assertXpathEvaluatesTo("Test Error", "//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='error']/ui:message", field);
    assertXpathEvaluatesTo("Test Warning", "//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='warn']/ui:message", field);
}
Also used : WField(com.github.bordertech.wcomponents.WField) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 10 with DiagnosticImpl

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

the class WFieldWarningIndicatorRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WPanel target = new WPanel();
    WFieldWarningIndicator indicator = new WFieldWarningIndicator(target);
    root.add(target);
    root.add(indicator);
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.WARNING, target, getMaliciousContent()));
    root.showWarningIndicators(diags);
    assertSafeContent(root);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WFieldWarningIndicator(com.github.bordertech.wcomponents.validation.WFieldWarningIndicator) Test(org.junit.Test)

Aggregations

DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)11 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 WContainer (com.github.bordertech.wcomponents.WContainer)6 WPanel (com.github.bordertech.wcomponents.WPanel)4 WValidationErrors (com.github.bordertech.wcomponents.validation.WValidationErrors)3 WFieldErrorIndicator (com.github.bordertech.wcomponents.validation.WFieldErrorIndicator)2 WFieldWarningIndicator (com.github.bordertech.wcomponents.validation.WFieldWarningIndicator)2 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WField (com.github.bordertech.wcomponents.WField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WTextArea (com.github.bordertech.wcomponents.WTextArea)1 WTextField (com.github.bordertech.wcomponents.WTextField)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 GroupedDiagnositcs (com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs)1 Serializable (java.io.Serializable)1