Package org.apache.click

Examples of org.apache.click.MockContext


     */
    public void testTrim() {
        String trimmedValue = "value";
        String value = " " + trimmedValue + " ";

        MockContext context = MockContext.initContext();
        context.getMockRequest().setParameter("field", value);

        Field field = new TextField("field");
        field.onProcess();

        // Check that the field trims its request value
View Full Code Here


public class ButtonTest extends TestCase {
    /**
     * Test Button onProcess behavior.
     */
    public void testOnProcess() {
        MockContext context = MockContext.initContext();
        MockRequest request = context.getMockRequest();
       
        Button button = new Button("button");
        assertEquals("button", button.getName());
       
        assertTrue(button.onProcess());
       
        request.setParameter("button", "true");
        assertTrue(button.onProcess());
       
        final boolean check[] = new boolean[1];
        button.setActionListener(new ActionListener() {
            private static final long serialVersionUID = 1L;

            public boolean onAction(Control source) {
                check[0] = true;
                return false;
            }
        });

        // No request param -> no action listener executed
        request.removeParameter("button");
        assertTrue(button.onProcess());
        context.executeActionListeners();
        assertFalse(check[0]);
       
        request.setParameter("button", "true");

        // Not an ajax request -> no action listener executed
        assertTrue(button.onProcess());
        context.executeActionListeners();
        assertFalse(check[0]);

        // ajax request, but no request param -> no action listener executed
        request.removeParameter("button");
        request.setParameter("X-Requested-With", "true");
        assertTrue(button.onProcess());
        context.executeActionListeners();
        assertFalse(check[0]);

        // Ajax request & request param -> call the onAction.
        request.setParameter("button", "true");
        request.setParameter("X-Requested-With", "true");
        assertTrue(button.onProcess());
        context.executeActionListeners();
        assertTrue(check[0]);
       
      
        button.setDisabled(true);
        assertTrue(button.onProcess());
View Full Code Here

     * HiddenField.
     *
     * CLK-267.
     */
    public void testDuplicateOnSubmitCheck() {
        MockContext context = MockContext.initContext("test-form.htm");
        MockRequest request = 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.setParameter(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

     * missing.
     *
     * CLK-289.
     */
    public void testOnSubmitCheckMissingParam() {
        MockContext context = MockContext.initContext("test-form.htm");
        MockRequest request = context.getMockRequest();
        request.setParameter("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);

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.initContext("test-form.htm");
        MockRequest request = context.getMockRequest();

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

        // Set form name and field name parameters
View Full Code Here

     * Check that Form processes controls even if their names is not defined.
     *
     * CLK-463
     */
    public void testProcessControlWhenNameIsNull() {
        MockContext context = MockContext.initContext();
        context.getMockRequest().setParameter("form_name", "form");
        String fieldValue = "test";
        context.getMockRequest().setParameter("field", fieldValue);

        Form form = new Form("form");
        Panel panel = new Panel();
        TextField textField = new TextField("field");
        panel.add(textField);
View Full Code Here

    /**
     *
     */
    public void testBindAndValidateForm() {
        MockContext context = MockContext.initContext();
        MockRequest request = context.getMockRequest();
        request.setParameter("form_name", "form");
        request.setParameter("firstName", "steve");

final String formError = "error";
        Form form = new Form("form") {
View Full Code Here

     *
     * CLK-715
     */
    public void testSaveState() {
        String pagePath = "/page.htm";
        MockContext context = MockContext.initContext(pagePath);

        // Setup Form
        Form form = new Form("form");
        Field nameField  = new TextField("name");
        nameField.setValue("Steve");
        form.add(nameField);

        // Save form state to the session
        ClickUtils.saveState(form, form.getName(), context);

        // Test that page state is stored in session under the Page path
        assertNotNull(context.getSessionAttribute(pagePath));
    }
View Full Code Here

     *
     * CLK-715
     */
    public void testRestoreState() {
        String pagePath = "/page.htm";
        MockContext context = MockContext.initContext(pagePath);

        // Setup Form and Fields
        Form form = new Form("form");
        Field nameField  = new TextField("name");
        form.add(nameField);

        Map pageStateMap = new HashMap();

        // Page state is stored in session under the Page path
        context.setSessionAttribute(pagePath, pageStateMap);

        Map formStateMap = new HashMap();
        formStateMap.put("name", "Steve");

        // Controls are stored in the Page Map under their names
View Full Code Here

     *
     * CLK-715
     */
    public void testRemoveState() {
        String pagePath = "/page.htm";
        MockContext context = MockContext.initContext(pagePath);

        // Setup Form
        Form form = new Form("form");

        Map pageStateMap = new HashMap();

        // Page state is stored in session under the Page path
        context.setSessionAttribute(pagePath, pageStateMap);
        assertNotNull(context.getSessionAttribute(pagePath));

        Map formStateMap = new HashMap();

        // Controls are stored in the Page Map under their names
        pageStateMap.put(form.getName(), formStateMap);

        // Remove form state
        ClickUtils.removeState(form, form.getName(), context);

        // Test that form state has been removed from the session
        assertNull(pageStateMap.get(form.getName()));

        // Since formState was the only state in the page map, test that
        // pageMap is also cleared from the session
        assertNull(context.getSessionAttribute(pagePath));
    }
View Full Code Here

TOP

Related Classes of org.apache.click.MockContext

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.