use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractWMultiSelectList_Test method testDoHandleRequestWithGroupOptions.
@Test
public void testDoHandleRequestWithGroupOptions() {
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS_WITH_GROUPS, true);
// Setup Request with optionA
MockRequest request = setupSingleOptionRequest(multi, OPTION_A);
boolean changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionA", OPTION_A, multi.getSelected().get(0));
Assert.assertTrue("doHandleRequest should have returned true", changed);
// Setup Request with optionB
request = setupSingleOptionRequest(multi, OPTION_B);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionB", OPTION_B, multi.getSelected().get(0));
Assert.assertTrue("doHandleRequest should have returned true", changed);
// Setup Request with optionC
request = setupSingleOptionRequest(multi, OPTION_C);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionC", OPTION_C, multi.getSelected().get(0));
Assert.assertTrue("doHandleRequest should have returned true", changed);
// Setup Request with option null
request = setupSingleOptionRequest(multi, OPTION_NULL);
changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be null option", OPTION_NULL, multi.getSelected().get(0));
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 testDoHandleRequestNothingSelectedWithNullOption.
@Test
public void testDoHandleRequestNothingSelectedWithNullOption() {
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS_WITH_NULL, 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 testDoHandleRequestWithInvalidOption.
@Test
public void testDoHandleRequestWithInvalidOption() {
AbstractWMultiSelectList multi = new MyWMultiSelectList(OPTIONS, true);
// Set selected to OptionA
multi.setSelected(SELECTED_A);
// Setup Request with Invalid Option
MockRequest request = setupNothingSelectedRequest(multi);
request.setParameter(multi.getId(), OPTION_INVALID);
boolean changed = multi.doHandleRequest(request);
Assert.assertEquals("Selected option should be optionA", SELECTED_A, 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 AbstractWSingleSelectList_Test method testDoHandleRequestWithNullOption.
@Test
public void testDoHandleRequestWithNullOption() {
AbstractWSingleSelectList single = new MyWSingleSelectList(OPTIONS_WITH_NULL, true);
// Set selected to OptionA
single.setSelected(OPTION_A);
// Setup Request with null option
MockRequest request = setupRequest(single, OPTION_NULL);
boolean changed = single.doHandleRequest(request);
Assert.assertNull("Selected option should have changed to null option", single.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 AbstractWSingleSelectList_Test method testDoHandleRequestLegacyMatching.
@Test
public void testDoHandleRequestLegacyMatching() {
Boolean optionA = Boolean.TRUE;
Boolean optionB = null;
Boolean optionC = Boolean.FALSE;
List<Boolean> options = Arrays.asList(new Boolean[] { optionA, optionB, optionC });
String selectedLegacy = "false";
// Set action on change
AbstractWSingleSelectList single = new MyWSingleSelectList(options, true);
// Set selected to OptionA - "String Representation" (Legacy String match)
// Get value from the bean (nut use setData)
single.setBeanProperty(".");
single.setLocked(true);
setActiveContext(createUIContext());
single.setBean(selectedLegacy);
// Setup Request with optionC (No Change)
MockRequest request = setupRequest(single, optionC);
boolean changed = single.doHandleRequest(request);
// Action should not trigger but selected should now be the correct option
Assert.assertEquals("Selected should have changed to optionA", optionC, single.getSelected());
Assert.assertFalse("doHandleRequest should have returned false", changed);
}
Aggregations