use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WShuffler_Test method testIsPresent.
@Test
public void testIsPresent() {
WShuffler shuffler = new WShuffler(OPTIONS);
shuffler.setLocked(true);
// Empty Request
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
Assert.assertFalse("IsPresent should return false", shuffler.isPresent(request));
// Shuffler on the request (but options are different)
request = new MockRequest();
request.setParameter(shuffler.getId(), new String[] { OPTION_A, OPTION_B });
Assert.assertFalse("IsPresent should return false when options have changed", shuffler.isPresent(request));
// Shuffler on the request (Same options)
request = new MockRequest();
request.setParameter(shuffler.getId(), new String[] { OPTION_C, OPTION_A, OPTION_B });
Assert.assertTrue("IsPresent should return true", shuffler.isPresent(request));
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WTableRenderer_Test method testDoPaintSortableSortModeDynamicClientSettings.
@Test
public void testDoPaintSortableSortModeDynamicClientSettings() throws IOException, SAXException, XpathException {
WTable component = new WTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
// sortable data model
TableModel tableModel = createTableModelSortable();
component.setTableModel(tableModel);
component.setVisible(true);
component.setSortMode(SortMode.DYNAMIC);
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
String colIndexStr = "0";
request.setParameter(component.getId() + "-h", "x");
request.setParameter(component.getId() + ".sort", colIndexStr);
request.setParameter(component.getId() + ".sortDesc", TRUE);
component.handleRequest(request);
assertSchemaMatch(component);
assertXpathEvaluatesTo("dynamic", "//ui:table/ui:sort/@mode", component);
assertXpathEvaluatesTo(colIndexStr, "//ui:table/ui:sort/@col", component);
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:sort/@descending", component);
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/ui:th[1]/@sortable", component);
assertXpathNotExists("//ui:table/ui:thead/ui:th[2]/@sortable", component);
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/ui:th[3]/@sortable", component);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScalingWithInterceptorChain.
@Test
public void testRenderingScalingWithInterceptorChain() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
makeAllInputsMandatory(component1);
component1.setLocked(true);
final UIContext uic1 = createUIContext();
final UIContext uicChain = createUIContext();
sendRequest(component1, uic1);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Just paint component
component1.preparePaint(new MockRequest());
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uicChain);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Paint with the interceptor chain
WebUtilities.renderWithTransformToHTML(component1);
}
}
};
// JIT warm-up
runnable.run();
long renderTimeChain = time(runnable) / NUM_REPETITIONS;
LOG.info("Render Component time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render Component/Chain time: " + (renderTimeChain / 1000000.0) + "ms");
Assert.assertTrue("Render with Chain time scaling should not be more than 3x.", renderTimeChain < renderTime1 * 3);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WNumberFieldRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WNumberField numberField = new WNumberField();
MockRequest request = new MockRequest();
request.setParameter(numberField.getId(), getMaliciousContent());
numberField.serviceRequest(request);
assertSafeContent(numberField);
numberField.setToolTip(getMaliciousAttribute("ui:numberfield"));
assertSafeContent(numberField);
numberField.setAccessibleText(getMaliciousAttribute("ui:numberfield"));
assertSafeContent(numberField);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AbstractCondition_Test method testTrueFalseAccessors.
@Test
public void testTrueFalseAccessors() {
MyCondition condition = new MyCondition();
// True Condition
condition.setTestCondition(true);
Assert.assertTrue("Condition isTrue should be true", condition.isTrue());
Assert.assertFalse("Condition isFalse should be false", condition.isFalse());
// False Condition
condition.setTestCondition(false);
Assert.assertFalse("Condition isTrue should be false", condition.isTrue());
Assert.assertTrue("Condition isFalse should be true", condition.isFalse());
MockRequest request = new MockRequest();
// True Condition
request.setParameter("condition", "true");
Assert.assertTrue("Condition isTrue should be true with Request", condition.isTrue(request));
Assert.assertFalse("Condition isFalse should be false with Request", condition.isFalse(request));
// False Condition
request.setParameter("condition", "false");
Assert.assertFalse("Condition isTrue should be false with Request", condition.isTrue(request));
Assert.assertTrue("Condition isFalse should be true with Request", condition.isFalse(request));
}
Aggregations