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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations