Search in sources :

Example 11 with MockRequest

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

Example 12 with MockRequest

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

Example 13 with MockRequest

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

Example 14 with MockRequest

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

Example 15 with MockRequest

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

Aggregations

MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)250 Test (org.junit.Test)216 UIContext (com.github.bordertech.wcomponents.UIContext)22 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)16 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)13 PrintWriter (java.io.PrintWriter)13 Request (com.github.bordertech.wcomponents.Request)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 StringWriter (java.io.StringWriter)7 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)6 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 BigDecimal (java.math.BigDecimal)5 Escape (com.github.bordertech.wcomponents.Escape)4 WTextField (com.github.bordertech.wcomponents.WTextField)4 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3