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();
}
}
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));
}
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));
}
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());
}
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;
}
Aggregations