Search in sources :

Example 56 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class AjaxDebugStructureInterceptor_Test method doAjaxRequest.

/**
 * Does an AJAX request for the app.
 *
 * @param app the MyApp instance to do an AJAX request for.
 * @return the AJAX xml output.
 */
private String doAjaxRequest(final MyApp app) {
    UIContext uic = createUIContext();
    uic.setUI(app);
    setActiveContext(uic);
    // Create interceptors
    AjaxSetupInterceptor ajaxSetupInterceptor = new AjaxSetupInterceptor();
    AjaxPageShellInterceptor ajaxPageInterceptor = new AjaxPageShellInterceptor();
    AjaxInterceptor ajaxInterceptor = new AjaxInterceptor();
    AjaxDebugStructureInterceptor debugInterceptor = new AjaxDebugStructureInterceptor();
    // Create chain
    debugInterceptor.setBackingComponent(ajaxInterceptor);
    ajaxPageInterceptor.setBackingComponent(debugInterceptor);
    ajaxSetupInterceptor.setBackingComponent(ajaxPageInterceptor);
    ajaxSetupInterceptor.attachUI(app);
    // Action phase
    MockRequest request = new MockRequest();
    AjaxHelper.registerComponent(app.target.getId(), app.trigger.getId());
    request.setParameter(WServlet.AJAX_TRIGGER_PARAM_NAME, app.trigger.getId());
    ajaxSetupInterceptor.serviceRequest(request);
    ajaxSetupInterceptor.preparePaint(request);
    // Render phase
    MockResponse response = new MockResponse();
    ajaxSetupInterceptor.attachResponse(response);
    ajaxSetupInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
    return response.getWriterOutput();
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest)

Example 57 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class DataListInterceptor_Test method testInterecptorWithNullOption.

@Test
public void testInterecptorWithNullOption() throws XpathException, SAXException, IOException {
    String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE_WITH_NULL_OPTION;
    // Create interceptor
    DataListInterceptor interceptor = new DataListInterceptor();
    interceptor.attachUI(new DefaultWComponent());
    // Action phase
    MockRequest request = new MockRequest();
    request.setParameter(WServlet.DATA_LIST_PARAM_NAME, tableKey);
    interceptor.serviceRequest(request);
    // Render phase
    MockResponse response = new MockResponse();
    interceptor.attachResponse(response);
    interceptor.paint(new WebXmlRenderContext(new PrintWriter(response.getWriter())));
    String xml = response.getWriterOutput();
    // Ensure that the data matches the test table.
    List<TestLookupTable.TableEntry> table = (List<TestLookupTable.TableEntry>) Factory.newInstance(LookupTable.class).getTable(tableKey);
    assertXpathEvaluatesTo(String.valueOf(table.size()), "count(/ui:datalist/ui:option)", xml);
    for (int i = 0; i < table.size(); i++) {
        if (table.get(i) == null) {
            assertXpathEvaluatesTo("", "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml);
            assertXpathEvaluatesTo("", "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml);
            assertXpathEvaluatesTo("true", "/ui:datalist/ui:option[" + (i + 1) + "]/@isNull", xml);
        } else {
            assertXpathEvaluatesTo(table.get(i).getCode(), "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml);
            assertXpathEvaluatesTo(table.get(i).getDesc(), "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml);
            assertXpathNotExists("/ui:datalist/ui:option[" + (i + 1) + "]/@isNull", xml);
        }
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) TestLookupTable(com.github.bordertech.wcomponents.TestLookupTable) List(java.util.List) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 58 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class ResponseCacheInterceptor_Test method testOverridePageNoCache.

@Test
public void testOverridePageNoCache() {
    /**
     * Original config.
     */
    Configuration originalConfig;
    originalConfig = Config.getInstance();
    String override = "OVERRIDE CONTENT NO CACHE";
    try {
        // Test override cache settings
        Configuration config = Config.copyConfiguration(originalConfig);
        config.setProperty(ConfigurationProperties.RESPONSE_NO_CACHE_SETTINGS, override);
        Config.setConfiguration(config);
        // 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()));
        // Check Override
        Assert.assertEquals("Cache-Control header not overriden correctly for CONTENT NO CACHE", override, response.getHeaders().get("Cache-Control"));
    } finally {
        // Remove overrides
        Config.setConfiguration(originalConfig);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) Configuration(org.apache.commons.configuration.Configuration) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 59 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext 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"));
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 60 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext 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"));
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Aggregations

WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)63 PrintWriter (java.io.PrintWriter)48 StringWriter (java.io.StringWriter)27 Test (org.junit.Test)27 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)17 UIContext (com.github.bordertech.wcomponents.UIContext)15 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)7 SystemException (com.github.bordertech.wcomponents.util.SystemException)7 WText (com.github.bordertech.wcomponents.WText)6 RenderContext (com.github.bordertech.wcomponents.RenderContext)5 WComponent (com.github.bordertech.wcomponents.WComponent)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)4 Configuration (org.apache.commons.configuration.Configuration)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 AllComponents (com.github.bordertech.wcomponents.AllComponents)3 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 Response (com.github.bordertech.wcomponents.Response)3