Search in sources :

Example 41 with MockRequest

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));
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 42 with MockRequest

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);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) WTextField(com.github.bordertech.wcomponents.WTextField) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 43 with MockRequest

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);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 44 with MockRequest

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);
}
Also used : WNumberField(com.github.bordertech.wcomponents.WNumberField) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 45 with MockRequest

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));
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Aggregations

MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)250 Test (org.junit.Test)216 UIContext (com.github.bordertech.wcomponents.UIContext)22 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)16 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)13 PrintWriter (java.io.PrintWriter)13 Request (com.github.bordertech.wcomponents.Request)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 StringWriter (java.io.StringWriter)7 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)6 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 BigDecimal (java.math.BigDecimal)5 Escape (com.github.bordertech.wcomponents.Escape)4 WTextField (com.github.bordertech.wcomponents.WTextField)4 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3