use of com.github.bordertech.wcomponents.util.mock.MockResponse in project wcomponents by BorderTech.
the class ResponseCacheInterceptor_Test method testOverrideContentCache.
@Test
public void testOverrideContentCache() {
/**
* Original config.
*/
Configuration originalConfig;
originalConfig = Config.getInstance();
String override = "OVERRIDE CONTENT 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 CONTENT 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 TemplateRenderInterceptorTest method generateOutput.
/**
* Render the component and execute the interceptor.
*
* @param testUI the test component
* @param headers Request headers to set (key/value pairs).
* @return the response
*/
private TestResult generateOutput(final MyComponent testUI, final Map<String, String> headers) {
InterceptorComponent interceptor = new TemplateRenderInterceptor();
interceptor.attachUI(testUI);
MockHttpServletRequest backing = new MockHttpServletRequest();
if (headers != null) {
for (String headerName : headers.keySet()) {
backing.setHeader(headerName, headers.get(headerName));
}
}
ServletRequest request = new ServletRequest(backing);
MockResponse response = new MockResponse();
interceptor.attachResponse(response);
StringWriter writer = new StringWriter();
UIContext uic = createUIContext();
uic.setLocale(new Locale("en"));
setActiveContext(uic);
try {
interceptor.preparePaint(request);
interceptor.paint(new WebXmlRenderContext(new PrintWriter(writer)));
} finally {
resetContext();
}
return new TestResult(writer.toString(), response.getContentType());
}
use of com.github.bordertech.wcomponents.util.mock.MockResponse in project wcomponents by BorderTech.
the class TransformXMLInterceptor_Test method generateOutput.
/**
* Render the component and execute the interceptor.
*
* @param testUI the test component
* @param headers Request headers to set (key/value pairs).
* @return the response
*/
private TestResult generateOutput(final MyComponent testUI, final Map<String, String> headers) {
InterceptorComponent interceptor = new TransformXMLInterceptor();
interceptor.attachUI(testUI);
MockHttpServletRequest backing = new MockHttpServletRequest();
if (headers != null) {
for (String headerName : headers.keySet()) {
backing.setHeader(headerName, headers.get(headerName));
}
}
ServletRequest request = new ServletRequest(backing);
MockResponse response = new MockResponse();
interceptor.attachResponse(response);
StringWriter writer = new StringWriter();
UIContext uic = createUIContext();
uic.setLocale(new Locale("en"));
setActiveContext(uic);
try {
interceptor.preparePaint(request);
interceptor.paint(new WebXmlRenderContext(new PrintWriter(writer)));
} finally {
resetContext();
}
return new TestResult(writer.toString(), response.getContentType());
}
use of com.github.bordertech.wcomponents.util.mock.MockResponse in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor_Test method testInterceptorRedirect.
@Test
public void testInterceptorRedirect() throws XpathException, SAXException, IOException {
Config.getInstance().setProperty(ConfigurationProperties.STEP_ERROR_URL, "http://test.test");
MyApp app = new MyApp();
app.setLocked(true);
MockResponse response = doAjaxRequest(app, 1, 99);
assertXpathEvaluatesTo("http://test.test", "//ui:redirect/@url", response.getWriterOutput());
}
use of com.github.bordertech.wcomponents.util.mock.MockResponse in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor_Test method testInterceptorWarp.
@Test
public void testInterceptorWarp() throws XpathException, SAXException, IOException {
Config.getInstance().setProperty(ConfigurationProperties.STEP_ERROR_URL, "");
MyApp app = new MyApp();
app.setLocked(true);
// Should redirect to app postpath
MockResponse response = doAjaxRequest(app, 1, 99);
assertXpathEvaluatesTo(APP_POSTPATH, "//ui:redirect/@url", response.getWriterOutput());
}
Aggregations