Search in sources :

Example 21 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WLink_Test method testHandleRequest.

@Test
public void testHandleRequest() {
    MockRequest request = new MockRequest();
    TestAction action = new TestAction();
    WLink link = new WLink();
    link.setAction(action);
    // Request with link NOT pressed
    UIContext uic = createUIContext();
    setActiveContext(uic);
    link.serviceRequest(request);
    Assert.assertFalse("Action should not have triggered", action.wasTriggered());
    // Setup request for UIC1
    try {
        // Setup AJAX Operation (not for the WLink)
        AjaxHelper.setCurrentOperationDetails(new AjaxOperation("X", "Z"), null);
        // Request with link NOT pressed (not current AJAX operation)
        link.serviceRequest(request);
        Assert.assertFalse("Action should not have triggered", action.wasTriggered());
        // Setup AJAX Operation trigger by the link
        AjaxHelper.setCurrentOperationDetails(new AjaxOperation(link.getId(), link.getId()), null);
        // Request with link pressed (via AJAX operation)
        link.serviceRequest(request);
        Assert.assertTrue("Action should have triggered", action.wasTriggered());
        // Request with link pressed disabled (via AJAX operation)
        action.reset();
        link.setDisabled(true);
        link.serviceRequest(request);
        Assert.assertFalse("Action should not have triggered when disabled", action.wasTriggered());
    } finally {
        // Clear AJAX operation
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 22 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WMultiDropdown_Test method testGetNewSelectionsMultipleNullInputs.

@Test
public void testGetNewSelectionsMultipleNullInputs() {
    List<String> data = Arrays.asList(null, "b", "c");
    WMultiDropdown dropdown = new WMultiDropdown(data);
    dropdown.setMaxInputs(2);
    // Test duplicates
    setActiveContext(createUIContext());
    MockRequest request = new MockRequest();
    request.setParameter(dropdown.getId(), new String[] { "1", "1", "1" });
    request.setParameter(dropdown.getId() + "-h", "x");
    dropdown.serviceRequest(request);
    Assert.assertEquals("Incorrect selection size", 1, dropdown.getSelected().size());
    Assert.assertNull("Incorrect selection 1", dropdown.getSelected().get(0));
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 23 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WPasswordField_Test method testGetRequestValue.

@Test
public void testGetRequestValue() {
    WPasswordField field = new WPasswordField();
    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));
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 24 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WRadioButton_Test method testRadioButtonInRepeater.

@Test
public void testRadioButtonInRepeater() {
    RadioButtonGroup group = new RadioButtonGroup();
    WContainer repeated = new WContainer();
    repeated.add(group.addRadioButton());
    WRepeater repeater = new WRepeater(repeated);
    WContainer root = new WContainer();
    root.add(group);
    root.add(repeater);
    root.add(group.addRadioButton("X"));
    root.add(group.addRadioButton("Y"));
    root.add(group.addRadioButton("Z"));
    root.setLocked(true);
    setActiveContext(createUIContext());
    repeater.setBeanList(Arrays.asList("A", "B", "C"));
    // Check nothing selected
    Assert.assertNull("Selecte dvalue should be null", group.getSelectedValue());
    // Empty Request
    MockRequest request = new MockRequest();
    root.serviceRequest(request);
    Assert.assertNull("Selected value should still be null after empty request", group.getSelectedValue());
    // Setup request with button on repeater selected
    request = setupRequest(group, "B");
    root.serviceRequest(request);
    Assert.assertEquals("Selected value should be 'B' after request", "B", group.getSelectedValue());
    // Setup request with button outside repeater
    request = setupRequest(group, "X");
    root.serviceRequest(request);
    Assert.assertEquals("Selected value should be 'X' after request", "X", group.getSelectedValue());
    // Setup request with null value
    request = setupRequest(group, null);
    root.serviceRequest(request);
    Assert.assertNull("Selected value should be null after request", group.getSelectedValue());
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 25 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WRadioButton_Test method setupRequest.

/**
 * @param group the radio group to include on the request
 * @param value the value for the radio group
 * @return the request with the radio group
 */
private MockRequest setupRequest(final RadioButtonGroup group, final String value) {
    MockRequest request = new MockRequest();
    request.setParameter(group.getId() + "-h", "x");
    if (value != null) {
        request.setParameter(group.getId(), value);
    }
    return request;
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest)

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