Search in sources :

Example 86 with MockRequest

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

the class AjaxSetupInterceptor_Test method testNoTriggerId.

@Test(expected = SystemException.class)
public void testNoTriggerId() throws IOException {
    AjaxSetupInterceptor ajax = new AjaxSetupInterceptor();
    ajax.serviceRequest(new MockRequest());
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 87 with MockRequest

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

the class DebugStructureInterceptor_Test method doRequest.

/**
 * Does a request/response cycle for a WApplication.
 *
 * @return the xml output.
 */
private String doRequest() {
    WApplication app = new WApplication();
    app.setLocked(true);
    UIContext uic = createUIContext();
    uic.setUI(app);
    setActiveContext(uic);
    // Create interceptor
    PageShellInterceptor pageInterceptor = new PageShellInterceptor();
    DebugStructureInterceptor debugInterceptor = new DebugStructureInterceptor();
    pageInterceptor.setBackingComponent(debugInterceptor);
    pageInterceptor.attachUI(app);
    // Action phase
    MockRequest request = new MockRequest();
    pageInterceptor.serviceRequest(request);
    pageInterceptor.preparePaint(request);
    // Render phase
    MockResponse response = new MockResponse();
    pageInterceptor.attachResponse(response);
    pageInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
    return response.getWriterOutput();
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest)

Example 88 with MockRequest

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

the class SessionTokenContentInterceptor_Test method testServiceRequestNoTokenOnRequest.

@Test(expected = SessionTokenException.class)
public void testServiceRequestNoTokenOnRequest() {
    // Setup interceptor
    SessionTokenContentInterceptor interceptor = new SessionTokenContentInterceptor();
    MyBackingContent component = new MyBackingContent();
    interceptor.attachUI(component);
    // Setup session token
    UIContext uic = UIContextHolder.getCurrent();
    uic.getEnvironment().setSessionToken("X");
    // Process request
    interceptor.serviceRequest(new MockRequest());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 89 with MockRequest

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

the class SessionTokenContentInterceptor_Test method testServiceRequestNoTokenOnUIC.

@Test(expected = SessionTokenException.class)
public void testServiceRequestNoTokenOnUIC() {
    SessionTokenContentInterceptor interceptor = new SessionTokenContentInterceptor();
    interceptor.serviceRequest(new MockRequest());
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 90 with MockRequest

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

the class SubordinateControlInterceptor_Test method testServiceRequestApplyControls.

@Test
public void testServiceRequestApplyControls() {
    ButtonState state = new ButtonState();
    // Create Target
    WButton target = new WButton();
    target.setAction((final ActionEvent event) -> {
        state.setClicked(true);
    });
    // Create Control - Enable/Disable Button
    WCheckBox box = new WCheckBox();
    Rule rule = new Rule();
    rule.setCondition(new Equal(box, Boolean.TRUE));
    rule.addActionOnTrue(new Enable(target));
    rule.addActionOnFalse(new Disable(target));
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    // Create component tree
    WContainer root = new WContainer();
    root.add(control);
    root.add(box);
    root.add(target);
    // Setup Intercepter
    SubordinateControlInterceptor interceptor = new SubordinateControlInterceptor();
    interceptor.setBackingComponent(root);
    UIContext uic = createUIContext();
    uic.setUI(root);
    setActiveContext(uic);
    state.setClicked(false);
    // Test Service Request - Empty Request and no control registered, so the control should not be applied
    MockRequest request = new MockRequest();
    interceptor.serviceRequest(request);
    // Target should still be enabled (control not applied)
    Assert.assertFalse("After service request target should be enabled", target.isDisabled());
    // Button not clicked
    Assert.assertFalse("Button should not have been clicked", state.isClicked());
    // Test Service Request - Try to click button while it is disabled and should not be clicked
    target.setDisabled(true);
    request.setParameter(target.getId(), "x");
    interceptor.serviceRequest(request);
    // Target should still be disabled (control not applied, as still not registered)
    Assert.assertTrue("After service request target should be disabled", target.isDisabled());
    // Button not clicked
    Assert.assertFalse("Button should not have been clicked while disabled", state.isClicked());
    // Test Prepare Paint - Should register and apply the subordinate control
    target.setDisabled(false);
    request = new MockRequest();
    interceptor.preparePaint(request);
    // Target should be disabled (Disabled by control as box is not selected)
    Assert.assertTrue("After service request target should be disabled", target.isDisabled());
    // Test Service Request - Simulate button click as it was enabled on the client by the check box being selected.
    // As the controls have been registered from the Prepare Paint, they will be applied in the Service Request and
    // this will enable the button and allow it to be clicked.
    state.setClicked(false);
    request.setParameter(target.getId(), "x");
    setupCheckBoxRequest(box, request, true);
    interceptor.serviceRequest(request);
    // Target should be enabled (enabled by control as box is selected)
    Assert.assertFalse("After service request target should be enabled", target.isDisabled());
    // Button should have been clicked
    Assert.assertTrue("Button should have been clicked", state.isClicked());
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) UIContext(com.github.bordertech.wcomponents.UIContext) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WButton(com.github.bordertech.wcomponents.WButton) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Equal(com.github.bordertech.wcomponents.subordinate.Equal) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Rule(com.github.bordertech.wcomponents.subordinate.Rule) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Disable(com.github.bordertech.wcomponents.subordinate.Disable) 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