use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.
the class AbstractContainerHelper method createUIContext.
/**
* Creates and initialises a new UIContext.
*
* @return a new UIContext.
*/
protected UIContext createUIContext() {
// Create UIC
UIContext uic = new UIContextImpl();
uic.setUI(getUI());
return uic;
}
use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.
the class WComponentTestCase method resetUIContext.
/**
* Replaces the UIContext with a new copy, to emulate a fresh session.
*/
protected void resetUIContext() {
uic = new UIContextImpl();
uic.setUI(getWrappedUi());
}
use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.
the class DiagnosticImpl_Test method testGetDescription.
@Test
public void testGetDescription() {
final UIContext uic = new UIContextImpl();
final WTextField input = new WTextField();
final String noArgsMessage = "The field is required";
final String fieldArgMessage = "The field ''{0}'' is required";
// Test with no formatting
DiagnosticImpl diag = new DiagnosticImpl(Diagnostic.INFO, uic, input, noArgsMessage);
Assert.assertEquals("Incorrect description text", noArgsMessage, diag.getDescription());
// Test with formatting, but missing label text should default to empty String
diag = new DiagnosticImpl(Diagnostic.INFO, uic, input, fieldArgMessage, input);
Assert.assertEquals("Incorrect description text", "The field '' is required", diag.getDescription());
// Test with formatting with accessible text set
input.setAccessibleText("a");
Assert.assertEquals("Incorrect description text", "The field 'a' is required", diag.getDescription());
// Test with formatting with toolTip
input.setAccessibleText(null);
input.setToolTip("a tooltip");
Assert.assertEquals("Incorrect description text", "The field 'a tooltip' is required", diag.getDescription());
// Test with label set
WLabel label = new WLabel("bc", input);
Assert.assertEquals("Incorrect description text", "The field 'bc' is required", diag.getDescription());
// Test with label set, with a colon at the end
label.setText("def:");
Assert.assertEquals("Incorrect description text", "The field 'def' is required", diag.getDescription());
}
use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.
the class WComponentRenderPerfTest method runRenderTest.
/**
* Runs the render test.
*/
private static void runRenderTest() {
UIContextImpl uic = new UIContextImpl();
PrintWriter printWriter = new PrintWriter(new NullWriter());
RenderContext renderContext = new WebXmlRenderContext(printWriter);
WComponent component = null;
long baseLineMemory = getHeapUsed();
try {
component = (WComponent) Class.forName(CLASS_TO_TEST).newInstance();
} catch (Exception e) {
String msg = "Unable to instantiate test component: " + CLASS_TO_TEST;
LOG.error(LINE_PREFIX + msg);
throw new SystemException(msg, e);
}
long memBeforePaint = getHeapUsed() - baseLineMemory;
// Set up velocity etc. to obtain a memory reading, and
// so that the performance results aren't skewed too much
UIContextHolder.pushContext(uic);
try {
component.paint(renderContext);
long memAfterOnePaint = getHeapUsed() - baseLineMemory;
long startTime = System.currentTimeMillis();
// Figure out the loop overhead
for (int i = 0; i < NUM_RENDERS; i++) {
}
long loopOverhead = System.currentTimeMillis() - startTime;
startTime = System.currentTimeMillis();
// Now run the render test
for (int i = 0; i < NUM_RENDERS; i++) {
component.paint(renderContext);
}
long elapsedTime = System.currentTimeMillis() - startTime - loopOverhead;
long memAfterAllPaints = getHeapUsed() - baseLineMemory;
LOG.info(LINE_PREFIX + "Memory use before paint: " + memBeforePaint);
LOG.info(LINE_PREFIX + "Memory use after 1 paint: " + memAfterOnePaint);
LOG.info(LINE_PREFIX + "Memory use after " + NUM_RENDERS + " paints: " + memAfterAllPaints);
LOG.info(LINE_PREFIX + "Render time: " + (elapsedTime / (double) NUM_RENDERS) + "ms");
Object[] treeAndSession = new Object[] { component, uic };
ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
LOG.info(LINE_PREFIX + "Component mem use: " + ((ObjectGraphNode) root.getChildAt(0)).getSize());
LOG.info(LINE_PREFIX + "UIC mem use: " + ((ObjectGraphNode) root.getChildAt(1)).getSize());
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.
the class WServlet_Test method testServiceAjaxRequest.
@Test
public void testServiceAjaxRequest() throws ServletException, IOException {
AjaxTestUI ui = new AjaxTestUI();
ui.setLocked(true);
MockHttpSession session1 = new MockHttpSession();
UIContextImpl uic1 = new UIContextImpl();
uic1.setEnvironment(new WServlet.WServletEnvironment("app", "http://localhost", ""));
uic1.setUI(ui);
uic1.getEnvironment().setSessionToken("1");
uic1.getEnvironment().setStep(1);
MockHttpSession session2 = new MockHttpSession();
UIContextImpl uic2 = new UIContextImpl();
uic2.setEnvironment(new WServlet.WServletEnvironment("app", "http://localhost", ""));
uic2.setUI(ui);
uic2.getEnvironment().setSessionToken("2");
// Request cycle for session 1
setActiveContext(uic1);
ui.serviceRequest(new ServletRequest(new MockHttpServletRequest(session1)));
ui.preparePaint(new ServletRequest(new MockHttpServletRequest(session1)));
ui.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
// Request cycle for session 2
setActiveContext(uic2);
ui.serviceRequest(new ServletRequest(new MockHttpServletRequest(session2)));
ui.preparePaint(new ServletRequest(new MockHttpServletRequest(session2)));
ui.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
// check handle request / paint counts for each session - label should not have been painted for either.
setActiveContext(uic1);
Assert.assertEquals("HandleRequest should have been called for main panel in session1", 1, ui.mainPanel.getHandleRequestCount());
Assert.assertEquals("HandleRequest should have been called for ajax panel in session1", 1, ui.ajaxPanel.getHandleRequestCount());
Assert.assertEquals("HandleRequest should have been called for label panel in session1", 1, ui.label.getHandleRequestCount());
Assert.assertEquals("Main panel should have painted in session1", 1, ui.mainPanel.getPaintCount());
Assert.assertEquals("Ajax panel should have painted in session1", 1, ui.ajaxPanel.getPaintCount());
Assert.assertEquals("Label should not have painted in session1", 0, ui.label.getPaintCount());
setActiveContext(uic2);
Assert.assertEquals("HandleRequest should have been called for main panel in session2", 1, ui.mainPanel.getHandleRequestCount());
Assert.assertEquals("HandleRequest should have been called for ajax panel in session2", 1, ui.ajaxPanel.getHandleRequestCount());
Assert.assertEquals("HandleRequest should have been called for label panel in session2", 1, ui.label.getHandleRequestCount());
Assert.assertEquals("Main panel should have painted in session2", 1, ui.mainPanel.getPaintCount());
Assert.assertEquals("Ajax panel should have painted in session2", 1, ui.ajaxPanel.getPaintCount());
Assert.assertEquals("Label should not have painted in session2", 0, ui.label.getPaintCount());
}
Aggregations