Search in sources :

Example 51 with MockRequest

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

Example 52 with MockRequest

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

Example 53 with MockRequest

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

Example 54 with MockRequest

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

Example 55 with MockRequest

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