Package org.apache.click.servlet

Examples of org.apache.click.servlet.MockRequest


        assertEquals(new Double(-20.1), doubleField.getValueObject());
    }

    public void testLocaleServerENClientDE() {
        MockContext mockContext = MockContext.initContext(Locale.GERMANY);
        MockRequest request = mockContext.getMockRequest();

        DoubleField doubleField = new DoubleField("id");

        // German uses ',' as the decimal separator
        // German 123,4 => double 123.4
        request.setParameter("id", "123,4");
        assertTrue(doubleField.onProcess());
        assertEquals("123,4", doubleField.getValue());
        assertEquals(new Double(123.4), doubleField.getDouble());
        assertEquals(new Double(123.4), doubleField.getValueObject());
    }
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();
        mockContext.setLocale(Locale.US);
       
        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

public class LongFieldTest extends TestCase {
   
    public void testOnProcess() {
        MockContext mockContext = MockContext.initContext();
        MockRequest request = mockContext.getMockRequest();
       
        LongField longField = new LongField("id");
        assertEquals("id", longField.getName());

        request.getParameterMap().put("id", "1234");
       
        assertTrue(longField.onProcess());
        assertTrue(longField.isValid());
        assertEquals("1234", longField.getValue());
        assertEquals(new Long(1234), longField.getValueObject());
       
        request.getParameterMap().put("id", "123.4");
       
        assertTrue(longField.onProcess());
        assertFalse(longField.isValid());
        assertEquals("123.4", longField.getValue());
        assertNull(longField.getValueObject());

        // Test not required + blank value
        request.getParameterMap().put("id", "");
       
        assertTrue(longField.onProcess());
        assertTrue(longField.isValid());
        assertEquals("", longField.getValue());
        assertNull(longField.getValueObject());
       
        longField.setRequired(true);
        assertTrue(longField.onProcess());
        assertFalse(longField.isValid());
        assertEquals("", longField.getValue());
        assertNull(longField.getValueObject());
       
        request.getParameterMap().put("id", "10");
       
        longField.setMinValue(10);    
        assertTrue(longField.onProcess());
        assertTrue(longField.isValid());
        assertEquals("10", longField.getValue());
        assertEquals(new Long(10), longField.getValueObject());
       
        longField.setMinValue(11);
        assertTrue(longField.onProcess());
        assertFalse(longField.isValid());
        assertEquals("10", longField.getValue());
        assertEquals(new Long(10), longField.getValueObject());
       
        request.getParameterMap().put("id", "20");
       
        longField.setMaxValue(20);
        assertTrue(longField.onProcess());
        assertTrue(longField.isValid());
        assertEquals("20", longField.getValue());
        assertEquals(new Long(20), longField.getValueObject());
       
        longField.setMaxValue(20);
        assertTrue(longField.onProcess());
        assertTrue(longField.isValid());
        assertEquals("20", longField.getValue());
        assertEquals(new Long(20), longField.getValueObject());
       
        longField.setMaxValue(19);
        assertTrue(longField.onProcess());
        assertFalse(longField.isValid());
        assertEquals("20", longField.getValue());
        assertEquals(new Long(20), longField.getValueObject());
       
        assertEquals(new Long(20), longField.getLong());
        assertEquals(new Integer(20), longField.getInteger());
       
        request.getParameterMap().put("id", "-20");
       
        longField.setMinValue(-21);
        assertTrue(longField.onProcess());
        assertTrue(longField.isValid());
        assertEquals("-20", longField.getValue());
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

        assertEquals(3456.134f, germanF.getNumber().floatValue(),0);
    }
   
    public void testOnProcess() {
        MockContext mockContext = MockContext.initContext(Locale.US);
        MockRequest req = mockContext.getMockRequest();
        Map<String, Object> params = req.getParameterMap();
       
        NumberField engF = new NumberField("en");
        engF.setPattern("#,##0.00");
       
        engF.setValidate(false);
        params.put("en", "no number");
        assertTrue(engF.onProcess());
        assertEquals("no number", engF.getValue());
        assertTrue(engF.isValid());
        assertNull(engF.getNumber());
        engF.validate();
        assertFalse(engF.isValid());
       
        engF = new NumberField("en");
        engF.setPattern("#,##0.00");
        params.put("en", "12.3");

        engF.setValidate(false);
        assertTrue(engF.onProcess());
        assertEquals("12.3",engF.getValue());
        assertEquals(12.3f,engF.getNumber().floatValue(),0);
        engF.validate();
        assertEquals("12.30",engF.getValue());
       
        engF = new NumberField("en");
        engF.setPattern("#,##0.00");
        params.put("en", "12.3");
       
        assertTrue(engF.onProcess());
        assertEquals("12.30",engF.getValue());
        assertEquals("12.3", req.getParameter(engF.getName()));
       
        params.put("en", "some value");
        assertTrue(engF.onProcess());
        assertEquals("some value", engF.getValue());
        assertNull(engF.getNumber());
        assertEquals("some value", req.getParameter(engF.getName()));
    }
View Full Code Here

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

        assertFalse(pat.matcher("#1234").matches());
    }
   
    public void testValidate() {
        MockContext mockContext = MockContext.initContext();
        MockRequest mr = mockContext.getMockRequest();
        Map<String, Object> params = mr.getParameterMap();
       
        ColorPicker cp = new ColorPicker("color");
       
        params.put("color","#fff");
        assertTrue(cp.onProcess());
View Full Code Here

        // Setup
        Menu menu = new Menu("menu");
        RoleAccessController controller = new RoleAccessController();
        menu.setAccessController(controller);

        MockRequest request = new MockRequest();
        String role = "userRole";
        MockPrincipal principal = new MockPrincipal("bob", role);
        request.setUserPrincipal(principal);

        // Perform tests
        assertTrue(menu.isUserInRoles());
    }
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.