Package org.apache.click

Examples of org.apache.click.MockContext


     * Checks that Click vetoes the addition of a Container to itself.
     *
     * CLK-414.
     */
    public void testAddContainerToItself() {
        MockContext context = MockContext.initContext();
        try {
            Form form = new Form("form");
            form.add(form);
            Assert.assertFalse("Cannot add container to itself", true);
        } catch (RuntimeException expected) {
View Full Code Here


     * HiddenField.
     *
     * 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

     * missing.
     *
     * 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);

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
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

    protected void tearDown() throws Exception {
        Locale.setDefault(defaultLocale);
    }

    public void testFormat() {
        MockContext mockContext = MockContext.initContext(Locale.US);
        MockRequest req = mockContext.getMockRequest();
       
        Number decNum = new Float(2.56f);
       
        NumberField engF = new NumberField("en");

        assertNull(engF.getPattern());
        engF.setPattern("#.00");
        assertEquals("#.00", engF.getPattern());
        engF.setPattern(null);
        assertNull(engF.getPattern());

        engF.setValue("some Text");
        assertEquals("some Text", engF.getValue());
        assertNull(engF.getNumber());
       
        engF.setValue("12.456,5656");
        assertEquals("12.456,5656", engF.getValue());
        assertEquals(new Double(12.456), engF.getNumber());
       
        engF.setNumber(decNum);
        assertEquals("2.56", engF.getValue());
        assertEquals(2.56d, engF.getNumber().doubleValue(),0);
       
        engF.setValue("123.6");
        assertEquals(123.6d, engF.getNumber().doubleValue(),0);
        assertEquals(engF.getNumber(), engF.getValueObject());
       
        engF.setPattern("0");
        engF.setNumber(new Float(123.6f));
        assertEquals("124", engF.getValue());
        assertEquals(124, engF.getNumber().intValue());
       
        engF.setValue("123.6");
        assertEquals("123.6", engF.getValue());
        assertEquals(123.6f, engF.getNumber().floatValue(),0);
       
        engF.setPattern("0.00");
        engF.setNumber(new Float(123.6f));
        assertEquals("123.60", engF.getValue());
        assertEquals(123.6f, engF.getNumber().floatValue(),0);
       
        engF.setValue("12.223");
        assertEquals(12.223f, engF.getNumber().floatValue(),0);
       
        //keeps the pattern
        engF.setNumberFormat(NumberFormat.getInstance(Locale.GERMAN));
        engF.setNumber(decNum);
        assertEquals("2,56", engF.getValue());
        engF.setValue("3456,134");
        assertEquals(3456.134f, engF.getNumber().floatValue(),0);
       
        mockContext = MockContext.initContext(Locale.GERMANY);
        req = mockContext.getMockRequest();
       
        NumberField germanF = new NumberField("de");
       
        germanF.setNumber(decNum);
        assertEquals("2,56", germanF.getValue());
View Full Code Here

        germanF.setValue("3.456,134");
        assertEquals(3456.134f, germanF.getNumber().floatValue(),0);
    }
   
    public void testOnProcess() {
        MockContext mockContext = MockContext.initContext(Locale.US);
        MockRequest req = mockContext.getMockRequest();
        Map params = req.getParameterMap();
       
        NumberField engF = new NumberField("en");
        engF.setPattern("#,##0.00");
       
View Full Code Here

        assertNull(engF.getNumber());
        assertEquals("some value", req.getParameter(engF.getName()));
    }
   
    public void testValidate() {
        MockContext mockContext = MockContext.initContext(Locale.US);
        MockRequest req = mockContext.getMockRequest();
        Map params = req.getParameterMap();
       
        NumberField engF = new NumberField("en");
        engF.setPattern("0");
       
View Full Code Here

     * no-argument version.
     *
     * CLK-461
     */
    public void testCopyToErrorMessages() {
        MockContext context = MockContext.initContext();
       
        // Setup request parameters
        String price = "10.99";
        context.getMockRequest().setParameter("part.price", price);
        context.getMockRequest().setParameter("form_name", "form");

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

        // Setup price field
View Full Code Here

            "three",
            "3.1"};
    }
   
    private void assertExpandOrCollapse(Tree tree, String[] nodeIds, boolean expected) {
        MockContext context = (MockContext) MockContext.getThreadLocalContext();
        for(int i = 0; i < nodeIds.length; i++) {
            TreeNode node = tree.find(nodeIds[i]);
            assertTrue("IsExpanded must be " + expected,node.isExpanded() == expected);
        }
        tree.onProcess();
        context.executeActionListeners();
        for(int i = 0; i < nodeIds.length; i++) {
            TreeNode node = tree.find(nodeIds[i]);
            assertTrue("IsExpanded must be " + !expected,node.isExpanded() == !expected);
        }
    }
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.