use of com.github.bordertech.wcomponents.util.mock.MockResponse in project wcomponents by BorderTech.
the class ResponseCacheInterceptor_Test method testCache.
@Test
public void testCache() {
// 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()));
Assert.assertEquals("Cache-Control header not set correctly for CACHE", ConfigurationProperties.getResponseCacheSettings(), response.getHeaders().get("Cache-Control"));
Assert.assertNull("Pragma header should be null for CACHE", response.getHeaders().get("Pragma"));
Assert.assertNull("Expires header should be null for CACHE", response.getHeaders().get("Expires"));
}
use of com.github.bordertech.wcomponents.util.mock.MockResponse in project wcomponents by BorderTech.
the class ResponseCacheInterceptor_Test method testNoCache.
@Test
public void testNoCache() {
// Create interceptor
ResponseCacheInterceptor interceptor = new ResponseCacheInterceptor(CacheType.CONTENT_NO_CACHE);
interceptor.setBackingComponent(new WText());
// Mock Response
MockResponse response = new MockResponse();
interceptor.attachResponse(response);
// Render phase
interceptor.paint(new WebXmlRenderContext(response.getWriter()));
Assert.assertEquals("Cache-Control header not set correctly for NO_CACHE", ConfigurationProperties.getResponseNoCacheSettings(), response.getHeaders().get("Cache-Control"));
Assert.assertEquals("Pragma header not set correctly for NO_CACHE", "no-cache", response.getHeaders().get("Pragma"));
Assert.assertEquals("Expires header not set correctly for NO_CACHE", "-1", response.getHeaders().get("Expires"));
}
use of com.github.bordertech.wcomponents.util.mock.MockResponse 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.util.mock.MockResponse in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor_Test method testInterceptorOkStep.
@Test
public void testInterceptorOkStep() throws XpathException, SAXException, IOException {
MyApp app = new MyApp();
app.setLocked(true);
MockResponse response = doAjaxRequest(app, 1, 1);
assertXpathEvaluatesTo(app.target.getText(), "//ui:textfield", response.getWriterOutput());
}
use of com.github.bordertech.wcomponents.util.mock.MockResponse 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