Search in sources :

Example 41 with Diagnostic

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

the class Validation_Test method testMandatory.

@Test
public void testMandatory() {
    List<Diagnostic> diags = new ArrayList<>();
    WTextField textField = new WTextField();
    Assert.assertFalse("Text field should not be mandatory by default", textField.isMandatory());
    // No validation logic yet, but that should still be ok.
    textField.validate(diags);
    Assert.assertEquals("Diags should be empty when there are no validators", 0, diags.size());
    // Add a mandatory validation
    textField.setMandatory(true);
    Assert.assertTrue("Text field should be mandatory", textField.isMandatory());
    textField.validate(diags);
    Assert.assertEquals("Diags should contain mandatory validation error", 1, diags.size());
    // Add some text to the text field
    textField.setText("Blah");
    diags.clear();
    textField.validate(diags);
    Assert.assertEquals("Diags should be empty when mandatory field is filled in", 0, diags.size());
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)41 ArrayList (java.util.ArrayList)29 Test (org.junit.Test)29 DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)10 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)8 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)7 WContainer (com.github.bordertech.wcomponents.WContainer)6 WComponent (com.github.bordertech.wcomponents.WComponent)5 WPanel (com.github.bordertech.wcomponents.WPanel)4 WTextField (com.github.bordertech.wcomponents.WTextField)4 WValidationErrors (com.github.bordertech.wcomponents.validation.WValidationErrors)3 WDateField (com.github.bordertech.wcomponents.WDateField)2 WFieldErrorIndicator (com.github.bordertech.wcomponents.validation.WFieldErrorIndicator)2 WFieldWarningIndicator (com.github.bordertech.wcomponents.validation.WFieldWarningIndicator)2 Date (java.util.Date)2 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 Diagnosable (com.github.bordertech.wcomponents.Diagnosable)1 Input (com.github.bordertech.wcomponents.Input)1 UIContext (com.github.bordertech.wcomponents.UIContext)1 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)1