use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class AbstractWComponent_Test method testVisibilityAndFlow.
@Test
public void testVisibilityAndFlow() {
// a
// /|\
// b c d
// |
// e
TestComp a = new TestComp("a");
TestComp b = new TestComp("b");
TestComp c = new TestComp("c");
TestComp d = new TestComp("d");
TestComp e = new TestComp("e");
a.add(b);
a.add(c);
a.add(d);
b.add(e);
// c is invisible by default.
c.setVisible(false);
a.setLocked(true);
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
// The standard lifecycle flow.
a.serviceRequest(request);
a.preparePaint(request);
a.paint(new WebXmlRenderContext(printWriter));
// Check that lifecycle methods were called as expected.
Assert.assertEquals("Handle request should have been called on 'a'", 1, a.getHandleRequestCount());
Assert.assertEquals("Handle request should have been called on 'b'", 1, b.getHandleRequestCount());
Assert.assertEquals("Handle request should have been called on static invisible 'c'", 0, c.getHandleRequestCount());
Assert.assertEquals("Handle request should have been calle on 'd'", 1, d.getHandleRequestCount());
Assert.assertEquals("Handle request should have been calle on 'e'", 1, e.getHandleRequestCount());
Assert.assertEquals("Prepare paint should have been called on 'a'", 1, a.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on 'b'", 1, b.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on static invisible 'c'", 0, c.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on 'd'", 1, d.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on 'e'", 1, e.getPreparePaintCount());
Assert.assertEquals("Incorrect paint order", "abed", stringWriter.toString());
// Reset the TestComp call flags.
a.reset();
// Make b invisible for user
b.setVisible(false);
// Create a new writer.
stringWriter = new StringWriter();
printWriter = new PrintWriter(stringWriter);
a.serviceRequest(request);
a.preparePaint(request);
a.paint(new WebXmlRenderContext(printWriter));
// Check that lifecycle methods were called as expected.
Assert.assertEquals("Handle request should have been called on 'a'", 1, a.getHandleRequestCount());
Assert.assertEquals("Handle request should have been called on dynamic invisible 'b'", 0, b.getHandleRequestCount());
Assert.assertEquals("Handle request should have been called on static invisible 'c'", 0, c.getHandleRequestCount());
Assert.assertEquals("Handle request should have been calle on 'd'", 1, d.getHandleRequestCount());
Assert.assertEquals("Handle request should have been calle on child 'e' of dynamic invisible 'b'", 0, e.getHandleRequestCount());
Assert.assertEquals("Prepare paint should have been called on 'a'", 1, a.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on dynamic invisible 'b'", 0, b.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on static invisible 'c'", 0, c.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on 'd'", 1, d.getPreparePaintCount());
Assert.assertEquals("Prepare paint should have been called on child 'e' of dynamic invisible 'b'", 0, e.getPreparePaintCount());
Assert.assertEquals("Incorrect paint order", "ad", stringWriter.toString());
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class UicProfileButton_Test method testAfterPaintButtonPressed.
@Test
public void testAfterPaintButtonPressed() {
UicProfileButton button = new UicProfileButton();
button.setLocked(true);
setActiveContext(createUIContext());
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter);
MockRequest request = new MockRequest();
button.setPressed(true, request);
button.afterPaint(new WebXmlRenderContext(writer));
Assert.assertTrue("for button pressed afterpaint writer output should start with <br/><br/>", strWriter.toString().startsWith("<br/><br/>"));
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class UicProfileButton_Test method testAfterPaintButtonNotPressed.
@Test
public void testAfterPaintButtonNotPressed() {
UicProfileButton button = new UicProfileButton();
button.setLocked(true);
setActiveContext(createUIContext());
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter);
MockRequest request = new MockRequest();
button.setPressed(false, request);
button.afterPaint(new WebXmlRenderContext(writer));
Assert.assertEquals("for button not pressed afterPaint writer output should be empty", strWriter.toString(), "");
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WPopup_Test method testNotVisibleAfterPaint.
@Test
public void testNotVisibleAfterPaint() {
WPopup popup = new WPopup();
// Should default to not visible
Assert.assertFalse("Popup should not be visible by default", popup.isVisible());
// Make visible
popup.setLocked(true);
setActiveContext(createUIContext());
popup.setVisible(true);
// Check not visible after paint
popup.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
Assert.assertFalse("Popup should not be visible after paint", popup.isVisible());
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WebUtilities method renderWithTransformToHTML.
/**
* Renders and transforms the given WComponent to a HTML String outside of the context of a Servlet.
*
* @param request the request being responded to
* @param component the root WComponent to render
* @param includePageShell true if include page shell
* @return the rendered output as a String.
*/
public static String renderWithTransformToHTML(final Request request, final WComponent component, final boolean includePageShell) {
// Setup a context (if needed)
boolean needsContext = UIContextHolder.getCurrent() == null;
if (needsContext) {
UIContextHolder.pushContext(new UIContextImpl());
}
try {
// Link Interceptors
InterceptorComponent templateRender = new TemplateRenderInterceptor();
InterceptorComponent transformXML = new TransformXMLInterceptor();
templateRender.setBackingComponent(transformXML);
if (includePageShell) {
transformXML.setBackingComponent(new PageShellInterceptor());
}
// Attach Component and Mock Response
InterceptorComponent chain = templateRender;
chain.attachUI(component);
chain.attachResponse(new MockResponse());
// Render chain
StringWriter buffer = new StringWriter();
chain.preparePaint(request);
try (PrintWriter writer = new PrintWriter(buffer)) {
chain.paint(new WebXmlRenderContext(writer));
}
return buffer.toString();
} finally {
if (needsContext) {
UIContextHolder.popContext();
}
}
}
Aggregations