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());
}
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();
}
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());
}
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());
}
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());
}
Aggregations