use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WDateField_Test method doRequest.
/**
* Emulates user interaction with the date field.
*
* @param dateField the date field to modify.
* @param dateStr the parsed date string.
*/
private void doRequest(final WDateField dateField, final String dateStr) {
MockRequest request = new MockRequest();
// don't really care about the user text
request.setParameter(dateField.getId(), dateStr);
request.setParameter(dateField.getId() + "-date", dateStr);
dateField.serviceRequest(request);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WDateField_Test method processDoHandleRequestWithValidDate.
/**
* @return a datefield processed with a request with a valid date
*/
private WDateField processDoHandleRequestWithValidDate() {
resetContext();
WDateField dateField = new WDateField();
String dateFieldId = dateField.getId();
dateField.setLocked(true);
// Valid DateType
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
request.setParameter(dateFieldId, REQUEST_VALID_USER_TEXT);
request.setParameter(dateFieldId + "-date", REQUEST_VALID_INTERNAL_DATE_TEXT);
dateField.doHandleRequest(request);
return dateField;
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WEmailField_Test method testDoHandleRequest.
@Test
public void testDoHandleRequest() {
WEmailField field = new WEmailField();
field.setLocked(true);
setActiveContext(createUIContext());
// Request with Empty Value and Field is null (No Change)
field.setData(null);
MockRequest request = new MockRequest();
request.setParameter(field.getId(), "");
boolean changed = field.doHandleRequest(request);
Assert.assertFalse("doHandleRequest should have returned false for request with empty value and field is null", changed);
Assert.assertNull("Value should still be null after empty request", field.getData());
// Request with Empty Value and Field is empty (No Change)
field.setData("");
request = new MockRequest();
request.setParameter(field.getId(), "");
changed = field.doHandleRequest(request);
Assert.assertFalse("doHandleRequest should have returned false for request with empty value and field is empty", changed);
Assert.assertEquals("Value should still be empty after empty request", "", field.getData());
// Request with Different Value (Change)
request = new MockRequest();
request.setParameter(field.getId(), "X");
changed = field.doHandleRequest(request);
Assert.assertTrue("doHandleRequest should have returned true for request with different value", changed);
Assert.assertEquals("Value not set after request", "X", field.getData());
// Request with Same Value (No Change)
request = new MockRequest();
request.setParameter(field.getId(), "X");
changed = field.doHandleRequest(request);
Assert.assertFalse("doHandleRequest should have returned false for request with same value", changed);
Assert.assertEquals("Value should not have changed after request with same value", "X", field.getData());
// Request with Empty Value (Change)
request = new MockRequest();
request.setParameter(field.getId(), "");
changed = field.doHandleRequest(request);
Assert.assertTrue("doHandleRequest should have returned true for request going back to an empty value", changed);
Assert.assertNull("Value should go back to null for request with empty value", field.getData());
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WDateField_Test method getRequestValue.
@Test
public void getRequestValue() throws ParseException {
WDateField dateField = new WDateField();
dateField.setLocked(true);
setActiveContext(createUIContext());
// Set current value
Date current = new Date();
dateField.setDate(current);
// Empty Request (not present, should return current value)
MockRequest request = new MockRequest();
Assert.assertEquals("Current value of the field should have been returned for empty request", current, dateField.getRequestValue(request));
// Request with "empty" value (should return null)
request = new MockRequest();
request.setParameter(dateField.getId(), "");
Assert.assertNull("Null should have been returned for request with empty value", dateField.getRequestValue(request));
// Request with "invalid" data parameter by T&S - wrong length (should return null)
request = new MockRequest();
request.setParameter(dateField.getId(), "TEST");
request.setParameter(dateField.getId() + "-date", "ABCDEFGHIHJKLMNOP");
Assert.assertNull("Null should have been returned for request with invalid length date parameter", dateField.getRequestValue(request));
// Request with "invalid" data parameter by T&S - empty (should return null)
request = new MockRequest();
request.setParameter(dateField.getId(), "TEST");
request.setParameter(dateField.getId() + "-date", "");
Assert.assertNull("Null should have been returned for request with invalid empty date parameter", dateField.getRequestValue(request));
// Request with invalid value but could be parsed if lenient (should return null)
request = new MockRequest();
request.setParameter(dateField.getId(), LENIENT_VALID_USER_TEXT);
request.setParameter(dateField.getId() + "-date", LENIENT_VALID_INTERNAL_DATE_TEXT);
Assert.assertNull("Null should have been returned for request with invalid value", dateField.getRequestValue(request));
// Request with valid value
request = new MockRequest();
request.setParameter(dateField.getId(), REQUEST_VALID_USER_TEXT);
request.setParameter(dateField.getId() + "-date", REQUEST_VALID_INTERNAL_DATE_TEXT);
Assert.assertEquals("Value from the request should have been returned", REQUEST_VALID_DATE_VALUE, dateField.getRequestValue(request));
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WDateField_Test method processDoHandleRequestWithEmptyRequest.
/**
* @return a datefield processed with a request with an empty value
*/
private WDateField processDoHandleRequestWithEmptyRequest() {
resetContext();
WDateField dateField = new WDateField();
String dateFieldId = dateField.getId();
dateField.setLocked(true);
// Empty Request
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
request.setParameter(dateFieldId, "");
dateField.doHandleRequest(request);
return dateField;
}
Aggregations