Package org.apache.click.servlet

Examples of org.apache.click.servlet.MockRequest


     * Check that MockRequest can dynamically add parameters and trigger
     * a Controls action listener.
     */
    public void testDynamicRequest() {
        MockContext context = MockContext.initContext();
        MockRequest request = (MockRequest) context.getMockRequest();

        TextArea textArea = new TextArea("text");
        assertEquals("text", textArea.getName());

        request.setParameter("param", "value");
        request.getParameterMap().put("text", "textvalue");

        // Registry a listener which must be invoked
        textArea.setActionListener(new ActionListener() {
            public boolean onAction(Control source) {
                // When action is invoked, set flag to true
View Full Code Here


            if (locale == null) {
                locale = Locale.getDefault();
            }
            if (getRequest() == null) {
                setRequest(new MockRequest(locale, getServletContext(),
                    getSession()));
            }
            getRequest().setAttribute(ClickServlet.MOCK_MODE_ENABLED, Boolean.TRUE);
            getServletContext().setAttribute(ClickServlet.MOCK_MODE_ENABLED,
                Boolean.TRUE);
View Full Code Here

        MockResponse response = new MockResponse();

        MockSession session = new MockSession(servletContext);

        MockRequest request = new MockRequest(locale, MockServletContext.DEFAULT_CONTEXT_PATH,
            servletPath, servletContext, session);

        return initContext(servletConfig, request, response, servlet);
    }
View Full Code Here

     *
     * CLK-267.
     */
    public void testDuplicateOnSubmitCheck() {
        MockContext context = MockContext.initContext("test-form.htm");
        MockRequest request = (MockRequest) context.getMockRequest();
        request.setParameter("form_name", "form");

        Page page = new Page();

        // Set the page to stateful
        page.setStateful(true);
        Form form = new Form("form");

        // Construct name of submit token
        String submitCheckName = Form.SUBMIT_CHECK + form.getName() + "_" + context.getResourcePath();

        // Simulate a submit check
        boolean valid = form.onSubmitCheck(page, "/invalid-submit.html");
        Assert.assertTrue(valid);

        // Assert that the submitCheck hidden field was created
        Field submitCheckField = form.getField(submitCheckName);
        Assert.assertNotNull(submitCheckField);

        // Add submitCheckField as a request parameter
        request.getParameterMap().put(Form.SUBMIT_CHECK + form.getName() + "_" + context.getResourcePath(), submitCheckField.getValue());
       
        // Simulate a second submit check.
        valid = form.onSubmitCheck(page, "/invalid-submit.html");
       
        // Assert the second onSubmitCheck did succeed as well.
View Full Code Here

     *
     * CLK-289.
     */
    public void testOnSubmitCheckMissingParam() {
        MockContext context = (MockContext) MockContext.initContext("test-form.htm");
        MockRequest request = (MockRequest) context.getMockRequest();
        request.getParameterMap().put("form_name", "form");
        Page page = new Page();
        Form form = new Form("form");

        // Construct name of submit token
        String submitTokenName = Form.SUBMIT_CHECK + form.getName() + "_" + context.getResourcePath();

        // Ensure there are no submitCheck hidden field yet
        Field submitCheckField = form.getField(submitTokenName);
        Assert.assertNull(submitCheckField);

        // Simulate a submit check
        boolean valid = form.onSubmitCheck(page, "/invalid-submit.html");
        Assert.assertTrue(valid);

        // Add the submitCheckField name and value to the parameters.
        submitCheckField = form.getField(submitTokenName);
        request.setParameter(submitTokenName, submitCheckField.getValue());

        // If we submit again, the assert should be true because the submit
        // token is set in the request parameters.
        valid = form.onSubmitCheck(page, "/invalid-submit.html");
        Assert.assertTrue(valid);
       
        // Now imagine the SUBMIT_CHECK token is removed by a hacker. To simulate
        // such a scenario we remove the submitTokenName from the request paramters.
        request.removeParameter(submitTokenName);
        valid = form.onSubmitCheck(page, "/invalid-submit.html");
        Assert.assertFalse(valid);
    }
View Full Code Here

     * Test that form processing binds a request parameter to a field value.
     */
    public void testFormOnProcessRequestBinding() {
        // Create a mock context
        MockContext context = (MockContext) MockContext.initContext("test-form.htm");
        MockRequest request = (MockRequest) context.getMockRequest();

        // The request value that should be set as the textField value
        String requestValue = "one";

        // Set form name and field name parameters
        request.setParameter("form_name", "form");
        request.setParameter("name", requestValue);

        // Create form and fields
        Form form = new Form("form");
        TextField nameField = new TextField("name");
        form.add(nameField);
View Full Code Here

    /**
     * Test expand and collapse of nodes.
     */
    public void testExpandAndCollapse() {
        MockRequest mockRequest = mockContext.getMockRequest();
        mockRequest.setParameter(Tree.EXPAND_TREE_NODE_PARAM, testIds);
        mockRequest.setParameter(ActionLink.ACTION_LINK, tree.getExpandLink().getName());

        assertExpandOrCollapse(tree, testIds, false);//test for expansion
        assertExpandOrCollapse(tree, testIds, true);//should reverse expand and collapse
    }
View Full Code Here

    /**
     * Test selected and deselect of nodes.
     */
    public void testSelectAndDeselect() {
        MockRequest mockRequest = mockContext.getMockRequest();
        mockRequest.setParameter(Tree.SELECT_TREE_NODE_PARAM, testIds);
        mockRequest.setParameter(ActionLink.ACTION_LINK, tree.getSelectLink().getName());

        assertSelectOrDeselect(tree, testIds, false);//test for selection
        assertSelectOrDeselect(tree, testIds, true);//should reverse selection and deselect
    }
View Full Code Here

*/
public class DateFieldTest extends TestCase {

    public void testNullParameter() {
        MockContext mockContext = MockContext.initContext();
        MockRequest request = mockContext.getMockRequest();

        DateField dateField = new DateField("dateField");
        assertEquals("dateField", dateField.getName());
       
        request.getParameterMap().put("dateField", "");       
        dateField.onProcess();       
        Date date = dateField.getDate();
        assertNull(date);
       
        request.getParameterMap().put("dateField", " ");       
        dateField.onProcess();       
        date = dateField.getDate();
        assertNull(date);

        request.getParameterMap().put("dateField", null);       
        dateField.onProcess();       
        date = dateField.getDate();
        assertNull(date);
       
        dateField.setValue(null);
View Full Code Here

     *
     * CLK-316
     */
    public void testIntegerCacheValue() {
        MockContext mockContext = MockContext.initContext();
        MockRequest request = mockContext.getMockRequest();
       
        DateField dateField = new DateField("dateField");
        dateField.setFormatPattern("dd MMM yyyy H m s S");
        String requestParam = "06 Oct 2008 2 30 59 999";
        request.getParameterMap().put("dateField", requestParam);

        assertTrue(dateField.onProcess());

        // Check that the value equals the request parameter
        assertEquals(requestParam, dateField.getValue());
View Full Code Here

TOP

Related Classes of org.apache.click.servlet.MockRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.