use of com.github.bordertech.wcomponents.ActionEscape in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor_Test method doAjaxRequest.
/**
* Does an AJAX request for the app.
*
* @param app the MyApp instance to do an AJAX request for.
* @param clientStep the client-side step counter
* @param serverStep the server-side step counter
* @return the response object.
*/
private MockResponse doAjaxRequest(final MyApp app, final int clientStep, final int serverStep) {
UIContext uic = createUIContext();
WServlet.WServletEnvironment env = new WServlet.WServletEnvironment(APP_POSTPATH, "http://localhost", "");
env.setStep(serverStep);
env.setSessionToken("T");
uic.setEnvironment(env);
uic.setUI(app);
setActiveContext(uic);
MockRequest request = new MockRequest();
MockResponse response = new MockResponse();
// Create interceptors
AjaxSetupInterceptor ajaxSetupInterceptor = new AjaxSetupInterceptor();
WrongStepAjaxInterceptor wrongStepInterceptor = new WrongStepAjaxInterceptor();
AjaxPageShellInterceptor ajaxPageInterceptor = new AjaxPageShellInterceptor();
AjaxInterceptor ajaxInterceptor = new AjaxInterceptor();
ajaxPageInterceptor.setBackingComponent(ajaxInterceptor);
wrongStepInterceptor.setBackingComponent(ajaxPageInterceptor);
ajaxSetupInterceptor.setBackingComponent(wrongStepInterceptor);
ajaxSetupInterceptor.attachUI(app);
ajaxSetupInterceptor.attachResponse(response);
// Action phase
try {
AjaxHelper.registerComponent(app.target.getId(), app.trigger.getId());
request.setParameter(WServlet.AJAX_TRIGGER_PARAM_NAME, app.trigger.getId());
request.setParameter(Environment.STEP_VARIABLE, String.valueOf(clientStep));
ajaxSetupInterceptor.serviceRequest(request);
ajaxSetupInterceptor.preparePaint(request);
// Render phase
ajaxSetupInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
} catch (ActionEscape ignored) {
// is thrown to skip render phase
}
return response;
}
use of com.github.bordertech.wcomponents.ActionEscape in project wcomponents by BorderTech.
the class WrongStepServerInterceptor_Test method testServiceRequestIncorrectSequenceWithRedirect.
@Test
public void testServiceRequestIncorrectSequenceWithRedirect() {
// Set redirect parameter
Configuration config = Config.copyConfiguration(originalConfig);
config.addProperty(ConfigurationProperties.STEP_ERROR_URL, "test.url");
Config.setConfiguration(config);
uic.getEnvironment().setStep(3);
request.setParameter(Environment.STEP_VARIABLE, "1");
interceptor.attachResponse(new MockResponse());
try {
interceptor.serviceRequest(request);
Assert.fail("Interceptor did not detect wrong step");
} catch (ActionEscape e) {
Assert.assertFalse("Action phase should not have occurred for step error with redirect", component.handleRequestCalled);
Assert.assertFalse("Handle Step Error should not have occurred for redirect", component.handleStepErrorCalled);
Assert.assertEquals("Step should not have been incremented", 3, uic.getEnvironment().getStep());
}
}
Aggregations