use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class DebugStructureInterceptor_Test method doRequest.
/**
* Does a request/response cycle for a WApplication.
*
* @return the xml output.
*/
private String doRequest() {
WApplication app = new WApplication();
app.setLocked(true);
UIContext uic = createUIContext();
uic.setUI(app);
setActiveContext(uic);
// Create interceptor
PageShellInterceptor pageInterceptor = new PageShellInterceptor();
DebugStructureInterceptor debugInterceptor = new DebugStructureInterceptor();
pageInterceptor.setBackingComponent(debugInterceptor);
pageInterceptor.attachUI(app);
// Action phase
MockRequest request = new MockRequest();
pageInterceptor.serviceRequest(request);
pageInterceptor.preparePaint(request);
// Render phase
MockResponse response = new MockResponse();
pageInterceptor.attachResponse(response);
pageInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
return response.getWriterOutput();
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WWindowInterceptor_Test method testServiceRequest.
@Test
public void testServiceRequest() {
final int initialServletStep = 123;
final int initialWindowStep = 111;
// Create app
WApplication app = new WApplication();
WWindow window = new WWindow();
window.setContent(new MockLabel("dummy"));
app.add(window);
WContent content = new WContent();
content.setContentAccess(new InternalResource("/wcomponents-test.properties", "test"));
app.add(content);
app.setLocked(true);
// Set up servlet env
WServlet.WServletEnvironment servletEnvironment = new WServlet.WServletEnvironment("/app", "", "");
servletEnvironment.setStep(initialServletStep);
// Set user session
UIContext uic = createUIContext();
uic.setUI(app);
uic.setEnvironment(servletEnvironment);
setActiveContext(uic);
window.setStep(initialWindowStep);
window.display();
// Target the content first - should pass through and update the environment's step
WWindowInterceptor interceptor = new WWindowInterceptor(true);
TestInterceptor testInterceptor = new TestInterceptor();
interceptor.setBackingComponent(testInterceptor);
interceptor.attachUI(app);
MockRequest request = new MockRequest();
request.setParameter(Environment.TARGET_ID, content.getId());
interceptor.serviceRequest(request);
Assert.assertEquals("Servlet step should have changed after serviceRequest", initialServletStep + 1, servletEnvironment.getStep());
Assert.assertEquals("Window step should not have changed", initialWindowStep, window.getStep());
interceptor.preparePaint(request);
Assert.assertEquals("Servlet step should have changed after preparePaint", initialServletStep + 2, servletEnvironment.getStep());
Assert.assertEquals("Window step should not have changed", initialWindowStep, window.getStep());
interceptor.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
Assert.assertEquals("Servlet step should have changed after paint", initialServletStep + 3, servletEnvironment.getStep());
Assert.assertEquals("Window step should not have changed", initialWindowStep, window.getStep());
servletEnvironment.setStep(initialServletStep);
request = new MockRequest();
request.setParameter(WWindow.WWINDOW_REQUEST_PARAM_KEY, window.getId());
interceptor.serviceRequest(request);
Assert.assertEquals("Window step should have changed after serviceRequest", initialWindowStep + 1, window.getStep());
Assert.assertEquals("Servlet step should not have changed", initialServletStep, servletEnvironment.getStep());
interceptor.preparePaint(request);
Assert.assertEquals("Window step should have changed after preparePaintnot have changed", initialWindowStep + 2, window.getStep());
Assert.assertEquals("Servlet step should not have changed", initialServletStep, servletEnvironment.getStep());
interceptor.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
Assert.assertEquals("Window step should have changed after paint", initialWindowStep + 3, window.getStep());
Assert.assertEquals("Servlet step should not have changed", initialServletStep, servletEnvironment.getStep());
String actualTargetId = testInterceptor.hiddenParams.get(WWindow.WWINDOW_REQUEST_PARAM_KEY);
Assert.assertEquals("Hidden params target id should be window id", window.getId(), actualTargetId);
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class UicStatsAsHtml_Test method testWriter.
/**
* Test writer.
*/
@Test
public void testWriter() {
// Set up a mock UI to test
WApplication app = new WApplication();
app.setLocked(true);
UIContext uic = new UIContextImpl();
uic.setUI(app);
setActiveContext(uic);
WButton button = new WButton("PUSH");
app.add(button);
WLabel label = new WLabel("HERE");
app.add(label);
// Run the UIStats extract
UicStats stats = new UicStats(uic);
stats.analyseWC(app);
StringWriter outStr = new StringWriter();
PrintWriter writer = new PrintWriter(outStr);
UicStatsAsHtml.write(writer, stats);
// expecting 1 root class, 3 components, class names as shown
String uicStatsHtml1 = UICSTATS_HTML1.replaceAll("<<NUM_ROOTS>>", "1");
String uicStatsHtml2 = UICSTATS_HTML2.replaceAll("<<NUM_COMPONENTS>>", "4");
String uicStatsHtml31 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WApplication");
String uicStatsHtml32 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WButton");
String uicStatsHtml33 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WLabel");
String[] expectedResults = { uicStatsHtml1, uicStatsHtml2, uicStatsHtml31, uicStatsHtml32, uicStatsHtml33 };
String result = outStr.toString();
for (int i = 0; i < expectedResults.length; i++) {
Assert.assertTrue("result should contain substring " + i + " ", result.indexOf(expectedResults[i]) != -1);
}
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class UicStats_Test method testGetWCTreeStats.
/**
* Test getWCTreeStats.
*/
@Test
public void testGetWCTreeStats() {
stats.analyseWC(app);
Map<WComponent, Stat> resultStats = stats.getWCTreeStats(app);
// label
for (Map.Entry<WComponent, Stat> entry : resultStats.entrySet()) {
WComponent comp = entry.getKey();
Stat stat = entry.getValue();
if (comp instanceof WLabel) {
Assert.assertEquals("this should be the label created", label, comp);
Assert.assertEquals("stat should have correct label name", label.getId(), stat.getName());
} else if (comp instanceof WButton) {
Assert.assertEquals("this should be the button in the app", button, comp);
Assert.assertEquals("stat should have correct button name", button.getId(), stat.getName());
} else if (comp instanceof WApplication) {
Assert.assertEquals("this should be the app", app, comp);
Assert.assertEquals("stat should have correct app name", app.getId(), stat.getName());
}
}
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testRenderedFormatWithHiddenFields.
@Test
public void testRenderedFormatWithHiddenFields() throws XpathException, IOException, SAXException {
MockWEnvironment environment = new MockWEnvironment();
environment.setPostPath("WApplicationRendererTest.postPath");
WApplication application = new WApplication();
UIContext uic = createUIContext();
uic.setEnvironment(environment);
uic.setUI(application);
setActiveContext(uic);
WLabel label = new WLabel("dummy");
application.add(label);
Map<String, String> hiddenParameters = new HashMap<>();
hiddenParameters.put("keyA", "valueA");
hiddenParameters.put("keyB", "valueB");
environment.setHiddenParameters(hiddenParameters);
assertSchemaMatch(application);
assertXpathEvaluatesTo(label.getText(), "normalize-space(//ui:application/ui:label)", application);
assertXpathEvaluatesTo("valueA", "//ui:application/ui:param[@name='keyA']/@value", application);
assertXpathEvaluatesTo("valueB", "//ui:application/ui:param[@name='keyB']/@value", application);
}
Aggregations