use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractWMultiSelectList_Test method testDoHandleRequestBeanBound.
@Test
public void testDoHandleRequestBeanBound() {
// Set action on change
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS, true);
// Set Bean Property
multi.setBeanProperty("myOptions");
WContainer container = new WContainer();
container.add(multi);
multi.setLocked(true);
setActiveContext(createUIContext());
// Set a Bean that has no selections
MyBean bean = new MyBean();
container.setBean(bean);
// Test Nothing Selected and Empty Request (No Change)
MockRequest request = setupNothingSelectedRequest(multi);
boolean changed = multi.doHandleRequest(request);
Assert.assertEquals("Should have no option selected", EMPTY_LIST, multi.getSelected());
Assert.assertFalse("doHandleRequest should have returned false", changed);
// Setup Request with optionA (Change)
request = setupSingleOptionRequest(multi, OPTION_A);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionA", SELECTED_A, multi.getSelected());
Assert.assertTrue("doHandleRequest should have returned true", changed);
// Setup Request with optionA (No Change)
request = setupSingleOptionRequest(multi, OPTION_A);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionA", SELECTED_A, multi.getSelected());
Assert.assertFalse("doHandleRequest should have returned false", changed);
// Update Bean (should have optionA on the bean)
multi.updateBeanValue();
Assert.assertEquals("Bean should contain optionA", SELECTED_A, bean.getMyOptions());
// Clear Context so gets value from the bean
multi.reset();
Assert.assertEquals("Selected option should be optionA", SELECTED_A, multi.getSelected());
// Change Bean to optionB (Make sure the value is coming from the bean)
bean.setMyOptions(SELECTED_B);
Assert.assertEquals("Selected should be optionB coming from the bean", SELECTED_B, multi.getSelected());
// Setup Request with optionA, optionB (Change)
request = setupMultiOptionRequest(multi, ARRAY_OPTIONS_A_B);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionA and optionB", SELECTED_A_B, multi.getSelected());
Assert.assertTrue("doHandleRequest should have returned true", changed);
// Setup Empty Request (Change)
request = setupNothingSelectedRequest(multi);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Should have no option selected", EMPTY_LIST, multi.getSelected());
Assert.assertTrue("doHandleRequest should have returned true", changed);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractWMultiSelectList_Test method testUpdateBeanDefaultFirstOption.
@Test
public void testUpdateBeanDefaultFirstOption() {
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS, false);
// Set Bean Property
multi.setBeanProperty("myOptions");
// With User Context
multi.setLocked(true);
setActiveContext(createUIContext());
// Set Bean Property and Bean
MyBean bean = new MyBean();
multi.setBean(bean);
// Null Bean Value - getValue will default to first Option
Assert.assertEquals("Data should default to OptionA", SELECTED_A, multi.getValue());
// Test handle request is "no change"
MockRequest request = setupSingleOptionRequest(multi, OPTION_A);
boolean changed = multi.doHandleRequest(request);
Assert.assertFalse("doHandleRequest should return false as option should not change", changed);
// Update Bean (should have optionA on the bean)
Assert.assertNull("Bean should still be null", bean.getMyOptions());
multi.updateBeanValue();
Assert.assertEquals("Bean should contain optionA", SELECTED_A, bean.getMyOptions());
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractWMultiSelectList_Test method testDoHandleRequestNothingSelected.
@Test
public void testDoHandleRequestNothingSelected() {
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS, true);
// Setup Option Request with nothing selected
MockRequest request = setupMultiOptionRequest(multi, null);
boolean changed = multi.doHandleRequest(request);
Assert.assertEquals("Should have no option selected", EMPTY_LIST, multi.getSelected());
Assert.assertFalse("doHandleRequest should have returned false", changed);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractWMultiSelectList_Test method setupSingleOptionRequest.
/**
* @param target the target component
* @param option the option to select on the request
* @return a mock request with a single option selected
*/
private MockRequest setupSingleOptionRequest(final AbstractWMultiSelectList target, final Object option) {
MockRequest request = new MockRequest();
if (target.isAllowNoSelection()) {
request.setParameter(target.getId() + "-h", "x");
}
request.setParameter(target.getId(), target.optionToCode(option));
return request;
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractWMultiSelectList_Test method testDoHandleRequestEditable.
@Test
public void testDoHandleRequestEditable() {
// Set action on change
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS, true);
// Set Editable
multi.setEditable(true);
// Set selected to OptionA
multi.setSelected(SELECTED_A);
// Setup Request with "user entered text"
String userText = "user entered text";
setActiveContext(createUIContext());
MockRequest request = setupNothingSelectedRequest(multi);
request.setParameter(multi.getId(), userText);
boolean changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected should have changed to user text", userText, multi.getSelected().get(0));
Assert.assertTrue("doHandleRequest should have returned true", changed);
}
Aggregations