Search in sources :

Example 31 with Diagnostic

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

the class WFieldSet_Test method testMandatoryWithMessage.

@Test
public void testMandatoryWithMessage() {
    WFieldSet fieldSet = new WFieldSet("");
    fieldSet.setMandatory(true, "test message");
    Diagnostic msg = fieldSet.createMandatoryDiagnostic();
    Assert.assertEquals("Message incorrect", "test message", msg.getDescription());
}
Also used : Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Example 32 with Diagnostic

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

the class WMessages_Test method testHasMessage.

@Test
public void testHasMessage() {
    WMessages messages = new WMessages();
    UIContext uic = new UIContextImpl();
    setActiveContext(uic);
    Assert.assertFalse("Should have no messages by default", messages.hasMessages());
    messages.addMessage(new Message(Message.SUCCESS_MESSAGE, "x"));
    Assert.assertTrue("Should be true if there are messages", messages.hasMessages());
    messages = new WMessages();
    messages.addMessage(new Message(Message.INFO_MESSAGE, "x"));
    Assert.assertTrue("Should be true if there are messages", messages.hasMessages());
    messages = new WMessages();
    messages.addMessage(new Message(Message.WARNING_MESSAGE, "x"));
    Assert.assertTrue("Should be true if there are messages", messages.hasMessages());
    messages = new WMessages();
    messages.addMessage(new Message(Message.ERROR_MESSAGE, "x"));
    Assert.assertTrue("Should be true if there are messages", messages.hasMessages());
    messages = new WMessages();
    Diagnostic error = new DiagnosticImpl(Diagnostic.ERROR, new WTextField(), "Error");
    List<Diagnostic> errors = new ArrayList<>();
    errors.add(error);
    messages.getValidationErrors().setErrors(errors);
    Assert.assertTrue("Should be true if there are messages", messages.hasMessages());
}
Also used : DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Example 33 with Diagnostic

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

the class WNumberField_Test method testValidateDecimalPlaces.

@Test
public void testValidateDecimalPlaces() {
    WNumberField numberField = new WNumberField();
    numberField.setLocked(true);
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertTrue("Null value with no decimal places set should be valid", diags.isEmpty());
    numberField.setDecimalPlaces(1);
    diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertTrue("Null value with 1 decimal place set should be valid", diags.isEmpty());
    numberField.setNumber(100);
    numberField.setDecimalPlaces(0);
    diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertTrue("Value with no decimal places and no decimal place set should be valid", diags.isEmpty());
    BigDecimal value = new BigDecimal("1.12");
    numberField.setNumber(value);
    numberField.setDecimalPlaces(0);
    diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertFalse("Value has more decimal places so should be invalid", diags.isEmpty());
    numberField.setDecimalPlaces(1);
    diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertFalse("Value has more decimal places so should be invalid", diags.isEmpty());
    numberField.setDecimalPlaces(2);
    diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertTrue("Value has the same decimal places so should be valid", diags.isEmpty());
    numberField.setDecimalPlaces(3);
    diags = new ArrayList<>();
    numberField.validate(diags);
    Assert.assertTrue("Value has less decimal places so should be valid", diags.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 34 with Diagnostic

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

the class WRepeater_Test method testValidate.

@Test
public void testValidate() {
    WTextField textField = new WTextField();
    textField.setMandatory(true);
    WRepeater repeater = new WRepeater();
    repeater.setRepeatedComponent(textField);
    repeater.setLocked(true);
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    repeater.preparePaint(new MockRequest());
    repeater.validate(diags);
    Assert.assertTrue("Should not have any validation errors for zero rows", diags.isEmpty());
    repeater.setBeanList(Arrays.asList(ROW_DATA));
    repeater.preparePaint(new MockRequest());
    repeater.validate(diags);
    Assert.assertEquals("Should have one validation error", 1, diags.size());
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Aggregations

Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)34 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)24 DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)9 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)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 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)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