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