use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WPartialDateField_Test method processDoHandleRequestWithValidPartialDate.
/**
* @return a datefield processed with a request with a valid date
*/
private WPartialDateField processDoHandleRequestWithValidPartialDate() {
resetContext();
WPartialDateField dateField = new WPartialDateField();
String dateFieldId = dateField.getId();
dateField.setLocked(true);
// Valid Date
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
request.setParameter(dateFieldId, REQUEST_VALID_PARTIAL_USER_TEXT);
request.setParameter(dateFieldId + "-date", REQUEST_VALID_PARTIAL_INTERNAL_DATE_TEXT);
dateField.doHandleRequest(request);
return dateField;
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WPartialDateField_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 WPartialDateField 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 WPartialDateField_Test method processDoHandleRequestWithValidDate.
/**
* @return a datefield processed with a request with a valid date
*/
private WPartialDateField processDoHandleRequestWithValidDate() {
resetContext();
WPartialDateField dateField = new WPartialDateField();
String dateFieldId = dateField.getId();
dateField.setLocked(true);
// Valid Date
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 WPartialDateField_Test method testDoHandleRequestValidDateScenarios.
@Test
public void testDoHandleRequestValidDateScenarios() {
WPartialDateField dateField = new WPartialDateField();
dateField.setLocked(true);
setActiveContext(createUIContext());
// Setup Request with Valid Date
MockRequest request = new MockRequest();
request.setParameter(dateField.getId(), REQUEST_VALID_USER_TEXT);
request.setParameter(dateField.getId() + "-date", REQUEST_VALID_INTERNAL_DATE_TEXT);
// Scenario #1
// Setup datefield with null value
dateField.setDate(null);
boolean changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Valid Date and field is null - doHandleRequest should have returned true", changed);
assertDateFieldValidDate(dateField, "Request with Valid Date and field is null");
// Scenario #2
// Setup datefield with a different valid date set
dateField.setDate(new Date());
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Valid Date and field has a different valid date set - doHandleRequest should have returned true", changed);
assertDateFieldValidDate(dateField, "Request with Valid Date and field has a different valid date set");
// Scenario #3
// Datefield with same valid date set
changed = dateField.doHandleRequest(request);
Assert.assertFalse("Request with Valid Date and field has same valid date set - doHandleRequest should have returned false", changed);
assertDateFieldValidDate(dateField, "Request with Valid Date and field has same valid date set");
// Scenario #4
// Setup datefield with invalid date value
MockRequest request2 = new MockRequest();
request2.setParameter(dateField.getId(), REQUEST_BAD_USER_TEXT);
dateField.doHandleRequest(request2);
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Valid Date and field has an invalid date - doHandleRequest should have returned true", changed);
assertDateFieldValidDate(dateField, "Request with Valid Date and field has an invalid date");
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WPartialDateField_Test method testDoHandleRequestBadDateScenarios.
@Test
public void testDoHandleRequestBadDateScenarios() {
WPartialDateField dateField = new WPartialDateField();
dateField.setLocked(true);
setActiveContext(createUIContext());
// Setup Request with Invalid Date (User text only)
MockRequest request = new MockRequest();
request.setParameter(dateField.getId(), REQUEST_BAD_USER_TEXT);
// Scenario #1
// Setup datefield with null value
dateField.setDate(null);
boolean changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Bad Date and field is null - doHandleRequest should have returned true", changed);
assertDateFieldBadDate(dateField, "Request with Bad Date and field is null");
// Scenario #2
// Setup datefield with a valid date set
dateField.setDate(new Date());
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Bad Date and field has a valid date set - doHandleRequest should have returned true", changed);
assertDateFieldBadDate(dateField, "Request with Bad Date and field has a valid date set");
// Scenario #3
// Setup datefield with DIFFERENT invalid date value
MockRequest request2 = new MockRequest();
request2.setParameter(dateField.getId(), "ANOTHER BAD DATE");
dateField.doHandleRequest(request2);
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Bad Date and field has a different invalid date - doHandleRequest should have returned true", changed);
assertDateFieldBadDate(dateField, "Request with Bad Date and field has a different invalid date");
// Scenario #4
// Setup datefield with SAME invalid date value
changed = dateField.doHandleRequest(request);
Assert.assertFalse("Request with Bad Date and field has same invalid date - doHandleRequest should have returned false", changed);
assertDateFieldBadDate(dateField, "Request with Bad Date and field has same invalid date");
// Scenario #5
// Setup datefield with valid date value
request2 = new MockRequest();
request2.setParameter(dateField.getId(), REQUEST_VALID_USER_TEXT);
request2.setParameter(dateField.getId() + "-date", REQUEST_VALID_INTERNAL_DATE_TEXT);
dateField.doHandleRequest(request2);
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Request with Bad Date and field has a valid value - doHandleRequest should have returned true", changed);
assertDateFieldBadDate(dateField, "Request with Bad Date and field has a valid value");
}
Aggregations