use of com.github.bordertech.wcomponents.ContentEscape in project wcomponents by BorderTech.
the class WrongStepContentInterceptor_Test method sendContentRequest.
/**
* Utility method to send a mock request to the application.
*
* @param target the target content.
* @param clientStep the client-side step count
* @param serverStep the server-side step count
* @return the response.
*/
private MockResponse sendContentRequest(final WComponent target, final int clientStep, final int serverStep) {
UIContext uic = createUIContext();
uic.setUI(WebUtilities.getTop(target));
WServlet.WServletEnvironment env = new WServlet.WServletEnvironment("/app", "http://localhost", "");
env.setStep(serverStep);
uic.setEnvironment(env);
setActiveContext(uic);
MockRequest request = new MockRequest();
request.setParameter(Environment.TARGET_ID, target.getId());
request.setParameter(Environment.STEP_VARIABLE, String.valueOf(clientStep));
MockResponse response = new MockResponse();
InterceptorComponent interceptor = new WrongStepContentInterceptor();
interceptor.attachUI(uic.getUI());
interceptor.attachResponse(response);
// Handle the request. This will either return the content or a step error
try {
interceptor.serviceRequest(request);
interceptor.preparePaint(request);
interceptor.paint(new WebXmlRenderContext(response.getWriter()));
} catch (ContentEscape escape) {
try {
// Content has been returned
escape.setRequest(request);
escape.setResponse(response);
escape.escape();
} catch (IOException e) {
Assert.fail("Failed to write content");
}
} catch (ErrorCodeEscape escape) {
try {
escape.setRequest(request);
escape.setResponse(response);
escape.escape();
} catch (IOException e) {
Assert.fail("Failed to write error content");
}
} catch (ActionEscape ignored) {
// don't care
}
// Step error
return response;
}
Aggregations