use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WDateFieldRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WDateField dateField = new WDateField();
setActiveContext(createUIContext());
dateField.setToolTip(getMaliciousAttribute("ui:datefield"));
assertSafeContent(dateField);
dateField.setAccessibleText(getMaliciousAttribute("ui:datefield"));
assertSafeContent(dateField);
MockRequest request = new MockRequest();
request.setParameter(dateField.getId(), getMaliciousContent());
request.setParameter(dateField.getId() + "-date", getMaliciousContent());
dateField.serviceRequest(request);
assertSafeContent(dateField);
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WDateFieldRenderer_Test method testDoPaintAutocompleteOff.
@Test
public void testDoPaintAutocompleteOff() throws IOException, SAXException, XpathException {
WDateField dateField = new WDateField();
dateField.setDate(TEST_DATE);
dateField.setAutocompleteOff();
// Validate Schema
assertSchemaMatch(dateField);
assertXpathEvaluatesTo("off", "//ui:datefield/@autocomplete", dateField);
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class AbstractCompare_Test method testConstructors.
@Test
public void testConstructors() {
AbstractCompare compare;
// --------------------------
// Constructor - Valid Value
SubordinateTrigger trigger = new MyInput();
String value = "test";
compare = new MyCompare(trigger, value);
Assert.assertEquals("Invalid trigger returned", trigger, compare.getTrigger());
Assert.assertEquals("Invalid compare value returned", value, compare.getValue());
// --------------------------
// Constructor - Null Value
trigger = new MyInput();
compare = new MyCompare(trigger, null);
Assert.assertEquals("Invalid trigger returned", trigger, compare.getTrigger());
Assert.assertNull("Invalid compare value returned", compare.getValue());
// Constructor - Null Trigger
try {
compare = new MyCompare(null, "Test");
Assert.fail("A null trigger should not be allowed");
} catch (IllegalArgumentException e) {
Assert.assertNotNull("Exception message for null trigger should not be null", e.getMessage());
}
// --------------------------
// Constructor - DateField and Valid Value
SubordinateTrigger dateTrigger = new WDateField();
Date dateValue = new Date();
compare = new MyCompare(dateTrigger, dateValue);
Assert.assertEquals("Invalid date trigger returned", dateTrigger, compare.getTrigger());
Assert.assertEquals("Invalid date compare value returned", dateValue, compare.getValue());
// Constructor - DateField and Invalid Value
try {
compare = new MyCompare(new WDateField(), "Invalid Date");
Assert.fail("A datefield trigger and invalid date value should not be allowed");
} catch (IllegalArgumentException e) {
Assert.assertNotNull("Exception message for datefield trigger and invalid date should not be null", e.getMessage());
}
// --------------------------
// Constructor - NumberField and Valid Value
SubordinateTrigger numberTrigger = new WNumberField();
BigDecimal numberValue = BigDecimal.valueOf(5);
compare = new MyCompare(numberTrigger, numberValue);
Assert.assertEquals("Invalid number trigger returned", numberTrigger, compare.getTrigger());
Assert.assertEquals("Invalid number compare value returned", numberValue, compare.getValue());
// Constructor - NumberField and Invalid Value
try {
compare = new MyCompare(new WNumberField(), "Invalid Number");
Assert.fail("A numberField trigger and invalid number value should not be allowed");
} catch (IllegalArgumentException e) {
Assert.assertNotNull("Exception message for numberField trigger and invalid number should not be null", e.getMessage());
}
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class AbstractCompare_Test method testGetTriggerValueDateField.
@Test
public void testGetTriggerValueDateField() {
WDateField trigger = new WDateField();
AbstractCompare compare = new MyCompare(trigger, null);
// No Value
trigger.setDate(null);
Assert.assertNull("DateField Trigger Value - should be null for null date", compare.getTriggerValue(null));
// Value
Date date = new Date();
String dateString = new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date);
trigger.setDate(date);
Assert.assertEquals("DateField Trigger Value - should be the formatted string of the date value", dateString, compare.getTriggerValue(null));
// Value on the Request
date = DateUtilities.createDate(03, 02, 2001);
dateString = new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date);
MockRequest request = new MockRequest();
request.setParameter(trigger.getId(), "03 FEB 2001");
request.setParameter(trigger.getId() + "-date", dateString);
Assert.assertEquals("DateField Trigger Value - should be the formatted string of the date value on the request", dateString, compare.getTriggerValue(request));
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class AbstractCompare_Test method testGetCompareValueDateField.
@Test
public void testGetCompareValueDateField() {
WDateField trigger = new WDateField();
// Null Value
AbstractCompare compare = new MyCompare(trigger, null);
Assert.assertNull("DateField Compare Value - should be null for null date", compare.getCompareValue());
// Value
Date date = new Date();
String dateString = new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date);
compare = new MyCompare(trigger, date);
Assert.assertEquals("DateField Compare Value - should be the formatted string of the date value", dateString, compare.getCompareValue());
}
Aggregations