use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WPartialDateField_Test method processDoHandleRequestWithBadDate.
/**
* @return a datefield processed with a request with a bad date
*/
private WPartialDateField processDoHandleRequestWithBadDate() {
resetContext();
WPartialDateField dateField = new WPartialDateField();
String dateFieldId = dateField.getId();
dateField.setLocked(true);
// Bad Date
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
request.setParameter(dateFieldId, REQUEST_BAD_USER_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 testDoHandleRequestEmptyScenarios.
@Test
public void testDoHandleRequestEmptyScenarios() {
WPartialDateField dateField = new WPartialDateField();
dateField.setLocked(true);
setActiveContext(createUIContext());
// Setup Request with empty value
MockRequest request = new MockRequest();
request.setParameter(dateField.getId(), "");
// Scenario #1
// Setup datefield with null value
dateField.setDate(null);
// Empty Request and Field is null (no change)
boolean changed = dateField.doHandleRequest(request);
Assert.assertFalse("Empty request and field is null - doHandleRequest should have returned false", changed);
assertDateFieldNullValue(dateField, "Empty request and field is null");
// Scenario #2
// Setup datefield with a valid date set
dateField.setDate(new Date());
// Empty Request and Field has a valid date set (change)
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Empty request and field has a valid date set - doHandleRequest should have returned true", changed);
assertDateFieldNullValue(dateField, "Empty request and field has a valid date set");
// Scenario #3
// Setup datefield with invalid date value
MockRequest request2 = new MockRequest();
request2.setParameter(dateField.getId(), REQUEST_BAD_USER_TEXT);
dateField.doHandleRequest(request2);
// Empty Request and Field has an invalid date value (change)
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Empty request and field has an invalid date - doHandleRequest should have returned true", changed);
assertDateFieldNullValue(dateField, "Empty request and field has an invalid date");
// Scenario #4
// 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);
// Empty Request and Field has a valid date value (change)
changed = dateField.doHandleRequest(request);
Assert.assertTrue("Empty request and field has a valid value - doHandleRequest should have returned true", changed);
assertDateFieldNullValue(dateField, "Empty request and field has a valid value");
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WPartialDateField_Test method getRequestValue.
@Test
public void getRequestValue() throws ParseException {
WPartialDateField dateField = new WPartialDateField();
dateField.setLocked(true);
setActiveContext(createUIContext());
// Set current value
dateField.setDate(REQUEST_VALID_DATE_DATE);
// 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", REQUEST_VALID_DATE_TEXT, 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 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_TEXT, dateField.getRequestValue(request));
// Request with partial valid value
request = new MockRequest();
request.setParameter(dateField.getId(), REQUEST_VALID_PARTIAL_USER_TEXT);
request.setParameter(dateField.getId() + "-date", REQUEST_VALID_PARTIAL_INTERNAL_DATE_TEXT);
Assert.assertEquals("Value from the request should have been returned", REQUEST_VALID_PARTIAL_DATE_TEXT, dateField.getRequestValue(request));
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WPhoneNumberField_Test method testDoHandleRequest.
@Test
public void testDoHandleRequest() {
WPhoneNumberField field = new WPhoneNumberField();
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 WPhoneNumberField_Test method testGetRequestValue.
@Test
public void testGetRequestValue() {
WPhoneNumberField field = new WPhoneNumberField();
field.setLocked(true);
setActiveContext(createUIContext());
// Set current value
field.setText("A");
// 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", "A", field.getRequestValue(request));
// Request with "empty" value (should return null as an empty value on the request is treated as null)
request = new MockRequest();
request.setParameter(field.getId(), "");
Assert.assertNull("Null should have been returned for request with empty value", field.getRequestValue(request));
// Request with value (should return the value on the request)
request = new MockRequest();
request.setParameter(field.getId(), "X");
Assert.assertEquals("Value from the request should have been returned", "X", field.getRequestValue(request));
}
Aggregations