Search in sources :

Example 6 with RenderContext

use of com.github.bordertech.wcomponents.RenderContext in project wcomponents by BorderTech.

the class VelocityInterceptor_Test method testPaint.

@Test
public void testPaint() {
    setActiveContext(createUIContext());
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    RenderContext renderContext = new WebXmlRenderContext(printWriter);
    MyVelocityComponent component = new MyVelocityComponent();
    component.setTemplate("com/github/bordertech/wcomponents/container/VelocityComponent_Test1.vm");
    component.paint(renderContext);
    String renderedFormat = stringWriter.toString().trim();
    Assert.assertEquals("Incorrect rendered format", TEST_VALUE, renderedFormat);
    // Errors in a template should not throw an exception, or render anything
    // Method called using reflection that results in a MethodInvocationException
    component.setTemplate("com/github/bordertech/wcomponents/container/VelocityComponent_Test2.vm");
    stringWriter.getBuffer().setLength(0);
    component.paint(renderContext);
    renderedFormat = stringWriter.toString().trim();
    Assert.assertEquals("Incorrect rendered format", "", renderedFormat);
    // Template that #includes a non-existant template
    component.setTemplate("com/github/bordertech/wcomponents/container/VelocityComponent_Test3.vm");
    stringWriter.getBuffer().setLength(0);
    component.paint(renderContext);
    renderedFormat = stringWriter.toString().trim();
    Assert.assertEquals("Incorrect rendered format", "", renderedFormat);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

RenderContext (com.github.bordertech.wcomponents.RenderContext)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 PrintWriter (java.io.PrintWriter)5 Test (org.junit.Test)5 UIContext (com.github.bordertech.wcomponents.UIContext)3 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)3 AllComponents (com.github.bordertech.wcomponents.AllComponents)2 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)2 WLabel (com.github.bordertech.wcomponents.WLabel)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 StringWriter (java.io.StringWriter)2 Request (com.github.bordertech.wcomponents.Request)1 WButton (com.github.bordertech.wcomponents.WButton)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WebComponent (com.github.bordertech.wcomponents.WebComponent)1 ObjectGraphNode (com.github.bordertech.wcomponents.util.ObjectGraphNode)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 IOException (java.io.IOException)1