use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class GridLayoutRenderer_Test method testDoRender.
@Test
public void testDoRender() throws IOException, SAXException, XpathException {
final String text1 = "GridRenderer_Test.testPaint.text1";
final String text2 = "GridRenderer_Test.testPaint.text2";
WPanel panel = new WPanel();
panel.setLayout(new GridLayout(1, 2, GAP, BIG_GAP));
assertSchemaMatch(panel);
assertXpathEvaluatesTo("1", "//ui:panel/ui:gridlayout/@rows", panel);
assertXpathEvaluatesTo("2", "//ui:panel/ui:gridlayout/@cols", panel);
assertXpathEvaluatesTo(GAP.toString(), "//ui:panel/ui:gridlayout/@hgap", panel);
assertXpathEvaluatesTo(BIG_GAP.toString(), "//ui:panel/ui:gridlayout/@vgap", panel);
assertXpathNotExists("//ui:panel/ui:gridlayout/ui:cell", panel);
panel.add(new WText(text1));
panel.add(new WText(text2));
assertXpathEvaluatesTo("2", "count(//ui:panel/ui:gridlayout/ui:cell)", panel);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:gridlayout/ui:cell[1])", panel);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:gridlayout/ui:cell[2])", panel);
}
use of com.github.bordertech.wcomponents.WText 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.WText in project wcomponents by BorderTech.
the class ResponseCacheInterceptor_Test method testOverrideDefaultNoCache.
@Test
public void testOverrideDefaultNoCache() {
/**
* Original config.
*/
Configuration originalConfig;
originalConfig = Config.getInstance();
String override = "OVERRIDE 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 NO CACHE", override, response.getHeaders().get("Cache-Control"));
} finally {
// Remove overrides
Config.setConfiguration(originalConfig);
}
}
use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class FlowLayoutRenderer_Test method testDoRenderWithContent.
@Test
public void testDoRenderWithContent() throws IOException, SAXException, XpathException {
final String text1 = "FlowRenderer_Test.testPaint.text1";
final String text2 = "FlowRenderer_Test.testPaint.text2";
WPanel panel = new WPanel();
panel.setLayout(new FlowLayout());
assertSchemaMatch(panel);
panel.add(new WText(text1));
panel.add(new WText(text2));
assertSchemaMatch(panel);
assertXpathEvaluatesTo("2", "count(//ui:panel/ui:flowlayout/ui:cell)", panel);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:flowlayout/ui:cell[1])", panel);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:flowlayout/ui:cell[2])", panel);
}
use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testDoPaintWithChildren.
@Test
public void testDoPaintWithChildren() throws IOException, SAXException, XpathException {
WApplication application = new WApplication();
WText text = new WText("test text");
WButton button = new WButton("button");
application.add(text);
application.add(button);
MockWEnvironment environment = new MockWEnvironment();
UIContext uic = createUIContext();
uic.setEnvironment(environment);
setActiveContext(uic);
application.setUnsavedChanges(true);
// Check Schema
assertSchemaMatch(application);
assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
// Check Children
assertXpathEvaluatesTo("test text", "normalize-space(//ui:application/text()[1])", application);
assertXpathEvaluatesTo("1", "count(//ui:application/html:button)", application);
}
Aggregations