use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class ResponseCacheInterceptor_Test method testOverrideDefaultCache.
@Test
public void testOverrideDefaultCache() {
/**
* Original config.
*/
Configuration originalConfig;
originalConfig = Config.getInstance();
String override = "OVERRIDE CACHE";
try {
// Test override cache settings
Configuration config = Config.copyConfiguration(originalConfig);
config.setProperty(ConfigurationProperties.RESPONSE_CACHE_SETTINGS, override);
Config.setConfiguration(config);
// Create interceptor
ResponseCacheInterceptor interceptor = new ResponseCacheInterceptor(CacheType.CONTENT_CACHE);
interceptor.setBackingComponent(new WText());
// Mock Response
MockResponse response = new MockResponse();
interceptor.attachResponse(response);
// Render phase
interceptor.paint(new WebXmlRenderContext(response.getWriter()));
// Check Override
Assert.assertEquals("Cache-Control header not overriden correctly for CACHE", override, response.getHeaders().get("Cache-Control"));
} finally {
// Remove overrides
Config.setConfiguration(originalConfig);
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class VelocityInterceptor_Test method testPaint.
@Test
public void testPaint() {
setActiveContext(createUIContext());
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
RenderContext renderContext = new WebXmlRenderContext(printWriter);
MyVelocityComponent component = new MyVelocityComponent();
component.setTemplate("com/github/bordertech/wcomponents/container/VelocityComponent_Test1.vm");
component.paint(renderContext);
String renderedFormat = stringWriter.toString().trim();
Assert.assertEquals("Incorrect rendered format", TEST_VALUE, renderedFormat);
// Errors in a template should not throw an exception, or render anything
// Method called using reflection that results in a MethodInvocationException
component.setTemplate("com/github/bordertech/wcomponents/container/VelocityComponent_Test2.vm");
stringWriter.getBuffer().setLength(0);
component.paint(renderContext);
renderedFormat = stringWriter.toString().trim();
Assert.assertEquals("Incorrect rendered format", "", renderedFormat);
// Template that #includes a non-existant template
component.setTemplate("com/github/bordertech/wcomponents/container/VelocityComponent_Test3.vm");
stringWriter.getBuffer().setLength(0);
component.paint(renderContext);
renderedFormat = stringWriter.toString().trim();
Assert.assertEquals("Incorrect rendered format", "", renderedFormat);
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext 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;
}
Aggregations