Search in sources :

Example 11 with WDateField

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);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 12 with WDateField

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);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) Test(org.junit.Test)

Example 13 with WDateField

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());
    }
}
Also used : WNumberField(com.github.bordertech.wcomponents.WNumberField) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) WDateField(com.github.bordertech.wcomponents.WDateField) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 14 with WDateField

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));
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 15 with WDateField

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());
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Aggregations

WDateField (com.github.bordertech.wcomponents.WDateField)27 Test (org.junit.Test)11 WTextField (com.github.bordertech.wcomponents.WTextField)8 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)7 Date (java.util.Date)7 SimpleDateFormat (java.text.SimpleDateFormat)5 WDataTable (com.github.bordertech.wcomponents.WDataTable)4 WNumberField (com.github.bordertech.wcomponents.WNumberField)4 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)3 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLabel (com.github.bordertech.wcomponents.WLabel)3 WText (com.github.bordertech.wcomponents.WText)3 SystemException (com.github.bordertech.wcomponents.util.SystemException)3 ArrayList (java.util.ArrayList)3 AbstractWSelectList (com.github.bordertech.wcomponents.AbstractWSelectList)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)2 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2