use of com.github.bordertech.wcomponents.validation.Diagnostic 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.Diagnostic 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);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WDateField_Test method testValidateMinValue.
@Test
public void testValidateMinValue() {
WDateField dateField = new WDateField();
dateField.setLocked(true);
Date value = DateUtilities.createDate(01, 02, 2003);
Date valueMinusOne = DateUtilities.createDate(01, 02, 2003);
Date valuePlusOne = DateUtilities.createDate(03, 02, 2003);
setActiveContext(createUIContext());
List<Diagnostic> diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Null value with no minimum set should be valid", diags.isEmpty());
dateField.setDate(value);
diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Value with no minimum set should be valid", diags.isEmpty());
dateField.reset();
dateField.setMinDate(value);
diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Null value with minimum set should be valid", diags.isEmpty());
dateField.setDate(value);
dateField.setMinDate(valueMinusOne);
diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Value is greater than minimum so should be valid", diags.isEmpty());
dateField.setMinDate(value);
diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Value is the same as minimum so should be valid", diags.isEmpty());
dateField.setMinDate(valuePlusOne);
diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertFalse("Value is less than minimum so should be invalid", diags.isEmpty());
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WDateField_Test method testValidateCustomError.
@Test
public void testValidateCustomError() {
WDateField dateField = new WDateField(false);
dateField.setInvalidDateErrorMessage(ERROR_MESSAGE);
dateField.setLocked(true);
setActiveContext(createUIContext());
List<Diagnostic> diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Empty field should not have a validation error", diags.isEmpty());
// Valid date
doRequest(dateField, VALID_INTERNAL_DATE);
dateField.validate(diags);
Assert.assertTrue("A valid date should not have a validation error", diags.isEmpty());
// Invalid date
doRequest(dateField, INVALID_INTERNAL_DATE);
dateField.validate(diags);
Assert.assertEquals("Invalid date should have a validation error", 1, diags.size());
Diagnostic diag = diags.get(0);
String text = diag.getDescription();
Assert.assertEquals("Incorrect error text", ERROR_MESSAGE, text);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WDateField_Test method testValidate.
@Test
public void testValidate() {
WDateField dateField = new WDateField();
dateField.setLocked(true);
setActiveContext(createUIContext());
List<Diagnostic> diags = new ArrayList<>();
dateField.validate(diags);
Assert.assertTrue("Empty field should not have a validation error", diags.isEmpty());
dateField.setMandatory(true);
dateField.validate(diags);
Assert.assertFalse("Empty should not validation error when mandatory", diags.isEmpty());
diags.clear();
// Valid date
doRequest(dateField, VALID_INTERNAL_DATE);
dateField.validate(diags);
Assert.assertTrue("A valid date should not have a validation error", diags.isEmpty());
// Valid (lenient) date
doRequest(dateField, LENIENT_VALID_INTERNAL_DATE_TEXT);
dateField.validate(diags);
Assert.assertFalse("Validator should not be lenient when validating dates", diags.isEmpty());
Diagnostic diag = diags.get(0);
String text = diag.getDescription();
Assert.assertTrue("Error message should not be empty", text != null && text.length() > 0);
diags.clear();
// Invalid date
doRequest(dateField, INVALID_INTERNAL_DATE);
dateField.validate(diags);
Assert.assertEquals("Invalid date should have a validation error", 1, diags.size());
diag = diags.get(0);
text = diag.getDescription();
Assert.assertTrue("Error message should not be empty", text != null && text.length() > 0);
// Invalid date - 2
diags.clear();
doRequest(dateField, INVALID_INTERNAL_DATE2);
dateField.validate(diags);
Assert.assertEquals("Invalid date should have a validation error", 1, diags.size());
// Invalid date - 3
diags.clear();
doRequest(dateField, INVALID_INTERNAL_DATE3);
dateField.validate(diags);
Assert.assertEquals("Invalid date should have a validation error", 1, diags.size());
}
Aggregations