Package org.apache.click

Examples of org.apache.click.MockContainer


        pstr.println(" <pages/>");
        pstr.println(" <template-service classname='org.apache.click.service.VelocityTemplateService'/>");
        pstr.println("</click-app>");
        pstr.close();

        MockContainer container = new MockContainer(tmpdir.getAbsolutePath());
        container.start();

        ConfigService config = ClickUtils.getConfigService(container.getServletContext());

        assertTrue(config.getTemplateService() instanceof VelocityTemplateService);

        container.stop();
        deleteDir(tmpdir);
    }
View Full Code Here


        pstr.println(" <pages/>");
        pstr.println(" <file-upload-service classname='org.apache.click.service.CommonsFileUploadService'/>");
        pstr.println("</click-app>");
        pstr.close();

        MockContainer container = new MockContainer(tmpdir.getAbsolutePath());
        container.start();

        ConfigService config = ClickUtils.getConfigService(container.getServletContext());

        assertTrue(config.getFileUploadService() instanceof CommonsFileUploadService);

        container.stop();
        deleteDir(tmpdir);
    }
View Full Code Here

        pstr.println(" <pages/>");
        pstr.println(" <messages-map-service classname='org.apache.click.service.XmlConfigServiceTest$MyMessagesMapService'/>");
        pstr.println("</click-app>");
        pstr.close();

        MockContainer container = new MockContainer(tmpdir.getAbsolutePath());
        container.start();

        ConfigService config = ClickUtils.getConfigService(container.getServletContext());

        assertTrue(config.getMessagesMapService() instanceof MyMessagesMapService);

        container.stop();
        deleteDir(tmpdir);
    }
View Full Code Here

    /**
     * Check that FileField onProcess works properly for multipart requests.
     */
    public void testOnProcess() {
        try {
            MockContainer container = new MockContainer("web");

        container.start();

          // Prepare a file for upload
        String fileName = "file-field.htm";
        String filePath = "/web/" + fileName;
            URL resource = container.getClass().getResource(filePath);
            URI uri = new URI(resource.toString());
            File file = new File(uri);

            // Prepare container parameters
            String fieldName = "fileField";
            container.setParameter(fieldName, file, "text/html");
            container.setParameter("form_name", "form");

            FileFieldPage page = container.testPage(FileFieldPage.class);

        FileField field = page.getFileField();

        // Perform tests
        assertNotNull(field.getFileItem());
        field.getFileItem().getName();
        assertEquals(fieldName, field.getFileItem().getFieldName());
        assertEquals(fileName, field.getFileItem().getName());
        assertEquals(file.length(), field.getFileItem().getSize());

        container.stop();

        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
View Full Code Here

   
    /**
     * Test with a session.
     */
    public void testSession() {
        MockContainer container = new MockContainer("web");
        container.start();
        HttpSession session = container.getRequest().getSession();
        SessionMap sm = new SessionMap(session);
      
        Assert.assertEquals(0, sm.size());
        Assert.assertEquals(0, sm.keySet().size());
        Assert.assertEquals(0, sm.entrySet().size());
        Assert.assertEquals(0, sm.values().size());
       
        Assert.assertNull(sm.get("attrib1"));
        Assert.assertNull(sm.get(null));
        Assert.assertTrue(sm.isEmpty());
       
        session.setAttribute("attrib1", "value1");
       
        Assert.assertEquals("value1", sm.get("attrib1"));
       
        Assert.assertEquals(1, sm.size());
        Assert.assertEquals(1, sm.keySet().size());
        Assert.assertTrue(sm.keySet().contains("attrib1"));
       
        Assert.assertEquals(1, sm.entrySet().size());
        Map.Entry<String, Object> entry = sm.entrySet().iterator().next();
        Assert.assertEquals("attrib1", entry.getKey());
        Assert.assertEquals("value1", entry.getValue());

        Assert.assertEquals(1, sm.values().size());
        Assert.assertTrue(sm.values().contains("value1"));

        container.stop();
    }
View Full Code Here

    /**
     * Test changes to the SessionMap.
     */
    public void testPuts() {
        MockContainer container = new MockContainer("web");
        container.start();
        HttpSession session = container.getRequest().getSession();
        SessionMap sm = new SessionMap(session);
      
        Assert.assertEquals(0, sm.size());
       
        sm.put("attrib1", "value1");
       
        Assert.assertEquals("value1", session.getAttribute("attrib1"));
       
        sm.put("attrib1", "value2");

        Assert.assertEquals("value2", session.getAttribute("attrib1"));

        Assert.assertEquals("value2", sm.remove("attrib1"));
       
        Assert.assertEquals(0, sm.size());
       
        sm.putAll(null);

        Assert.assertEquals(0, sm.size());

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("attrib2", "value2");
       
        sm.putAll(map);
        Assert.assertEquals(1, sm.size());

        sm.clear();
       
        Assert.assertEquals(0, sm.size());
       
        container.stop();
    }
View Full Code Here

   
    /**
     * Test iteration over entrySet from velocity.
     */
    public void testPage() {
        MockContainer container = new MockContainer("web");
        container.start();
        HttpSession session = container.getRequest().getSession(true);
       
        session.setAttribute("attrib1", "value1");
       
        container.getRequest().setMethod("GET");

        container.testPage(SessionMapPage.class);
        Assert.assertTrue(container.getHtml().contains("attrib1=value1"));
       
        container.stop();
    }
View Full Code Here

        pstr.println(" <control-set name='MyControlSet.xml'/>");
        pstr.println("</controls>");
        pstr.println("</click-app>");
        pstr.close();

        MockContainer container = new MockContainer(tmpdir.getAbsolutePath());
        container.start();

        container.stop();

        deleteDir(tmpdir);
    }
View Full Code Here

        pstr.println("  <property name='type' value='app'/>");
        pstr.println(" </page-interceptor>");
        pstr.println("</click-app>");
        pstr.close();

        MockContainer container = new MockContainer(tmpdir.getAbsolutePath());
        container.start();

        ConfigService config = ClickUtils.getConfigService(container.getServletContext());

        List<PageInterceptor> list = config.getPageInterceptors();
        assertEquals(2, list.size());
        assertEquals("std", list.get(0).toString());
        assertEquals("app", list.get(1).toString());
        container.stop();

        deleteDir(tmpdir);
    }
View Full Code Here

     * by multiple threads.
     */
    public void testClassAttributeRendering() {
        // PickList uses Velocity to render its template. In this test we start a
        // MockContainer which also configures Velocity
        MockContainer container = new MockContainer("web");
        container.start();

        // MockContext is created when a container tests a page. There
        // is no page to test so we manually create a MockContext
        // and reuse the Mock Servlet objects created in the container.
        MockContext.initContext(container.getServletConfig(),
            container.getRequest(), container.getResponse(), container.getClickServlet());

        PickList pickList = new PickList("pickList");

        pickList.addStyleClass("white");
        pickList.setAttribute("title", "test");

        String pickListStr = pickList.toString();

        // Perform checks within the first 100 characters
        pickListStr = pickListStr.substring(0, 100);

        // Check that class attribute was rendered
        assertEquals(1, StringUtils.countMatches(pickListStr, "class=\"white picklist\""));

        // Check that the title attribute was rendered
        assertEquals(1, StringUtils.countMatches(pickListStr, "title=\"test\""));

        // Check that class attribute was rendered once
        assertEquals(1, StringUtils.countMatches(pickListStr, "class="));
        container.stop();
    }
View Full Code Here

TOP

Related Classes of org.apache.click.MockContainer

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.