Search in sources :

Example 66 with MockRequest

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

the class UicProfileButton_Test method testAfterPaintButtonPressed.

@Test
public void testAfterPaintButtonPressed() {
    UicProfileButton button = new UicProfileButton();
    button.setLocked(true);
    setActiveContext(createUIContext());
    StringWriter strWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(strWriter);
    MockRequest request = new MockRequest();
    button.setPressed(true, request);
    button.afterPaint(new WebXmlRenderContext(writer));
    Assert.assertTrue("for button pressed afterpaint writer output should start with <br/><br/>", strWriter.toString().startsWith("<br/><br/>"));
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 67 with MockRequest

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

the class UicProfileButton_Test method testDumpAll.

@Test
public void testDumpAll() {
    UicProfileButton button = new UicProfileButton();
    button.setLocked(true);
    setActiveContext(createUIContext());
    MockRequest request = new MockRequest();
    button.setPressed(true, request);
    String result = button.dumpAll().toString();
    // result table contains class name
    Assert.assertTrue("dump table should contain component class name", result.indexOf("<td>" + button.getClass().getName() + "</td>") != -1);
    // result table contains component id
    Assert.assertTrue("dump table should contain component id", result.indexOf("<td>" + button.getId() + "</td>") != -1);
    // result table contains isSerialisable
    Assert.assertTrue("dump table should contain serialisability", result.indexOf("<td>true</td>") != -1);
    // result table contains size
    Assert.assertTrue("dump table should contain size", result.indexOf("<td>0</td></tr>") != -1);
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 68 with MockRequest

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

the class UicProfileButton_Test method testAfterPaintButtonNotPressed.

@Test
public void testAfterPaintButtonNotPressed() {
    UicProfileButton button = new UicProfileButton();
    button.setLocked(true);
    setActiveContext(createUIContext());
    StringWriter strWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(strWriter);
    MockRequest request = new MockRequest();
    button.setPressed(false, request);
    button.afterPaint(new WebXmlRenderContext(writer));
    Assert.assertEquals("for button not pressed afterPaint writer output should be empty", strWriter.toString(), "");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 69 with MockRequest

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

the class WAjaxControl_Test method testPreparePaintComponent.

@Test
public void testPreparePaintComponent() {
    WApplication app = new WApplication();
    AjaxTrigger trigger = new WButton();
    AjaxTarget target = new WPanel();
    WAjaxControl control = new WAjaxControl(trigger, target);
    app.add(control);
    app.add(trigger);
    app.add(target);
    app.setLocked(true);
    UIContext uic = createUIContext();
    uic.setUI(app);
    setActiveContext(uic);
    MockRequest req = new MockRequest();
    control.handleRequest(req);
    control.preparePaint(req);
    AjaxOperation ajaxOperation = AjaxHelper.getAjaxOperation(trigger.getId());
    Assert.assertNotNull("Ajax operation should have been registered", ajaxOperation);
    Assert.assertEquals("Incorrect ajax operation trigger id", trigger.getId(), ajaxOperation.getTriggerId());
    Assert.assertEquals("Incorrect ajax operation targets", target.getId(), ajaxOperation.getTargets().get(0));
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 70 with MockRequest

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

the class WDataTable_Test method testSingleHandleSelectionRequest.

@Test
public void testSingleHandleSelectionRequest() {
    WDataTable table = new WDataTable();
    table.setSelectMode(WDataTable.SelectMode.SINGLE);
    table.setDataModel(new SimpleTableDataModel(new String[100][1]));
    table.setLocked(true);
    setActiveContext(createUIContext());
    MockRequest request = new MockRequest();
    request.setParameter(table.getId() + "-h", "x");
    request.setParameter(table.getId() + ".selected", new String[] { "5", "6", "7" });
    table.handleRequest(request);
    Assert.assertEquals("Should only have selected the first item after handleRequest", Arrays.asList(new Integer[] { 5 }), table.getSelectedRows());
    resetContext();
    Assert.assertTrue("Incorrect default selection after handleRequest", table.getSelectedRows().isEmpty());
}
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