use of com.github.bordertech.wcomponents.render.webxml.VelocityRenderer in project wcomponents by BorderTech.
the class VelocityRenderer_Test method testGetUrl.
@Test
public void testGetUrl() {
String layoutUrl = "com/github/bordertech/wcomponents/velocity/VelocityRenderer_Test.vm";
VelocityRenderer layout = new VelocityRenderer(layoutUrl);
Assert.assertEquals("Incorrect url", layoutUrl, layout.getUrl());
}
use of com.github.bordertech.wcomponents.render.webxml.VelocityRenderer in project wcomponents by BorderTech.
the class UIManager method createRenderer.
/**
* Attempts to create a Renderer with the given name.
*
* @param rendererName the name of the Renderer
* @return a Renderer of the given type, or null if the class was not found.
*/
private static Renderer createRenderer(final String rendererName) {
if (rendererName.endsWith(".vm")) {
// This is a velocity template, so use a VelocityLayout
return new VelocityRenderer(rendererName);
}
try {
Class<?> managerClass = Class.forName(rendererName);
Object manager = managerClass.newInstance();
if (!(manager instanceof Renderer)) {
throw new SystemException(rendererName + " is not a Renderer");
}
return (Renderer) manager;
} catch (ClassNotFoundException e) {
// Legal - there might not a manager implementation in a given theme
return null;
} catch (InstantiationException e) {
throw new SystemException("Failed to instantiate " + rendererName, e);
} catch (IllegalAccessException e) {
throw new SystemException("Failed to access " + rendererName, e);
}
}
use of com.github.bordertech.wcomponents.render.webxml.VelocityRenderer in project wcomponents by BorderTech.
the class VelocityRenderer_Test method testPaint.
@Test
public void testPaint() {
TestComponent component = new TestComponent();
VelocityRenderer layout = new VelocityRenderer("com/github/bordertech/wcomponents/velocity/VelocityRenderer_Test.vm");
setActiveContext(createUIContext());
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
layout.render(component, new WebXmlRenderContext(printWriter));
printWriter.close();
String result = writer.toString();
Assert.assertTrue("Missing 'this'", result.contains("this=com.github.bordertech.wcomponents.velocity.VelocityRenderer_Test$TestComponent"));
Assert.assertTrue("Missing 'this.someProperty'", result.contains("[this.someProperty=somePropertyValue]"));
Assert.assertTrue("Missing 'uicontext'", result.contains("[uicontext=com.github.bordertech.wcomponents.UIContextImpl"));
Assert.assertTrue("Missing 'uic'", result.contains("uicontext=com.github.bordertech.wcomponents.UIContextImpl"));
Assert.assertTrue("Missing 'children'", result.contains("[children=[A, B, C, D]]"));
Assert.assertTrue("Missing 'childA'", result.contains("[childA=A]"));
Assert.assertTrue("Missing 'childB'", result.contains("[childB=B]"));
Assert.assertTrue("Missing 'childC'", result.contains("[childC=]"));
Assert.assertTrue("Missing 'test_list'", result.contains("[test_list=[C, D]]"));
Assert.assertTrue("Missing velocity map params", result.contains("[velocityMapParam=velocityMapParamValue]"));
Assert.assertTrue("Map should have been used", component.mapUsedCalled);
Assert.assertFalse("Should not contain debug markers", result.contains("<!-- Start"));
Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_VELOCITY_DEBUG, "true");
writer = new StringWriter();
printWriter = new PrintWriter(writer);
layout.render(component, new WebXmlRenderContext(printWriter));
printWriter.close();
result = writer.toString();
int startIndex = result.indexOf("<!-- Start " + layout.getUrl() + " -->");
int endIndex = result.indexOf("<!-- End " + layout.getUrl() + " -->");
Assert.assertTrue("Should contain start debug marker", startIndex != -1);
Assert.assertTrue("Should contain end debug marker", endIndex != -1);
Assert.assertTrue("Start debug marker should be before end debug marker", startIndex < endIndex);
}
use of com.github.bordertech.wcomponents.render.webxml.VelocityRenderer in project wcomponents by BorderTech.
the class VelocityRenderer_Test method testPaintMissingTemplate.
@Test
public void testPaintMissingTemplate() {
TestComponent component = new TestComponent();
VelocityRenderer layout = new VelocityRenderer("/com/github/bordertech/wcomponents/velocity/VelocityRenderer_Test_missing_template.vm");
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
layout.render(component, new WebXmlRenderContext(printWriter));
printWriter.close();
// This should still render, and just dump out the contents of the Velocity context.
String result = writer.toString();
Assert.assertTrue("Should have rendered output", result.contains("<td>this</td>"));
Assert.assertTrue("Should have rendered output", result.contains("<td>" + component.getClass().getName() + "</td>"));
}
Aggregations